diff setup.py @ 4613:e7f1cf9eeb96

Static file serving built-in (see details below). Moved wiki/htdocs to MoinMoin/web/static/htdocs. MoinMoin.web.static has a static file serving wrapper that uses the files from htdocs subdirectory by default (docs=True). You can also give another path or switch off creation of that static wrapper. See the docstring of the static package for details. distutils had a major problem after I wanted it to just include everything below MoinMoin/web/static/htdocs - if you try to just use a glob ('htdocs/*'), it breaks distutils at 'setup.py install' time, because that glob matches directories and distutils only expects files. Therefore I added make_filelist to setup.py which creates just a list of all files below some specified directory.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 01 Mar 2009 03:02:57 +0100
parents 0dbfbe73371d
children 995e39af3f7c
line wrap: on
line diff
--- a/setup.py	Sat Feb 28 22:35:16 2009 +0100
+++ b/setup.py	Sun Mar 01 03:02:57 2009 +0100
@@ -88,6 +88,26 @@
     destination = os.path.join(prefix, dirname[strip:])
     found.append((destination, files))
 
+def make_filelist(dir, strip_prefix=''):
+    """ package_data is pretty stupid: if the globs that can be given there
+        match a directory, then setup.py install will fall over that later,
+        because it expects only files.
+        Use make_filelist(dir, strip) to create a list of all FILES below dir,
+        stripping off the strip_prefix at the left side.
+    """
+    found = []
+    def _visit((found, strip), dirname, names):
+        files = []
+        for name in names:
+            path = os.path.join(dirname, name)
+            if os.path.isfile(path):
+                if path.startswith(strip):
+                    path = path[len(strip):]
+                files.append(path)
+        found.extend(files)
+
+    os.path.walk(dir, _visit, (found, strip_prefix))
+    return found
 
 #############################################################################
 ### Build script files
@@ -302,6 +322,7 @@
         'MoinMoin.userprefs',
         'MoinMoin.util',
         'MoinMoin.web',
+        'MoinMoin.web.static',
         'MoinMoin.widget',
         'MoinMoin.wikixml',
         'MoinMoin.xmlrpc',
@@ -310,12 +331,17 @@
         #'MoinMoin._tests',
     ],
 
-    'package_dir': {'MoinMoin.i18n': 'MoinMoin/i18n', },
+    'package_dir': {'MoinMoin.i18n': 'MoinMoin/i18n',
+                    'MoinMoin.web.static': 'MoinMoin/web/static',
+                   },
     'package_data': {'MoinMoin.i18n': ['README', 'Makefile', 'MoinMoin.pot', 'POTFILES.in',
                                        '*.po',
                                        'tools/*',
                                        'jabberbot/*',
-                                      ], },
+                                      ],
+                     'MoinMoin.web.static': make_filelist('MoinMoin/web/static/htdocs',
+                                                          strip_prefix='MoinMoin/web/static/'),
+                    },
 
     # Override certain command classes with our own ones
     'cmdclass': {
@@ -337,13 +363,14 @@
     setup_args['platforms'] = "any"
 
 
-try:
-    setup(**setup_args)
-except distutils.errors.DistutilsPlatformError, ex:
-    print
-    print str(ex)
+if __name__ == '__main__':
+    try:
+        setup(**setup_args)
+    except distutils.errors.DistutilsPlatformError, ex:
+        print
+        print str(ex)
 
-    print """
+        print """
 POSSIBLE CAUSE
 
 "distutils" often needs developer support installed to work