comparison setup.py @ 933:a03c030a62c5

make setup.py work with python2.3 AND copy *.po to package dir
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 08 Jul 2006 22:52:38 +0200
parents ce7ca91787b0
children 4b02826f6408
comparison
equal deleted inserted replaced
932:da5d404f4d97 933:a03c030a62c5
13 from distutils.core import setup 13 from distutils.core import setup
14 from distutils.command.build_scripts import build_scripts 14 from distutils.command.build_scripts import build_scripts
15 15
16 from MoinMoin.version import release, revision 16 from MoinMoin.version import release, revision
17 17
18 # we need this for distutils from python 2.3 compatibility, python 2.4 has the
19 # 'package_data' keyword to the 'setup' function to install data in packages
20 # see http://wiki.python.org/moin/DistutilsInstallDataScattered
21 from distutils.command.install_data import install_data
22 class smart_install_data(install_data):
23 def run(self):
24 i18n_data_files = [(target, files) for (target, files) in self.data_files if target.startswith('MoinMoin/i18n')]
25 share_data_files = [(target, files) for (target, files) in self.data_files if target.startswith('share/moin')]
26 # first install the share/moin stuff:
27 self.data_files = share_data_files
28 install_data.run(self)
29 # now we need to install the *.po files to the package dir:
30 # need to change self.install_dir to the library dir
31 install_cmd = self.get_finalized_command('install')
32 self.install_dir = getattr(install_cmd, 'install_lib')
33 self.data_files = i18n_data_files
34 return install_data.run(self)
18 35
19 ############################################################################# 36 #############################################################################
20 ### Helpers 37 ### Helpers
21 ############################################################################# 38 #############################################################################
22 39
59 """ 76 """
60 # Strip 'dir/' from of path before joining with prefix 77 # Strip 'dir/' from of path before joining with prefix
61 dir = dir.rstrip('/') 78 dir = dir.rstrip('/')
62 strip = len(dir) + 1 79 strip = len(dir) + 1
63 found = [] 80 found = []
64 os.path.walk(dir, visit, (prefix, strip, found)) 81 os.path.walk(dir, visit, (prefix, strip, found))
65 return found 82 return found
66 83
67 def visit((prefix, strip, found), dirname, names): 84 def visit((prefix, strip, found), dirname, names):
68 """ Visit directory, create distutil tuple 85 """ Visit directory, create distutil tuple
69 86
84 continue 101 continue
85 elif isgood(name): 102 elif isgood(name):
86 files.append(path) 103 files.append(path)
87 destination = os.path.join(prefix, dirname[strip:]) 104 destination = os.path.join(prefix, dirname[strip:])
88 found.append((destination, files)) 105 found.append((destination, files))
89 106
90 107
91 ############################################################################# 108 #############################################################################
92 ### Build script files 109 ### Build script files
93 ############################################################################# 110 #############################################################################
94 111
114 """ Create each script listed in 'self.scripts' 131 """ Create each script listed in 'self.scripts'
115 """ 132 """
116 if not self.package_name: 133 if not self.package_name:
117 raise Exception("You have to inherit build_scripts_create and" 134 raise Exception("You have to inherit build_scripts_create and"
118 " provide a package name") 135 " provide a package name")
119 136
120 to_module = string.maketrans('-/', '_.') 137 to_module = string.maketrans('-/', '_.')
121 138
122 self.mkpath(self.build_dir) 139 self.mkpath(self.build_dir)
123 for script in self.scripts: 140 for script in self.scripts:
124 outfile = os.path.join(self.build_dir, os.path.basename(script)) 141 outfile = os.path.join(self.build_dir, os.path.basename(script))
236 253
237 # if we get *massive* amounts of test, this should probably be left out 254 # if we get *massive* amounts of test, this should probably be left out
238 'MoinMoin._tests', 255 'MoinMoin._tests',
239 ], 256 ],
240 257
241 # TODO package_dir and package_data only works for python >= 2.4 258 # We can use package_* instead of the smart_install_data hack when we
242 # in case we don't require python >= 2.4 for 1.6 release, we need to find 259 # require Python 2.4.
243 # a solution for python 2.3.x 260 #'package_dir': { 'MoinMoin.i18n': 'MoinMoin/i18n', },
244 'package_dir': { 'MoinMoin.i18n': 'MoinMoin/i18n', }, 261 #'package_data': { 'MoinMoin.i18n': ['README', 'Makefile', 'MoinMoin.pot', 'POTFILES.in',
245 'package_data': { 'MoinMoin.i18n': ['README', 'Makefile', 'MoinMoin.pot', 'POTFILES.in', 262 # '*.po',
246 '*.po', 263 # 'tools/*',], },
247 'tools/*',], },
248 264
249 # Override certain command classes with our own ones 265 # Override certain command classes with our own ones
250 'cmdclass': { 266 'cmdclass': {
251 'build_scripts': build_scripts_moin, 267 'build_scripts': build_scripts_moin,
268 'install_data': smart_install_data, # hack needed for 2.3
252 }, 269 },
253 270
254 'scripts': moin_scripts, 271 'scripts': moin_scripts,
255 272
256 # This copy the contents of wiki dir under sys.prefix/share/moin 273 # This copies the contents of wiki dir under sys.prefix/share/moin
257 # Do not put files that should not be installed in the wiki dir, or 274 # Do not put files that should not be installed in the wiki dir, or
258 # clean the dir before you make the distribution tarball. 275 # clean the dir before you make the distribution tarball.
259 'data_files': makeDataFiles('share/moin', 'wiki'), 276 'data_files': makeDataFiles('share/moin', 'wiki') + makeDataFiles('MoinMoin/i18n', 'MoinMoin/i18n')
260 } 277 }
261 278
262 if hasattr(distutils.dist.DistributionMetadata, 'get_keywords'): 279 if hasattr(distutils.dist.DistributionMetadata, 'get_keywords'):
263 setup_args['keywords'] = "wiki web" 280 setup_args['keywords'] = "wiki web"
264 281
269 try: 286 try:
270 apply(setup, (), setup_args) 287 apply(setup, (), setup_args)
271 except distutils.errors.DistutilsPlatformError, ex: 288 except distutils.errors.DistutilsPlatformError, ex:
272 print 289 print
273 print str(ex) 290 print str(ex)
274 291
275 print """ 292 print """
276 POSSIBLE CAUSE 293 POSSIBLE CAUSE
277 294
278 "distutils" often needs developer support installed to work 295 "distutils" often needs developer support installed to work
279 correctly, which is usually located in a separate package 296 correctly, which is usually located in a separate package