forked from Nuitka/Nuitka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
246 lines (197 loc) · 7.04 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
# Copyright 2016, 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.
#
import os
import sys
from distutils.command.install_scripts import install_scripts
from distutils.core import setup
os.chdir(os.path.dirname(__file__) or '.')
scripts = ["bin/nuitka", "bin/nuitka-run"]
# 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():
version_line, = [
line
for line in
open("nuitka/Options.py")
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 find_packages():
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.
if "__init__.py" not in filenames:
continue
result.append(
root.replace(os.path.sep,'.')
)
return result
package = find_packages()
class NuitkaInstallScripts(install_scripts):
"""
This is a specialization of install_scripts that replaces the @LIBDIR@ with
the configured directory for modules. If possible, the path is made relative
to the directory for scripts.
"""
def initialize_options(self):
install_scripts.initialize_options(self)
self.install_lib = None
def finalize_options(self):
install_scripts.finalize_options(self)
self.set_undefined_options("install", ("install_lib", "install_lib"))
def run(self):
install_scripts.run(self)
if os.path.splitdrive(self.install_dir)[0] != \
os.path.splitdrive(self.install_lib)[0]:
# can't make relative paths from one drive to another, so use an
# absolute path instead
libdir = self.install_lib
else:
common = os.path.commonprefix(
(self.install_dir, self.install_lib )
)
rest = self.install_dir[len(common):]
uplevel = len([n for n in os.path.split(rest) if n ])
libdir = uplevel * (".." + os.sep) + self.install_lib[len(common):]
patch_bats = os.path.exists(
os.path.join(self.install_dir, "Python.exe")
)
for outfile in self.outfiles:
fp = open(outfile, "rb")
data = fp.read()
fp.close()
# skip binary files
if b'\0' in data:
continue
old_data = data
data = data.replace(b"@LIBDIR@", libdir.encode("unicode_escape"))
if patch_bats and outfile.endswith(".bat"):
data = data.replace(b"..\\",b"")
if data != old_data:
fp = open(outfile, "wb")
fp.write(data)
fp.close()
cmdclass = {
"install_scripts" : NuitkaInstallScripts,
}
try:
import setuptools.command.easy_install
except ImportError:
pass
else:
orig_easy_install = setuptools.command.easy_install.easy_install
class NuitkaEasyInstall(setuptools.command.easy_install.easy_install):
@staticmethod
def _load_template(dev_path):
result = orig_easy_install._load_template(dev_path)
result = result.replace(
"__import__('pkg_resources')",
"# __import__('pkg_resources')",
)
return result
setuptools.command.easy_install.easy_install = NuitkaEasyInstall
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"
# Lets hack the byte_compile function so it doesn't byte compile Scons built-in
# copy with Python3.
if sys.version_info >= (3,):
from distutils import util
real_byte_compile = util.byte_compile
def byte_compile(py_files, *args, **kw):
py_files = [
py_file
for py_file in py_files
if "inline_copy" not in py_file
]
real_byte_compile(py_files, *args, **kw)
util.byte_compile = byte_compile
setup(
name = project_name,
license = "Apache License, Version 2.0",
version = version,
packages = find_packages(),
scripts = scripts,
cmdclass = cmdclass,
package_data = {
# Include extra files
"" : ["*.txt", "*.rst", "*.c", "*.h", "*.ui"],
"nuitka.build" : [
"SingleExe.scons",
"static_src/*.c",
"static_src/*/*.c",
"static_src/*/*.h",
"static_src/*/*.asm",
"static_src/*/*.S",
"include/*.h",
"include/*/*.h",
"include/*/*/*.h",
] + scons_files,
"nuitka.gui" : [
"dialogs/*.ui",
],
},
# metadata for upload to PyPI
author = "Kay Hayen",
author_email = "[email protected]",
url = "http://nuitka.net",
description = """\
Python compiler with full language support and CPython compatibility""",
keywords = "compiler,python,nuitka",
)