forked from adobe-type-tools/afdko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
222 lines (188 loc) · 7.4 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import distutils.command.build_scripts
import io
import os
import platform
import sys
from distutils import log
from distutils.dep_util import newer
from distutils.util import convert_path
from distutils.util import get_platform
import setuptools.command.install
from skbuild import setup
try:
from wheel.bdist_wheel import bdist_wheel
class CustomBDistWheel(bdist_wheel):
"""Mark the wheel as python 3, yet platform-specific,
since it contains native C executables.
"""
def finalize_options(self):
bdist_wheel.finalize_options(self)
self.root_is_pure = False
def get_tag(self):
return ('py3', 'none',) + bdist_wheel.get_tag(self)[2:]
except ImportError:
print("afdko: setup.py requires that the Python package 'wheel' be "
"installed. Try the command 'pip install wheel'.")
sys.exit(1)
class InstallPlatlib(setuptools.command.install.install):
"""This is to force installing all the modules to the non-pure, platform-
specific lib directory, even though we haven't defined any 'ext_modules'.
The distutils 'install' command, in 'finalize_options' method, picks
either 'install_platlib' or 'install_purelib' based on whether the
'self.distribution.ext_modules' list is not empty.
Without this hack, auditwheel would flag the afdko wheel as invalid since
it contains native executables inside the pure lib folder.
TODO Remove this hack if/when in the future we install extension modules.
"""
def finalize_options(self):
setuptools.command.install.install.finalize_options(self)
self.install_lib = self.install_platlib
class CustomBuildScripts(distutils.command.build_scripts.build_scripts):
def copy_scripts(self):
"""Copy each script listed in 'self.scripts' *as is*, without
attempting to adjust the !# shebang. The default build_scripts command
in python3 calls tokenize to detect the text encoding, treating all
scripts as python scripts. But all our 'scripts' are native C
executables, thus the python3 tokenize module fails with SyntaxError
on them. Here we just skip the if branch where distutils attempts
to adjust the shebang.
"""
self.mkpath(self.build_dir)
outfiles = []
updated_files = []
for script in self.scripts:
script = convert_path(script)
outfile = os.path.join(self.build_dir, os.path.basename(script))
outfiles.append(outfile)
if not self.force and not newer(script, outfile):
log.debug("afdko: not copying %s (up-to-date)", script)
continue
try:
f = open(script, "rb")
except OSError:
if not self.dry_run:
raise
f = None
else:
first_line = f.readline()
if not first_line:
f.close()
self.warn("afdko: %s is an empty file (skipping)" % script)
continue
if f:
f.close()
updated_files.append(outfile)
self.copy_file(script, outfile)
return outfiles, updated_files
def _get_scripts():
script_names = [
'detype1', 'makeotfexe', 'mergefonts', 'rotatefont',
'sfntdiff', 'sfntedit', 'spot', 'tx', 'type1'
]
if platform.system() == 'Windows':
extension = '.exe'
else:
extension = ''
scripts = [f'bin/{script_name}{extension}'
for script_name in script_names]
return scripts
def _get_console_scripts():
script_entries = [
('buildcff2vf', 'buildcff2vf:main'),
('buildmasterotfs', 'buildmasterotfs:main'),
('comparefamily', 'comparefamily:main'),
('checkoutlinesufo', 'checkoutlinesufo:main'),
('makeotf', 'makeotf:main'),
('makeinstancesufo', 'makeinstancesufo:main'),
('otc2otf', 'otc2otf:main'),
('otf2otc', 'otf2otc:main'),
('otf2ttf', 'otf2ttf:main'),
('ttfcomponentizer', 'ttfcomponentizer:main'),
('ttfdecomponentizer', 'ttfdecomponentizer:main'),
('ttxn', 'ttxn:main'),
('charplot', 'proofpdf:charplot'),
('digiplot', 'proofpdf:digiplot'),
('fontplot', 'proofpdf:fontplot'),
('fontplot2', 'proofpdf:fontplot2'),
('fontsetplot', 'proofpdf:fontsetplot'),
('hintplot', 'proofpdf:hintplot'),
('waterfallplot', 'proofpdf:waterfallplot'),
('otfautohint', 'otfautohint.__main__:main'),
('otfstemhist', 'otfautohint.__main__:stemhist'),
]
scripts_path = 'afdko'
scripts = [f'{name} = {scripts_path}.{entry}'
for name, entry in script_entries]
return scripts
def _get_requirements():
with io.open("requirements.txt", encoding="utf-8") as requirements:
return [rl.replace("==", ">=") for rl in requirements.readlines()]
def main():
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3.8',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: Linux',
]
# concatenate README and NEWS into long_description so they are
# displayed on the afdko project page on PyPI
# Copied from fonttools setup.py
with io.open("README.md", encoding="utf-8") as readme:
long_description = readme.read()
long_description += '\n'
with io.open("NEWS.md", encoding="utf-8") as changelog:
long_description += changelog.read()
platform_name = get_platform()
setup(name="afdko",
use_scm_version=True,
description="Adobe Font Development Kit for OpenType",
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/adobe-type-tools/afdko',
author='Adobe Type team & friends',
author_email='[email protected]',
license='Apache License, Version 2.0',
classifiers=classifiers,
keywords='font development tools',
platforms=[platform_name],
package_dir={'': 'python'},
packages=['afdko', 'afdko.pdflib', 'afdko.otfautohint'],
include_package_data=True,
package_data={
'afdko': [
'resources/*.txt',
'resources/Adobe-CNS1/*',
'resources/Adobe-GB1/*',
'resources/Adobe-Japan1/*',
'resources/Adobe-Korea1/*'
],
},
zip_safe=False,
python_requires='>=3.8',
setup_requires=[
'wheel',
'setuptools_scm',
'scikit-build',
'cmake',
'ninja'
],
tests_require=[
'pytest',
],
install_requires=_get_requirements(),
scripts=_get_scripts(),
entry_points={
'console_scripts': _get_console_scripts(),
},
cmdclass={
'build_scripts': CustomBuildScripts,
'bdist_wheel': CustomBDistWheel,
'install': InstallPlatlib,
},
)
if __name__ == '__main__':
main()