Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit c62f0f7

Browse files
author
Tom Brown
committed
py2exe fix to work with current pytz and better dist directory name
Review at http://codereview.appspot.com/9465 fix for issue 121: zoneinfo not included in py2exe library.zip http://code.google.com/p/googletransitdatafeed/issues/detail?id=121
1 parent d5cbf08 commit c62f0f7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

setup.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
kwargs['data_files'] = \
5050
[('schedule_viewer_files',
5151
glob.glob(os.path.join('gtfsscheduleviewer', 'files', '*')))]
52+
options['py2exe'] = {'dist_dir': 'transitfeed-windows-binary-%s' % VERSION}
5253

5354
setup(
5455
version=VERSION,
@@ -87,3 +88,30 @@
8788
options=options,
8889
**kwargs
8990
)
91+
92+
if has_py2exe:
93+
# Sometime between pytz-2008a and pytz-2008i common_timezones started to
94+
# include only names of zones with a corresponding data file in zoneinfo.
95+
# pytz installs the zoneinfo directory tree in the same directory
96+
# as the pytz/__init__.py file. These data files are loaded using
97+
# pkg_resources.resource_stream. py2exe does not copy this to library.zip so
98+
# resource_stream can't find the files and common_timezones is empty when
99+
# read in the py2exe executable.
100+
# This manually copies zoneinfo into the zip. See also
101+
# http://code.google.com/p/googletransitdatafeed/issues/detail?id=121
102+
import pytz
103+
import zipfile
104+
# Make sure the layout of pytz hasn't changed
105+
assert (pytz.__file__.endswith('__init__.pyc') or
106+
pytz.__file__.endswith('__init__.py')), pytz.__file__
107+
zoneinfo_dir = os.path.join(os.path.dirname(pytz.__file__), 'zoneinfo')
108+
# '..\\Lib\\pytz\\__init__.py' -> '..\\Lib'
109+
disk_basedir = os.path.dirname(os.path.dirname(pytz.__file__))
110+
zipfile_path = os.path.join(options['py2exe']['dist_dir'], 'library.zip')
111+
z = zipfile.ZipFile(zipfile_path, 'a')
112+
for absdir, directories, filenames in os.walk(zoneinfo_dir):
113+
assert absdir.startswith(disk_basedir), (absdir, disk_basedir)
114+
zip_dir = absdir[len(disk_basedir):]
115+
for f in filenames:
116+
z.write(os.path.join(absdir, f), os.path.join(zip_dir, f))
117+
z.close()

0 commit comments

Comments
 (0)