|
49 | 49 | kwargs['data_files'] = \ |
50 | 50 | [('schedule_viewer_files', |
51 | 51 | glob.glob(os.path.join('gtfsscheduleviewer', 'files', '*')))] |
| 52 | + options['py2exe'] = {'dist_dir': 'transitfeed-windows-binary-%s' % VERSION} |
52 | 53 |
|
53 | 54 | setup( |
54 | 55 | version=VERSION, |
|
87 | 88 | options=options, |
88 | 89 | **kwargs |
89 | 90 | ) |
| 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