[r377]: trunk / py2exe / setup.py  Maximize  Restore  History

Download this file

408 lines (347 with data), 16.3 kB

  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
##
## Copyright (c) 2000, 2001, 2002, 2003 Thomas Heller
##
## Permission is hereby granted, free of charge, to any person obtaining
## a copy of this software and associated documentation files (the
## "Software"), to deal in the Software without restriction, including
## without limitation the rights to use, copy, modify, merge, publish,
## distribute, sublicense, and/or sell copies of the Software, and to
## permit persons to whom the Software is furnished to do so, subject to
## the following conditions:
##
## The above copyright notice and this permission notice shall be
## included in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
## LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
## OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
## WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
##
"""This package is a distutils extension to build
standalone windows executable programs from
python scripts.
"""
__version__ = "0.4.2"
# $Id: setup.py 247 2003-08-22 19:55:33Z theller $
import sys, os, string
from distutils.core import setup, Extension, Command
from distutils.dist import Distribution
from distutils.command import build_ext, build
from distutils.sysconfig import customize_compiler
from distutils.dep_util import newer_group
from distutils.errors import *
class Interpreter(Extension):
def __init__(self, *args, **kw):
# Add a custom 'target_desc' option, which matches CCompiler
# (is there a better way?
if kw.has_key("target_desc"):
self.target_desc = kw['target_desc']
del kw['target_desc']
else:
self.target_desc = "executable"
Extension.__init__(self, *args, **kw)
class Dist(Distribution):
def __init__(self,attrs):
self.interpreters = None
Distribution.__init__(self,attrs)
def has_interpreters(self):
return self.interpreters and len(self.interpreters) > 0
class BuildInterpreters(build_ext.build_ext):
description = "build special python interpreter stubs"
def finalize_options(self):
build_ext.build_ext.finalize_options(self)
self.interpreters = self.distribution.interpreters
def run (self):
if not self.interpreters:
return
self.setup_compiler()
# Now actually compile and link everything.
for inter in self.interpreters:
sources = inter.sources
if sources is None or type(sources) not in (type([]), type(())):
raise DistutilsSetupError, \
("in 'interpreters' option ('%s'), " +
"'sources' must be present and must be " +
"a list of source filenames") % inter.name
sources = list(sources)
fullname = self.get_exe_fullname(inter.name)
if self.inplace:
# ignore build-lib -- put the compiled extension into
# the source tree along with pure Python modules
modpath = string.split(fullname, '.')
package = string.join(modpath[0:-1], '.')
base = modpath[-1]
build_py = self.get_finalized_command('build_py')
package_dir = build_py.get_package_dir(package)
exe_filename = os.path.join(package_dir,
self.get_exe_filename(base))
else:
exe_filename = os.path.join(self.build_lib,
self.get_exe_filename(fullname))
if not (self.force or \
newer_group(sources, exe_filename + '.exe', 'newer')):
self.announce("skipping '%s' interpreter (up-to-date)" %
inter.name)
continue # 'for' loop over all interpreters
else:
self.announce("building '%s' interpreter" % inter.name)
sources = self.swig_sources(sources)
extra_args = inter.extra_compile_args or []
macros = inter.define_macros[:]
for undef in inter.undef_macros:
macros.append((undef,))
objects = self.compiler.compile(sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=inter.include_dirs,
debug=self.debug,
extra_postargs=extra_args)
if inter.extra_objects:
objects.extend(inter.extra_objects)
extra_args = inter.extra_link_args or []
print "Calling link with", inter.target_desc
# XXX - is msvccompiler.link broken? From what I can see, the
# following should work, instead of us checking the param:
# self.compiler.link(inter.target_desc,
if inter.target_desc == 'executable':
linker = self.compiler.link_executable
else:
linker = self.compiler.link_shared_lib
linker(
objects, exe_filename,
libraries=self.get_libraries(inter),
library_dirs=inter.library_dirs,
runtime_library_dirs=inter.runtime_library_dirs,
extra_postargs=extra_args,
debug=self.debug)
# cannot use upx any longer, since this collides with
# the update resource code.
# build_extensions ()
def get_exe_fullname (self, inter_name):
if self.package is None:
return inter_name
else:
return self.package + '.' + inter_name
def get_exe_filename (self, inter_name):
ext_path = string.split(inter_name, '.')
if self.debug:
return apply(os.path.join, ext_path) + '_d'
return apply(os.path.join, ext_path)
def setup_compiler(self):
# This method *should* be available separately in build_ext!
from distutils.ccompiler import new_compiler
# If we were asked to build any C/C++ libraries, make sure that the
# directory where we put them is in the library search path for
# linking interpreters.
if self.distribution.has_c_libraries():
build_clib = self.get_finalized_command('build_clib')
self.libraries.extend(build_clib.get_library_names() or [])
self.library_dirs.append(build_clib.build_clib)
# Setup the CCompiler object that we'll use to do all the
# compiling and linking
self.compiler = new_compiler(compiler=self.compiler,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force)
customize_compiler(self.compiler)
# And make sure that any compile/link-related options (which might
# come from the command-line or from the setup script) are set in
# that CCompiler object -- that way, they automatically apply to
# all compiling and linking done here.
if self.include_dirs is not None:
self.compiler.set_include_dirs(self.include_dirs)
if self.define is not None:
# 'define' option is a list of (name,value) tuples
for (name,value) in self.define:
self.compiler.define_macro(name, value)
if self.undef is not None:
for macro in self.undef:
self.compiler.undefine_macro(macro)
if self.libraries is not None:
self.compiler.set_libraries(self.libraries)
if self.library_dirs is not None:
self.compiler.set_library_dirs(self.library_dirs)
if self.rpath is not None:
self.compiler.set_runtime_library_dirs(self.rpath)
if self.link_objects is not None:
self.compiler.set_link_objects(self.link_objects)
# setup_compiler()
# class BuildInterpreters
def InstallSubCommands():
"""Adds our own sub-commands to build and install"""
has_interpreters = lambda self: self.distribution.has_interpreters()
buildCmds = [('build_interpreters', has_interpreters)]
build.build.sub_commands.extend(buildCmds)
InstallSubCommands()
############################################################################
class deinstall(Command):
description = "Remove all installed files"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
self.run_command('build')
build = self.get_finalized_command('build')
install = self.get_finalized_command('install')
self.announce("removing files")
for n in 'platlib', 'purelib', 'headers', 'scripts', 'data':
dstdir = getattr(install, 'install_' + n)
try:
srcdir = getattr(build, 'build_' + n)
except AttributeError:
pass
else:
self._removefiles(dstdir, srcdir)
def _removefiles(self, dstdir, srcdir):
# Remove all files in dstdir which are present in srcdir
assert dstdir != srcdir
if not os.path.isdir(srcdir):
return
for n in os.listdir(srcdir):
name = os.path.join(dstdir, n)
if os.path.isfile(name):
self.announce("removing '%s'" % name)
if not self.dry_run:
try:
os.remove(name)
except OSError, details:
self.warn("Could not remove file: %s" % details)
if os.path.splitext(name)[1] == '.py':
# Try to remove .pyc and -pyo files also
try:
os.remove(name + 'c')
except OSError:
pass
try:
os.remove(name + 'o')
except OSError:
pass
elif os.path.isdir(name):
self._removefiles(name, os.path.join(srcdir, n))
if not self.dry_run:
try:
os.rmdir(name)
except OSError, details:
self.warn("Are there additional user files?\n"\
" Could not remove directory: %s" % details)
else:
self.announce("skipping removal of '%s' (does not exist)" %\
name)
############################################################################
run = Interpreter("py2exe.run",
["source/run.c", "source/start.c", "source/icon.rc"],
include_dirs=["source/zlib"],
libraries=["zlibstat"],
library_dirs=["source/zlib/static32"],
extra_link_args=["/NOD:LIBC"],
define_macros=[("ZLIB_DLL", None), ("_WINDOWS", None)],
)
run_w = Interpreter("py2exe.run_w",
["source/run_w.c", "source/start.c", "source/icon.rc"],
include_dirs=["source/zlib"],
libraries=["zlibstat", "user32"],
library_dirs=["source/zlib/static32"],
extra_link_args=["/NOD:LIBC"],
define_macros=[("ZLIB_DLL", None), ("_WINDOWS", None)],
)
msg = """PYWIN32DIR invalid.
To build py2exe from source, you must either:
- Download and build Mark Hammond's pywin32 source code
from http://starship.python.net/crew/mhammond, and set
the PYWIN32DIR variable to point to this directory
- or change this setup script to not build run_svc target,
then you will not be able to build Windows NT services
with py2exe.
"""
def _check_build_dir(map, key, source_root_name, child):
check = os.path.join(source_root_name, child)
if os.path.isdir(check):
map[key] = check
return True
return False
def _get_build_dirs(source_root_name):
ret = {}
if _check_build_dir(ret, "win32", source_root_name, "build/temp.win32-%s/Release" % sys.winver):
pass
elif _check_build_dir(ret, "win32", source_root_name, "win32/build"):
pass
# todo: add com etc maybe?
return ret
PYWIN32DIR = os.environ.get("PYWIN32DIR", os.path.abspath(r"\pywin32"))
build_dirs = _get_build_dirs(PYWIN32DIR)
if not build_dirs.has_key("win32"):
# Check dev studio build running in place
# win32api.__file__: 'prefix\\pywin32\\win32\\Build\\win32api.pyd'
# PYWIN32DIR -> 'prefix\\pywin32'
try:
import win32api
except ImportError:
raise RuntimeError, msg
PYWIN32DIR = os.path.dirname(os.path.dirname(os.path.dirname(win32api.__file__)))
build_dirs = _get_build_dirs(PYWIN32DIR)
if not build_dirs.has_key("win32"):
raise RuntimeError, msg
pywintypes_lib = os.path.join(build_dirs["win32"], "pywintypes.lib")
if not os.path.isfile(pywintypes_lib):
raise RuntimeError, msg
run_svc = Interpreter("py2exe.run_svc",
["source/PythonService.cpp",
"source/run_svc.c", "source/start.c",
PYWIN32DIR + "/win32/src/PythonServiceMessages.mc"
],
include_dirs=["source/zlib",
PYWIN32DIR + "/win32/src"],
libraries=["zlibstat", "user32", "advapi32",
"oleaut32", "ole32", "shell32"],
library_dirs=["source/zlib/static32",
build_dirs["win32"]],
extra_link_args=["/NOD:LIBC"],
define_macros=[("ZLIB_DLL", None),
("_WINDOWS", None),
("BUILD_FREEZE", None),
("BUILD_PY2EXE", None),
("WIN32", None),
("__WIN32__", None),
## ("_UNICODE", None),
## ("UNICODE", None),
("NDEBUG", None),
("STRICT", None)
]
)
run_dll = Interpreter("py2exe.run_dll",
["source/run_dll.c", "source/start.c", "source/icon.rc"],
include_dirs=["source/zlib"],
libraries=["zlibstat", "user32"],
library_dirs=["source/zlib/static32"],
extra_link_args=["/NOD:LIBC", "/def:source/run_dll.def"],
define_macros=[("ZLIB_DLL", None), ("_WINDOWS", None)],
target_desc = "shared_library",
)
setup(name="py2exe",
version=__version__,
description="Build standalone executables for windows",
long_description=__doc__,
author="Thomas Heller",
author_email="theller@python.net",
url="http://starship.python.net/crew/theller/py2exe/",
license="MIT/X11",
platforms="Windows",
download_url="http://sourceforge.net/project/showfiles.php?group_id=15583&release_id=158217",
distclass = Dist,
cmdclass = {'build_interpreters': BuildInterpreters,
'deinstall': deinstall},
ext_modules = [Extension("py2exe.py2exe_util",
sources=["source/py2exe_util.c"],
libraries=["imagehlp"]),
],
interpreters = [run, run_w, run_svc, run_dll],
packages=['py2exe', 'py2exe.tools', 'py2exe.resources'],
)
# Local Variables:
# compile-command: "setup.py install"
# End:

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks