forked from pymupdf/PyMuPDF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
160 lines (147 loc) · 4.62 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from distutils.core import setup, Extension
from distutils.command.build_py import build_py as build_py_orig
import re, sys, os
# custom build_py command which runs build_ext first
# this is necessary because build_py needs the fitz.py which is only generated
# by SWIG in the build_ext step
class build_ext_first(build_py_orig):
def run(self):
self.run_command("build_ext")
return super().run()
DEFAULT = [
"mupdf",
"mupdf-third",
]
ARCH_LINUX = DEFAULT + [
"jbig2dec",
"openjp2",
"jpeg",
"freetype",
"gumbo",
]
OPENSUSE = ARCH_LINUX + [
"harfbuzz",
"png16",
]
FEDORA = ARCH_LINUX + [
"harfbuzz",
]
LIBRARIES = {
"default": DEFAULT,
"ubuntu": DEFAULT,
"arch": ARCH_LINUX,
"manjaro": ARCH_LINUX,
"artix": ARCH_LINUX,
"opensuse": OPENSUSE,
"fedora": FEDORA,
}
def load_libraries():
try:
import distro
os_id = distro.id()
except:
os_id = ""
if os_id in list(LIBRARIES.keys()) + ["manjaro", "artix"]:
return LIBRARIES[os_id]
filepath = "/etc/os-release"
if not os.path.exists(filepath):
return LIBRARIES["default"]
regex = re.compile("^([\\w]+)=(?:'|\")?(.*?)(?:'|\")?$")
with open(filepath) as os_release:
info = {
regex.match(line.strip()).group(1): re.sub(
r'\\([$"\'\\`])', r"\1", regex.match(line.strip()).group(2)
)
for line in os_release
if regex.match(line.strip())
}
os_id = info["ID"]
if os_id.startswith("opensuse"):
os_id = "opensuse"
if os_id not in LIBRARIES.keys():
return LIBRARIES["default"]
return LIBRARIES[os_id]
# check the platform
if sys.platform.startswith("linux") or "gnu" in sys.platform:
module = Extension(
"fitz._fitz", # name of the module
["fitz/fitz.i"],
include_dirs=[ # we need the path of the MuPDF headers
"/usr/include/mupdf",
"/usr/local/include/mupdf",
"/usr/include/freetype2",
],
libraries=load_libraries(),
)
elif sys.platform.startswith(("darwin", "freebsd")):
module = Extension(
"fitz._fitz", # name of the module
["fitz/fitz.i"],
# directories containing mupdf's header files
include_dirs=[
"/usr/local/include/mupdf",
"/usr/local/include",
"/usr/include/freetype2",
"/usr/local/include/freetype2",
"/opt/homebrew/include",
"/opt/homebrew/include/mupdf",
"/opt/homebrew/include/freetype2",
],
# libraries should already be linked here by brew
library_dirs=["/usr/local/lib", "/opt/homebrew/lib"],
# library_dirs=['/usr/local/Cellar/mupdf-tools/1.8/lib/',
#'/usr/local/Cellar/openssl/1.0.2g/lib/',
#'/usr/local/Cellar/jpeg/8d/lib/',
#'/usr/local/Cellar/freetype/2.6.3/lib/',
#'/usr/local/Cellar/jbig2dec/0.12/lib/'
# ],
libraries=["mupdf", "mupdf-third"],
)
else:
# ===============================================================================
# Build / set up PyMuPDF under Windows
# ===============================================================================
module = Extension(
"fitz._fitz",
["fitz/fitz.i"],
include_dirs=[ # we need the path of the MuPDF's headers
"./mupdf/include",
"./mupdf/include/mupdf",
"./mupdf/thirdparty/freetype/include",
],
libraries=[ # these are needed in Windows
"libmupdf",
"libresources",
"libthirdparty",
],
extra_link_args=["/NODEFAULTLIB:MSVCRT"],
# x86 dir of libmupdf.lib etc.
library_dirs=["./mupdf/platform/win32/Release"],
# x64 dir of libmupdf.lib etc.
# library_dirs=['./mupdf/platform/win32/x64/Release'],
)
pkg_tab = open("PKG-INFO").read().split("\n")
long_dtab = []
classifier = []
for l in pkg_tab:
if l.startswith("Classifier: "):
classifier.append(l[12:])
continue
if l.startswith(" "):
long_dtab.append(l.strip())
long_desc = "\n".join(long_dtab)
setup(
name="PyMuPDF",
version="1.18.12",
description="Python bindings for the PDF rendering library MuPDF",
long_description=long_desc,
classifiers=classifier,
url="https://github.com/pymupdf/PyMuPDF",
author="Jorj McKie",
author_email="[email protected]",
cmdclass={"build_py": build_ext_first},
ext_modules=[module],
py_modules=["fitz.fitz", "fitz.utils", "fitz.__main__"],
license="GNU AFFERO GPL 3.0",
data_files=["README.md"],
)