Py2Exe: setup.py

File setup.py, 2.7 KB (added by flip, 9 years ago)
Line 
1# Python modules
2from __future__ import division
3import distutils.core as duc
4import distutils.sysconfig
5import sys
6import os
7import shutil
8import zipfile
9
10VERSION = "0.1"
11
12NAME = "analysis"
13
14import py2exe
15
16""" This is a setup.py experiment dedicated to py2exe. It's a rough draft.
17To invoke, use this command:
18   python setup.py py2exe
19 
20py2exe must be installed on the target computer. I think py2exe only works
21under Windows.
22
23When setup is done, the dist directory will hold the good stuff, with main.exe
24being the thing you'd double click on to launch the app. dist.zip is a
25zipped version of the dist directory created by setup.
26"""
27
28# Remove the previous build to ensure fresh files
29if os.path.exists("build"):
30    print "Removing old build..."
31    shutil.rmtree("build")
32if os.path.exists("dist"):
33    print "Removing old dist..."
34    shutil.rmtree("dist")
35
36# When a Python app runs "normally" (i.e. not via py2exe but by being
37# invoked as `python /usr/local/bin/foo_app/foo.py`), the starting path is
38# added to sys.path automatically by Python. This makes it possible to import
39# modules in the current directory. We make heavy use of this.
40# For some reason, py2exe doesn't do this so we have to do it manually. If
41# we don't, then when the EXE runs it will get an ImportError in main.py
42# on the first import of a file in the same directory.
43sys.path.append("src")
44
45# Matplotlib uses some data files that have long been a headache for py2exe
46# users. To make life easier, matplotlib added the function
47# get_py2exe_datafiles().
48import matplotlib
49data_files = [ ]
50data_files += matplotlib.get_py2exe_datafiles()
51
52
53# Hack, see http://www.py2exe.org/index.cgi/OverridingCriteraForIncludingDlls
54origIsSystemDLL = py2exe.build_exe.isSystemDLL
55def isSystemDLL(pathname):
56        if os.path.basename(pathname).lower() in ("msvcp71.dll", "dwmapi.dll"):
57                return 0
58        return origIsSystemDLL(pathname)
59py2exe.build_exe.isSystemDLL = isSystemDLL
60
61packages = ["analysis",
62          "analysis.libduke_mr",
63          "analysis.plugins",
64          "analysis.plugins.ecc_methods",
65          "analysis.plugins.ecc_methods.simple",
66           ]
67
68py2exe_options = { "packages" : packages }
69
70duc.setup(windows=["src/main.py"],
71          zipfile=None,
72          name = NAME,
73          version = VERSION,
74          package_dir = {"analysis" : "src"},
75          packages = packages,
76          options = { "py2exe" : py2exe_options },
77          data_files = data_files,
78         )
79
80
81print "\nBuilding dist.zip..."
82z = zipfile.ZipFile("dist.zip", "w", zipfile.ZIP_DEFLATED)
83
84for path, directories, filenames in os.walk("dist"):
85    for filename in filenames:
86        filename = os.path.join(path, filename)
87        z.write(filename, filename)
88   
89z.close()