setup.py
changeset 9999 f91e5630ce7e
parent 9998 4a3c388f8c69
child 10000 16f49d671c7f
--- a/setup.py	Thu Dec 03 20:41:43 2009 +0100
+++ b/setup.py	Tue Dec 01 16:06:10 2009 +0100
@@ -165,12 +165,6 @@
 except ImportError:
     version = 'unknown'
 
-class install_package_data(install_data):
-    def finalize_options(self):
-        self.set_undefined_options('install',
-                                   ('install_lib', 'install_dir'))
-        install_data.finalize_options(self)
-
 class build_mo(build):
 
     description = "build translations (.mo files)"
@@ -193,16 +187,17 @@
             pofile = join(podir, po)
             modir = join('locale', po[:-3], 'LC_MESSAGES')
             mofile = join(modir, 'hg.mo')
-            cmd = ['msgfmt', '-v', '-o', mofile, pofile]
+            mobuildfile = join('mercurial', mofile)
+            cmd = ['msgfmt', '-v', '-o', mobuildfile, pofile]
             if sys.platform != 'sunos5':
                 # msgfmt on Solaris does not know about -c
                 cmd.append('-c')
-            self.mkpath(modir)
-            self.make_file([pofile], mofile, spawn, (cmd,))
-            self.distribution.data_files.append((join('mercurial', modir),
-                                                 [mofile]))
+            self.mkpath(join('mercurial', modir))
+            self.make_file([pofile], mobuildfile, spawn, (cmd,))
 
-build.sub_commands.append(('build_mo', None))
+# Insert build_mo first so that files in mercurial/locale/ are found
+# when build_py is run next.
+build.sub_commands.insert(0, ('build_mo', None))
 
 Distribution.pure = 0
 Distribution.global_options.append(('pure', None, "use pure (slow) Python "
@@ -230,8 +225,7 @@
             else:
                 yield module
 
-cmdclass = {'install_data': install_package_data,
-            'build_mo': build_mo,
+cmdclass = {'build_mo': build_mo,
             'build_py': hg_build_py}
 
 ext_modules=[
@@ -255,13 +249,21 @@
                                      ['hgext/inotify/linux/_inotify.c']))
         packages.extend(['hgext.inotify', 'hgext.inotify.linux'])
 
+packagedata = {'mercurial': ['locale/*/LC_MESSAGES/hg.mo',
+                             'help/*.txt']}
+
+def ordinarypath(p):
+    return p and p[0] != '.' and p[-1] != '~'
+
+for root in ('templates', ):
+    for curdir, dirs, files in os.walk(os.path.join('mercurial', root)):
+        curdir = curdir.split(os.sep, 1)[1]
+        dirs[:] = filter(ordinarypath, dirs)
+        for f in filter(ordinarypath, files):
+            f = os.path.join(curdir, f)
+            packagedata['mercurial'].append(f)
+
 datafiles = []
-for root in ('templates', 'help'):
-    for dir, dirs, files in os.walk(root):
-        dirs[:] = [x for x in dirs if not x.startswith('.')]
-        files = [x for x in files if not x.startswith('.')]
-        datafiles.append((os.path.join('mercurial', dir),
-                          [os.path.join(dir, file_) for file_ in files]))
 
 setup(name='mercurial',
       version=version,
@@ -274,6 +276,7 @@
       packages=packages,
       ext_modules=ext_modules,
       data_files=datafiles,
+      package_data=packagedata,
       cmdclass=cmdclass,
       options=dict(py2exe=dict(packages=['hgext', 'email']),
                    bdist_mpkg=dict(zipdist=True,