forked from marcelotduarte/cx_Freeze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·195 lines (179 loc) · 7.45 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
"""
Distutils script for cx_Freeze.
"""
import distutils.command.build_ext
import distutils.command.install
import distutils.command.install_data
import distutils.sysconfig
import os
import sys
if sys.version_info < (3, 5):
sys.exit("Sorry, Python < 3.5 is not supported. Use cx_Freeze 5 for "
"support of earlier Python versions.")
try:
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup
from distutils.extension import Extension
class build_ext(distutils.command.build_ext.build_ext):
def build_extension(self, ext):
if "bases" not in ext.name:
distutils.command.build_ext.build_ext.build_extension(self, ext)
return
if sys.platform == "win32" and self.compiler.compiler_type == "mingw32":
ext.sources.append("source/bases/manifest.rc")
os.environ["LD_RUN_PATH"] = "${ORIGIN}/../lib:${ORIGIN}/lib"
objects = self.compiler.compile(ext.sources,
output_dir = self.build_temp,
include_dirs = ext.include_dirs,
debug = self.debug,
depends = ext.depends)
fileName = os.path.splitext(self.get_ext_filename(ext.name))[0]
if self.inplace:
fullName = os.path.join(os.path.dirname(__file__), fileName)
else:
fullName = os.path.join(self.build_lib, fileName)
libraryDirs = ext.library_dirs or []
libraries = self.get_libraries(ext)
extraArgs = ext.extra_link_args or []
if sys.platform == "win32":
compiler_type = self.compiler.compiler_type
if compiler_type == "msvc":
extraArgs.append("/MANIFEST")
elif compiler_type == "mingw32":
if "Win32GUI" in ext.name:
extraArgs.append("-mwindows")
else:
extraArgs.append("-mconsole")
if sys.version_info[0] == 3:
extraArgs.append("-municode")
else:
vars = distutils.sysconfig.get_config_vars()
libraryDirs.append(vars["LIBPL"])
abiflags = getattr(sys, "abiflags", "")
libraries.append("python%s.%s%s" % \
(sys.version_info[0], sys.version_info[1], abiflags))
if vars["LINKFORSHARED"] and sys.platform != "darwin":
extraArgs.extend(vars["LINKFORSHARED"].split())
if vars["LIBS"]:
extraArgs.extend(vars["LIBS"].split())
if vars["LIBM"]:
extraArgs.append(vars["LIBM"])
if vars["BASEMODLIBS"]:
extraArgs.extend(vars["BASEMODLIBS"].split())
if vars["LOCALMODLIBS"]:
extraArgs.extend(vars["LOCALMODLIBS"].split())
extraArgs.append("-s")
self.compiler.link_executable(objects, fullName,
libraries = libraries,
library_dirs = libraryDirs,
runtime_library_dirs = ext.runtime_library_dirs,
extra_postargs = extraArgs,
debug = self.debug)
def get_ext_filename(self, name):
fileName = distutils.command.build_ext.build_ext.get_ext_filename(self,
name)
if name.endswith("util"):
return fileName
vars = distutils.sysconfig.get_config_vars()
soExt = vars.get("EXT_SUFFIX", vars.get("SO"))
ext = self.compiler.exe_extension or ""
return fileName[:-len(soExt)] + ext
def find_cx_Logging():
dirName = os.path.dirname(os.getcwd())
loggingDir = os.path.join(dirName, "cx_Logging")
if not os.path.exists(loggingDir):
return
subDir = "implib.%s-%s" % (distutils.util.get_platform(), sys.version[:3])
importLibraryDir = os.path.join(loggingDir, "build", subDir)
includeDir = os.path.join(loggingDir, "src")
if not os.path.exists(importLibraryDir):
return
return includeDir, importLibraryDir
commandClasses = dict(build_ext=build_ext)
# build utility module
if sys.platform == "win32":
libraries = ["imagehlp", "Shlwapi"]
else:
libraries = []
utilModule = Extension("cx_Freeze.util", ["source/util.c"],
libraries = libraries)
# build base executables
docFiles = "README.txt"
options = dict(install=dict(optimize=1))
depends = ["source/bases/Common.c"]
console = Extension("cx_Freeze.bases.Console", ["source/bases/Console.c"],
depends = depends, libraries = libraries)
extensions = [utilModule, console]
if sys.platform == "win32":
gui = Extension("cx_Freeze.bases.Win32GUI", ["source/bases/Win32GUI.c"],
depends = depends, libraries = libraries + ["user32"])
extensions.append(gui)
moduleInfo = find_cx_Logging()
if moduleInfo is not None:
includeDir, libraryDir = moduleInfo
service = Extension("cx_Freeze.bases.Win32Service",
["source/bases/Win32Service.c"], depends = depends,
library_dirs = [libraryDir],
libraries = libraries + ["advapi32", "cx_Logging"],
include_dirs = [includeDir])
extensions.append(service)
# define package data
packageData = []
for fileName in os.listdir(os.path.join("cx_Freeze", "initscripts")):
name, ext = os.path.splitext(fileName)
if ext != ".py":
continue
packageData.append("initscripts/%s" % fileName)
for fileName in os.listdir(os.path.join("cx_Freeze", "samples")):
dirName = os.path.join("cx_Freeze", "samples", fileName)
if not os.path.isdir(dirName):
continue
packageData.append("samples/%s/*.py" % fileName)
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Python Software Foundation License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: C",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Software Distribution",
"Topic :: Utilities"
]
with open("cx_Freeze/__init__.py") as fp:
for line in fp:
if line.startswith('__version__'):
version = line.replace('__version__ = "', '').replace('"\n', '')
break
setup(name = "cx_Freeze",
description = "create standalone executables from Python scripts",
long_description = "create standalone executables from Python scripts",
version = version,
cmdclass = commandClasses,
options = options,
ext_modules = extensions,
packages = ['cx_Freeze'],
maintainer="Anthony Tuininga",
maintainer_email="[email protected]",
url = "https://anthony-tuininga.github.io/cx_Freeze",
classifiers = classifiers,
keywords = "freeze",
license = "Python Software Foundation License",
package_data = {"cx_Freeze" : packageData },
entry_points = {
'console_scripts': [
'cxfreeze = cx_Freeze.main:main',
'cxfreeze-quickstart = cx_Freeze.setupwriter:main',
],
},
zip_safe=False,
)