[zpkg] SVN: zpkgtools/branches/philikon-toplevel-modules/zpkg Rethink strategy for dealing with top-level modules:

Philipp von Weitershausen philikon at philikon.de
Mon Nov 14 12:25:33 EST 2005


Log message for revision 40096:
  Rethink strategy for dealing with top-level modules:
  
  We don't put them in Dependencies/<depname>, but we put them in a
  Modules/ directory that is top-level to the distribution and a sibling
  to Dependencies. Distutils likes to have all top-level modules
  (py_modules parameter) to be in one directory, which is incidentally
  the one specified by package_dir['']. zpkgsetup now satisfies distutils
  in both of those ways.
  
  Now, when dealing with a ModuleComponent, zpkg doesn't create a setup.py,
  setup.cfg under Dependencies/<depname> anymore. Instead it creates a
  MODULE.cfg, a very simple configuration file telling zpkgsetup the name
  of the module. It will then try to find it under Modules/ where zpkgtools
  will have put it.
  
  This approach works well so far; it's only that I'm getting a weird error now
  ("error: Is a directory") when running python install.py build; in particular
  it occurs in the build_scripts subcommand.  Unfortunately the error doesn't
  occur in python (otherwise I'd have a nice traceback). I'm further
  investigating.
  

Changed:
  A   zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/module.xml
  U   zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/package.py
  U   zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/setup.py
  U   zpkgtools/branches/philikon-toplevel-modules/zpkgtools/app.py

-=-
Added: zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/module.xml
===================================================================
--- zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/module.xml	2005-11-14 17:13:42 UTC (rev 40095)
+++ zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/module.xml	2005-11-14 17:25:33 UTC (rev 40096)
@@ -0,0 +1,3 @@
+<schema prefix="zpkgsetup">
+  <key name="module" datatype=".package.path_ref"/>
+</schema>


Property changes on: zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/module.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/package.py
===================================================================
--- zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/package.py	2005-11-14 17:13:42 UTC (rev 40095)
+++ zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/package.py	2005-11-14 17:25:33 UTC (rev 40096)
@@ -67,6 +67,7 @@
 
 
 PACKAGE_CONF = "SETUP.cfg"
+MODULE_CONF = "MODULE.cfg"
 
 get_schema = cfgparser.cachedSchemaLoader("package.xml")
 
@@ -124,6 +125,14 @@
                                for path in pkginfo.header]
     return pkginfo
 
+def read_module_info(directory):
+    module_schema = cfgparser.cachedSchemaLoader("module.xml")
+    module_cfg = os.path.join(directory, MODULE_CONF)
+    f = file(module_cfg)
+    url = urlutils.file_url(urllib.pathname2url(module_cfg))
+    pkginfo, _ = cfgparser.loadConfigFile(module_schema(), f, url)
+    f.close()
+    return pkginfo
 
 def read_package_info(directory, reldir=None):
     """Read the package information file from a specified directory.

Modified: zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/setup.py
===================================================================
--- zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/setup.py	2005-11-14 17:13:42 UTC (rev 40095)
+++ zpkgtools/branches/philikon-toplevel-modules/zpkgsetup/setup.py	2005-11-14 17:25:33 UTC (rev 40096)
@@ -67,6 +67,7 @@
         self.package_data = {}
         self.package_dir = {}
         self.package_headers = []
+        self.py_modules = []
         self.ext_modules = []
         self.scripts = []
         self.platforms = None
@@ -82,6 +83,10 @@
         pkgdir = os.path.join(self._working_dir, self._pkgname)
         self.scan(self._pkgname, pkgdir, self._pkgname)
         depsdir = os.path.join(self._working_dir, "Dependencies")
+        modsdir = os.path.join(self._working_dir, "Modules")
+        if os.path.isdir(modsdir):
+            # we do the following so that top-level modules can be installed
+            self.package_dir[""] = 'Modules'
         if os.path.isdir(depsdir):
             depnames = os.listdir(depsdir)
             suffix = "-%s-%s" % (self._pkgname, self.version)
@@ -97,9 +102,22 @@
                     print >>sys.stderr, \
                           "unexpected file in Dependencies/: %r" % name
                     continue
+
                 depname = name[:-len(suffix)]
+                reldir = posixpath.join("Dependencies", name, depname)
                 pkgdir = os.path.join(depdir, depname)
-                reldir = posixpath.join("Dependencies", name, depname)
+
+                # quick hack to see if we're dealing with a top-level
+                # module or not. If we are, slightly adjust the
+                # dependency name etc. according to the value supplied
+                # in SETUP.cfg.
+                if os.path.exists(os.path.join(depdir, package.MODULE_CONF)):
+                    pkginfo = package.read_module_info(depdir)
+                    if pkginfo.module:
+                        depname = pkginfo.module[:-3]
+                        reldir = "Modules"
+                        pkgdir = os.path.join(modsdir, depname)
+
                 self.scan(depname, pkgdir, reldir)
 
     def setup(self):
@@ -163,7 +181,6 @@
         #
         parts = root.split("/")
         local_root = os.path.join(*parts)
-        self.package_dir[""] = root
         if os.path.isfile(os.path.join(local_root, package.PACKAGE_CONF)):
             # There's a SETUP.cfg at the top level; load it:
             pkginfo = package.loadCollectionInfo(
@@ -186,12 +203,18 @@
                 self.scan_package(pkgname, local_full_path, relative_path)
 
     def scan(self, name, directory, reldir):
+        module_py = directory + '.py'
         init_py = os.path.join(directory, "__init__.py")
-        if os.path.isfile(init_py):
+        if os.path.isfile(module_py):
+            self.scan_module(name, module_py, reldir)
+        elif os.path.isfile(init_py):
             self.scan_package(name, directory, reldir)
         else:
             self.scan_collection(name, directory, reldir)
 
+    def scan_module(self, name, filename, reldir):
+        self.py_modules.append(name)
+
     def scan_collection(self, name, directory, reldir):
         # load the collection metadata
         pkginfo = package.loadCollectionInfo(directory, reldir)

Modified: zpkgtools/branches/philikon-toplevel-modules/zpkgtools/app.py
===================================================================
--- zpkgtools/branches/philikon-toplevel-modules/zpkgtools/app.py	2005-11-14 17:13:42 UTC (rev 40095)
+++ zpkgtools/branches/philikon-toplevel-modules/zpkgtools/app.py	2005-11-14 17:25:33 UTC (rev 40096)
@@ -617,43 +617,25 @@
         if not os.path.exists(destination):
             os.mkdir(destination)
         self.ip.addIncludes(destination, self.distribution)
-        self.ip.copy_file(self.source, destination)
+        self.write_module_cfg()
+        module_dest = os.path.join(destination, '..', '..', 'Modules')
+        if not os.path.exists(module_dest):
+            os.mkdir(module_dest)
+        self.ip.copy_file(self.source, module_dest)
 
-    def write_setup_cfg(self):
-        setup_cfg = os.path.join(self.destination, "setup.cfg")
-        self.ip.add_output(setup_cfg)
-        f = open(setup_cfg, "w")
-        f.write("# THIS IS A GENERATED FILE.\n")
-        f.write("\n")
-        f.write("[install_lib]\n")
-        # generate .pyc files
-        f.write("compile = 1\n")
-        # generate .pyo files using "python -O"
-        f.write("optimize = 1\n")
+    def write_module_cfg(self):
+        module_cfg = os.path.join(self.destination, 'MODULE.cfg')
+        self.ip.add_output(module_cfg)
+        f = file(module_cfg, 'w')
+        print >>f, "module %s" % self.filename
         f.close()
 
+    def write_setup_cfg(self):
+        pass
+
     def write_setup_py(self, filename="setup.py", version=None, pathparts=[],
                        distclass=None):
-        # simply assume that the filename ends in '.py'
-        module_name = self.filename[:-3]
-        setup_py = os.path.join(self.destination, filename)
-        self.ip.add_output(setup_py)
-        f = open(setup_py, "w")
-        if pathparts:
-            extrapath = ", ".join([""] + [repr(pp) for pp in pathparts])
-        else:
-            extrapath = ""
-        print >>f, SETUP_HEADER % extrapath
-        print >>f, "context = zpkgsetup.setup.SetupContext("
-        if distclass:
-            print >>f, "    %r, %r, __file__," % (module_name, version)
-            print >>f, "    %r)" % distclass
-        else:
-            print >>f, "    %r, %r, __file__)" % (module_name, version)
-        print >>f
-        print >>f, "context.initialize()"
-        print >>f, "context.setup()"
-        f.close()
+        pass
 
 
 SETUP_HEADER = """\



More information about the zpkg mailing list