forked from Nuitka/Nuitka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
341 lines (292 loc) · 11.6 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
# Copyright 2021, 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.
"""
import os
import re
import sys
from setuptools import setup
from setuptools.command import easy_install
os.chdir(os.path.dirname(__file__) or ".")
scripts = []
# For Windows, there are batch files to launch Nuitka.
if os.name == "nt":
scripts += ["misc/nuitka.bat", "misc/nuitka-run.bat"]
# Detect the version of Nuitka from its source directly. Without calling it, we
# don't mean to pollute with ".pyc" files and similar effects.
def detectVersion():
with open("nuitka/Version.py") as version_file:
(version_line,) = [line for line in version_file if line.startswith("Nuitka V")]
return version_line.split("V")[1].strip()
version = detectVersion()
# The MSI installer enforces a 3 digit version number, which is stupid, but no
# way around it, so we map our number to it, in some way.
if os.name == "nt" and "bdist_msi" in sys.argv:
# Pre-releases are always smaller, official releases get the "1".
middle = 1 if "rc" not in version else 0
version = version.replace("rc", "")
parts = version.split(".")
major, first, last = parts[:3]
hotfix = parts[3] if len(parts) > 3 else 0
version = ".".join(
"%s" % value
for value in (
int(major) * 10 + int(first),
middle,
int(last) * 10 + int(hotfix),
)
)
def findNuitkaPackages():
result = []
for root, dirnames, filenames in os.walk("nuitka"):
# Ignore the inline copy of scons, these are not packages of Nuitka.
if "scons-" in root:
continue
# 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 "qualit"y.
if "release" in dirnames:
dirnames.remove("release")
if "quality" in dirnames:
dirnames.remove("quality")
result.append(root.replace(os.path.sep, "."))
return result
if (
os.path.exists("/usr/bin/scons")
and "sdist" not in sys.argv
and "bdist_wininst" not in sys.argv
and "bdist_msi" not in sys.argv
):
scons_files = []
else:
scons_files = [
"inline_copy/*/*.py",
"inline_copy/*/*/*.py",
"inline_copy/*/*/*/*.py",
"inline_copy/*/*/*/*/*.py",
"inline_copy/*/*/*/*/*/*.py",
]
# Have different project names for MSI installers, so 32 and 64 bit versions do
# not conflict.
if "bdist_msi" in sys.argv:
project_name = "Nuitka%s" % (64 if "AMD64" in sys.version else 32)
else:
project_name = "Nuitka"
import distutils.util
orig_byte_compile = distutils.util.byte_compile
def byte_compile(py_files, *args, **kw):
# Lets hack the byte_compile function so it doesn't byte compile old Scons built-in
# copy with Python3 or Windows as it's not used there.
if sys.version_info >= (3,) or (os.name == "nt" and "sdist" not in sys.argv):
py_files = [py_file for py_file in py_files if "scons-2.3.2" not in py_file]
# Disable bytecode compilation output, too annoying.
kw["verbose"] = 0
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( # pylint: disable=protected-access
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
if sys.version_info[0] == 2:
binary_suffix = ""
else:
binary_suffix = "%d" % sys.version_info[0]
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", ""
)
long_description = long_description.replace(
".. raw:: pdf\n\n PageBreak oneColumn\n SetPageCounter 1", ""
)
setup(
name=project_name,
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",
# 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",
# License
"License :: OSI Approved :: Apache Software License",
],
packages=findNuitkaPackages(),
package_data={
# Include extra files
"": ["*.txt", "*.rst", "*.c", "*.h", "*.ui"],
"nuitka.build": [
"Backend.scons",
"Onefile.scons",
"static_src/*.c",
"static_src/*/*.c",
"static_src/*/*.h",
"static_src/*/*.asm",
"static_src/*/*.S",
"include/*.h",
"include/*/*.h",
"include/*/*/*.h",
]
+ scons_files,
},
# 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",
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": [
"nuitka%s = nuitka.__main__:main" % binary_suffix,
"nuitka%s-run = nuitka.__main__:main" % binary_suffix,
],
},
)