Skip to content

Commit 828c484

Browse files
author
Ram Rachum
committed
-
1 parent e57a897 commit 828c484

File tree

2 files changed

+74
-25
lines changed

2 files changed

+74
-25
lines changed

garlicsim_wx/py2exe_cruft/setup_extenstion.py renamed to garlicsim_wx/py2exe_cruft/setup_extension.py

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,82 @@
1-
# tododoc: document extensively
1+
# Copyright 2009-2010 Ram Rachum. No part of this program may be used, copied
2+
# or distributed without explicit written permission from Ram Rachum.
3+
4+
'''
5+
Module for packaging garlicsim_wx as executable using py2exe.
6+
7+
Normally the contents of this module would be in setup.py; But py2exe introduces
8+
so much cruft, and I wanted to keep it away from my setup.py. So setup.py
9+
imports this module when it gets a `py2exe` command. This module should not be
10+
used otherwise.
11+
12+
This module assumes that the `garlicsim` and `garlicsim_lib` folders are
13+
alongside the `garlicsim_wx` folder, as in the official git repo of GarlicSim.
14+
'''
215

316
import setuptools
417
import py2exe
518
import imp
619
import sys, os.path, glob
720

8-
path_to_garlicsim = os.path.abspath('../../garlicsim')
9-
path_to_garlicsim_lib = os.path.abspath('../../garlicsim_lib')
21+
# This module is meant to be imported from the garlicsim_wx setup.py file, and
22+
# should not be used otherwise:
23+
assert any('setup.py' in s for s in sys.argv)
24+
25+
path_to_garlicsim = os.path.abspath('../garlicsim')
26+
path_to_garlicsim_lib = os.path.abspath('../garlicsim_lib')
1027
paths_to_add = [path_to_garlicsim, path_to_garlicsim_lib]
1128
for path_to_add in paths_to_add:
1229
if path_to_add not in sys.path:
1330
sys.path.append(path_to_add)
1431

1532

1633
def package_to_path(package):
34+
'''
35+
Given a package name, convert to path.
36+
37+
The path will be relative to the folder that contains the root packakge. So
38+
`package_to_path('numpy.core') == 'numpy/core'`.
39+
'''
1740
return package.replace('.', '/')
1841

1942

2043
def get_garlicsim_packages():
44+
'''
45+
Get all the packages in garlicsim.
46+
47+
This returns an answer in the form: ['garlicsim.data_structures',
48+
'garlicsim.bootstrap', 'garlicsim.misc', ...]
49+
'''
2150
return ['garlicsim.' + p for p
22-
in setuptools.find_packages('../../garlicsim/garlicsim')] + \
51+
in setuptools.find_packages('../garlicsim/garlicsim')] + \
2352
['garlicsim']
2453

2554
garlicsim_packages = get_garlicsim_packages()
2655

2756

2857
def get_garlicsim_lib_packages():
58+
'''
59+
Get all the packages in garlicsim_lib.
60+
61+
This returns an answer in the form: ['garlicsim_lib.simpacks.life',
62+
'garlicsim_lib.simpacks.prisoner', ...]
63+
'''
2964
return ['garlicsim_lib.' + p for p
30-
in setuptools.find_packages('../../garlicsim_lib/garlicsim_lib')] + \
65+
in setuptools.find_packages('../garlicsim_lib/garlicsim_lib')] + \
3166
['garlicsim_lib']
3267

3368
garlicsim_lib_packages = get_garlicsim_lib_packages()
3469

3570

3671
def get_garlicsim_wx_packages():
72+
'''
73+
Get all the packages in garlicsim_wx.
74+
75+
This returns an answer in the form: ['garlicsim_wx.frame',
76+
'garlicsim_wx.widgets', 'garlicsim_wx.misc', ...]
77+
'''
3778
return ['garlicsim_wx.' + p for p
38-
in setuptools.find_packages('../garlicsim_wx')] + \
79+
in setuptools.find_packages('garlicsim_wx')] + \
3980
['garlicsim_wx']
4081

4182
garlicsim_wx_packages = get_garlicsim_wx_packages()
@@ -45,7 +86,8 @@ def get_garlicsim_data_files():
4586
total_data_files = []
4687
for package in garlicsim_packages:
4788
path = package_to_path(package)
48-
all_files_and_folders = glob.glob(path_to_garlicsim + '/' + path + '/*')
89+
all_files_and_folders = \
90+
glob.glob(path_to_garlicsim + '/' + path + '/*')
4991
data_files = [f for f in all_files_and_folders if
5092
(not '.py' in f[4:]) and (not os.path.isdir(f))]
5193
total_data_files.append(('lib/' + path, data_files))
@@ -56,7 +98,8 @@ def get_garlicsim_lib_data_files():
5698
total_data_files = []
5799
for package in garlicsim_lib_packages:
58100
path = package_to_path(package)
59-
all_files_and_folders = glob.glob(path_to_garlicsim + '/' + path + '/*')
101+
all_files_and_folders = \
102+
glob.glob(path_to_garlicsim_lib + '/' + path + '/*')
60103
data_files = [f for f in all_files_and_folders if
61104
(not '.py' in f[4:]) and (not os.path.isdir(f))]
62105
total_data_files.append(('lib/' + path, data_files))
@@ -104,7 +147,7 @@ def get_all_subpackages(package_name):
104147
return [
105148
(package_name + '.' + m) for m in
106149
setuptools.find_packages(
107-
imp.find_module(package_name)[1]
150+
imp.find_module(package_name, sys.path)[1]
108151
)
109152
]
110153

garlicsim_wx/setup.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

3-
# Copyright 2009-2010 Ram Rachum.
4-
# This program is distributed under the LGPL2.1 license.
3+
# Copyright 2009-2010 Ram Rachum. No part of this program may be used, copied
4+
# or distributed without explicit written permission from Ram Rachum.
55

66
'''Setuptools setup file for garlicsim_wx.'''
77

@@ -11,25 +11,30 @@
1111
import setuptools
1212
import distutils # Just for deleting the "build" directory.
1313

14-
if 'py2exe' in sys.argv:
15-
from .py2exe_cruft import setup_extension
16-
1714

18-
# tododoc: the py2exe parts assume `garlicsim` is in the neighboring directory
19-
# like in the git repo
15+
if 'py2exe' in sys.argv:
16+
# We have a separate file for doing stuff that is needed when packaaging
17+
# with py2exe.
18+
import py2exe_cruft.setup_extension
2019

21-
# tododoc: move all the py2exe parts to `py2exe_cruft`
2220

2321
# tododoc: document this module exhaustively.
2422

25-
23+
# Automatically deleting the build directory, in case one was left over from
24+
# last time.
2625
try:
2726
distutils.dir_util.remove_tree('build', verbose=True)
2827
except Exception:
2928
pass
3029

3130

3231
def get_garlicsim_wx_packages():
32+
'''
33+
Get all the packages in garlicsim_wx.
34+
35+
This returns an answer in the form: ['garlicsim_wx.frame',
36+
'garlicsim_wx.widgets', 'garlicsim_wx.misc', ...]
37+
'''
3338
return ['garlicsim_wx.' + p for p
3439
in setuptools.find_packages('./garlicsim_wx')] + \
3540
['garlicsim_wx']
@@ -74,7 +79,8 @@ def get_garlicsim_wx_packages():
7479
'garlicsim_lib == 0.4'
7580
],
7681

77-
'description': 'GUI for garlicsim, a Pythonic framework for computer simulations',
82+
'description': \
83+
'GUI for garlicsim, a Pythonic framework for computer simulations',
7884
'author': 'Ram Rachum',
7985
'author_email': 'cool-rr@cool-rr.com',
8086
'url': 'http://garlicsim.org',
@@ -91,12 +97,12 @@ def get_garlicsim_wx_packages():
9197
path_to_add = os.path.abspath('./py2exe_cruft')
9298
if path_to_add not in sys.path:
9399
sys.path.append(path_to_add)
94-
# Adding it because there's some dll there that we need.
100+
# Adding it because there's some dll there that we need, and py2exe
101+
# looks on sys.path.
95102

96-
97-
setup_kwargs.update(py2exe_kwargs)
103+
setup_kwargs.update(py2exe_cruft.setup_extension.py2exe_kwargs)
98104

99105

100-
setuptools.setup(
101-
**setup_kwargs
102-
)
106+
setuptools.setup(**setup_kwargs)
107+
108+

0 commit comments

Comments
 (0)