forked from Nuitka/Nuitka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
455 lines (381 loc) · 15.3 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# Copyright 2023, Kay Hayen, mailto:[email protected]
#
# Part of "Nuitka", an optimizing Python compiler that is compatible and
# integrates with CPython, but also works on its own.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
""" Setup file for Nuitka.
This applies a few tricks. First, the Nuitka version is read from
the source code. Second, the packages are scanned from the filesystem,
and third, the byte code compilation is avoided for inline copies of
scons with mismatching Python major versions. Also a binary distribution
is enforced, to avoid being cached with wrong inline copies for the
Python version.
spellchecker: ignore chdir,pythonw,tqdm,distutil,atomicwrites,markupsafe
spellchecker: ignore wininst,distclass,Containerfile,orderedset
"""
import os
import sys
os.chdir(os.path.dirname(__file__) or ".")
sys.path.insert(0, os.path.abspath(os.getcwd()))
# isort:start
import fnmatch
import re
from setuptools import Distribution, setup
from setuptools.command import easy_install
# TODO: We need a better solution for this, probably error exit, once sys.exit
# is optimized for. This is to avoid descending into Nuitka through distutils.
if __name__ == "__main__":
from nuitka.PythonFlavors import isMSYS2MingwPython
from nuitka.utils.FileOperations import getFileList
from nuitka.Version import getNuitkaVersion
scripts = []
# For Windows, there are batch files to launch Nuitka.
if os.name == "nt" and not isMSYS2MingwPython():
scripts += ["misc/nuitka.bat", "misc/nuitka-run.bat"]
version = getNuitkaVersion()
def findNuitkaPackages():
result = []
for root, dirnames, filenames in os.walk("nuitka"):
# Packages must contain "__init__.py" or they are merely directories
# in Nuitka as we are Python2 compatible.
if "__init__.py" not in filenames:
continue
# The "release" namespace is code used to release, but not itself for
# release, same goes for "quality".
if "release" in dirnames:
dirnames.remove("release")
if "quality" in dirnames:
dirnames.remove("quality")
# Handled separately.
if "inline_copy" in dirnames:
dirnames.remove("inline_copy")
result.append(root.replace(os.path.sep, "."))
return result
inline_copy_files = []
no_byte_compile = []
def addDataFiles(data_files, base_path, do_byte_compile=True):
patterns = (
"%s/*.py" % base_path,
"%s/*/*.py" % base_path,
"%s/*/*/*.py" % base_path,
"%s/*/*/*/*.py" % base_path,
"%s/*/*/*/*/*.py" % base_path,
"%s/config*" % base_path,
"%s/LICENSE*" % base_path,
"%s/*/LICENSE*" % base_path,
"%s/READ*" % base_path,
)
data_files.extend(patterns)
if not do_byte_compile:
no_byte_compile.extend(patterns)
def addInlineCopy(name, do_byte_compile=True):
if int(os.environ.get("NUITKA_NO_INLINE_COPY", 0)) == 1:
return
addDataFiles(
inline_copy_files, "inline_copy/%s" % name, do_byte_compile=do_byte_compile
)
addInlineCopy("appdirs")
addInlineCopy("glob2")
addInlineCopy("markupsafe")
addInlineCopy("tqdm")
sdist_mode = "sdist" in sys.argv
if os.name == "nt" or sdist_mode:
addInlineCopy("atomicwrites")
addInlineCopy("clcache")
addInlineCopy("colorama")
if sys.version_info < (3,) or sdist_mode:
addInlineCopy("yaml_27")
if (3,) < sys.version_info < (3, 6) or sdist_mode:
addInlineCopy("yaml_35")
if sys.version_info >= (3, 6) or sdist_mode:
addInlineCopy("yaml")
if sys.version_info < (3, 6) or sdist_mode:
addInlineCopy("jinja2_35")
if sys.version_info >= (3, 6) or sdist_mode:
addInlineCopy("jinja2")
addInlineCopy("pkg_resources")
# Scons really only, with historic naming and positioning. Needs to match the
# "scons.py" in bin with respect to versions selection.
addInlineCopy("bin")
if os.name == "nt" or sdist_mode:
addInlineCopy("lib/scons-4.3.0", do_byte_compile=sys.version_info >= (3,))
if (os.name != "nt" and sys.version_info < (2, 7)) or sdist_mode:
addInlineCopy("lib/scons-2.3.2")
if (os.name != "nt" and sys.version_info >= (2, 7)) or sdist_mode:
addInlineCopy("lib/scons-3.1.2")
nuitka_packages = findNuitkaPackages()
# Include extra files
package_data = {
"": ["*.txt", "*.rst", "*.c", "*.h", "*.yml"],
"nuitka.build": [
"*.scons",
"static_src/*.c",
"static_src/*.cpp",
"static_src/*/*.c",
"static_src/*/*.h",
"inline_copy/zstd/LICENSE.txt",
"inline_copy/zstd/*.h",
"inline_copy/zstd/*/*.h",
"inline_copy/zstd/*/*.c",
"static_src/*/*.asm",
"static_src/*/*.S",
"include/*.h",
"include/*/*.h",
"include/*/*/*.h",
]
+ inline_copy_files,
"nuitka.code_generation": ["templates_c/*.j2"],
"nuitka.reports": ["*.j2"],
}
if "nuitka.plugins.commercial" in nuitka_packages:
commercial_data_files = []
commercial_plugins_dir = os.path.join("nuitka", "plugins", "commercial")
for filename in getFileList(commercial_plugins_dir):
filename_relative = os.path.relpath(filename, commercial_plugins_dir)
if (
filename_relative.endswith(".py")
and os.path.basename(filename_relative) == filename_relative
):
continue
if filename.endswith((".py", ".yml", ".c", ".h", ".plk", ".tmd")):
commercial_data_files.append(filename_relative)
continue
filename_base = os.path.basename(filename_relative)
if filename_base.startswith("LICENSE"):
commercial_data_files.append(filename_relative)
continue
package_data["nuitka.plugins.commercial"] = commercial_data_files
package_data["nuitka.tools.commercial.container_build"] = ["Containerfile"]
try:
import distutils.util
except ImportError:
# Python 3.12 might do this, we need to find out where to disable the
# bytecode compilation there.
pass
else:
orig_byte_compile = distutils.util.byte_compile
def byte_compile(py_files, *args, **kw):
# Disable bytecode compilation output, too annoying.
kw["verbose"] = 0
# Avoid attempting files that won't work.
py_files = [
filename
for filename in py_files
if not any(
fnmatch.fnmatch(filename, "*/*/*/" + pattern)
for pattern in no_byte_compile
)
]
orig_byte_compile(py_files, *args, **kw)
distutils.util.byte_compile = byte_compile
# We monkey patch easy install script generation to not load pkg_resources,
# which is very slow to launch. This can save one second or more per launch
# of Nuitka.
runner_script_template = """\
# -*- coding: utf-8 -*-
# Launcher for Nuitka
import nuitka.__main__
nuitka.__main__.main()
"""
# This is for newer setuptools:
@classmethod
def get_args(cls, dist, header=None):
"""
Yield write_script() argument tuples for a distribution's
console_scripts and gui_scripts entry points.
"""
if header is None:
header = cls.get_header()
for type_ in "console", "gui":
group = type_ + "_scripts"
for name, _ep in dist.get_entry_map(group).items():
script_text = runner_script_template
args = cls._get_script_args(type_, name, header, script_text)
for res in args:
yield res
try:
easy_install.ScriptWriter.get_args = get_args
except AttributeError:
pass
# This is for older setuptools:
def get_script_args(dist, executable=os.path.normpath(sys.executable), wininst=False):
"""Yield write_script() argument tuples for a distribution's entrypoints"""
header = easy_install.get_script_header("", executable, wininst)
for group in "console_scripts", "gui_scripts":
for name, _ep in dist.get_entry_map(group).items():
script_text = runner_script_template
if sys.platform == "win32" or wininst:
# On Windows/wininst, add a .py extension and an .exe launcher
if group == "gui_scripts":
launcher_type = "gui"
ext = "-script.pyw"
old = [".pyw"]
new_header = re.sub("(?i)python.exe", "pythonw.exe", header)
else:
launcher_type = "cli"
ext = "-script.py"
old = [".py", ".pyc", ".pyo"]
new_header = re.sub("(?i)pythonw.exe", "python.exe", header)
if (
os.path.exists(new_header[2:-1].strip('"'))
or sys.platform != "win32"
):
hdr = new_header
else:
hdr = header
yield (name + ext, hdr + script_text, "t", [name + x for x in old])
yield (
name + ".exe",
easy_install.get_win_launcher(launcher_type),
"b", # write in binary mode
)
if not easy_install.is_64bit():
# install a manifest for the launcher to prevent Windows
# from detecting it as an installer (which it will for
# launchers like easy_install.exe). Consider only
# adding a manifest for launchers detected as installers.
# See Distribute #143 for details.
m_name = name + ".exe.manifest"
yield (m_name, easy_install.load_launcher_manifest(name), "t")
else:
# On other platforms, we assume the right thing to do is to
# just write the stub with no extension.
yield (name, header + script_text)
try:
easy_install.get_script_args
except AttributeError:
pass
else:
easy_install.get_script_args = get_script_args
binary_suffix = "%d" % sys.version_info[0]
if os.name == "nt" and not isMSYS2MingwPython():
console_scripts = []
else:
console_scripts = [
"nuitka%s = nuitka.__main__:main" % binary_suffix,
"nuitka%s-run = nuitka.__main__:main" % binary_suffix,
]
# With this, we can enforce a binary package.
class BinaryDistribution(Distribution):
"""Distribution which always forces a binary package with platform name"""
@staticmethod
def has_ext_modules():
return True
with open("README.rst", "rb") as input_file:
long_description = input_file.read().decode("utf8")
# Need to remove the ..contents etc from the rest, or else PyPI will not render
# it.
long_description = long_description.replace(".. contents::\n", "")
long_description = long_description.replace(
".. image:: doc/images/Nuitka-Logo-Symbol.png\n", ""
)
install_requires = []
if sys.version_info >= (3, 7):
install_requires.append("ordered-set >= 4.1.0")
if sys.version_info[:2] == (2, 7):
install_requires.append("subprocess32")
if sys.version_info >= (3, 7):
install_requires.append("zstandard >= 0.15")
if os.name != "nt" and sys.platform != "darwin" and sys.version_info < (3, 7):
install_requires.append("orderedset >= 2.0.3")
if sys.platform == "darwin" and sys.version_info < (3, 7):
install_requires.append("orderedset >= 2.0.3")
setup(
name="Nuitka",
license="Apache License, Version 2.0",
version=version,
long_description=long_description,
long_description_content_type="text/x-rst",
classifiers=[
# Nuitka is mature even
"Development Status :: 5 - Production/Stable",
# Indicate who Nuitka is for
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
# Nuitka is a compiler and a build tool as such.
"Topic :: Software Development :: Compilers",
"Topic :: Software Development :: Build Tools",
# Is has a weak subset of PyLint, but aims for more long term
"Topic :: Software Development :: Quality Assurance",
# Nuitka standalone mode aims at distribution
"Topic :: System :: Software Distribution",
# Python2 supported versions.
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
# Python3 supported versions.
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
# We depend on CPython.
"Programming Language :: Python :: Implementation :: CPython",
# We generate C intermediate code and implement part of the
# run time environment in C. Actually C11.
"Programming Language :: C",
# Supported OSes are many
"Operating System :: POSIX :: Linux",
"Operating System :: POSIX :: BSD :: FreeBSD",
"Operating System :: POSIX :: BSD :: NetBSD",
"Operating System :: POSIX :: BSD :: OpenBSD",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
"Operating System :: Android",
# License
"License :: OSI Approved :: Apache Software License",
],
packages=nuitka_packages,
package_data=package_data,
# metadata for upload to PyPI
author="Kay Hayen",
author_email="[email protected]",
url="https://nuitka.net",
description="""\
Python compiler with full language support and CPython compatibility""",
keywords="compiler,python,nuitka",
project_urls={
"Commercial": "https://nuitka.net/doc/commercial.html",
"Support": "https://nuitka.net/pages/support.html",
"Documentation": "https://nuitka.net/doc/user-manual.html",
"Donations": "https://nuitka.net/pages/donations.html",
"Mastodon": "https://fosstodon.org/@kayhayen",
"Twitter": "https://twitter.com/KayHayen",
"Source": "https://github.com/Nuitka/Nuitka",
},
zip_safe=False,
scripts=scripts,
entry_points={
"distutils.commands": [
"bdist_nuitka = \
nuitka.distutils.DistutilCommands:bdist_nuitka",
"build_nuitka = \
nuitka.distutils.DistutilCommands:build",
"install_nuitka = \
nuitka.distutils.DistutilCommands:install",
],
"distutils.setup_keywords": [
"build_with_nuitka = nuitka.distutils.DistutilCommands:setupNuitkaDistutilsCommands"
],
"console_scripts": console_scripts,
},
install_requires=install_requires,
# As we do version specific hacks for installed inline copies, make the
# wheel version and platform specific.
distclass=BinaryDistribution,
)