[Zope-CVS] SVN: zpkgtools/trunk/ - remove restriction that collections cannot contain extension modules

Fred L. Drake, Jr. fdrake at gmail.com
Thu Aug 25 13:06:36 EDT 2005


Log message for revision 38091:
  - remove restriction that collections cannot contain extension modules
  - make walk_packages() deal with a SETUP.cfg at the top of the tree
    so that extensions not included in packages work
  

Changed:
  U   zpkgtools/trunk/doc/metadata.txt
  U   zpkgtools/trunk/zpkgsetup/build_headers.py
  U   zpkgtools/trunk/zpkgsetup/install_headers.py
  U   zpkgtools/trunk/zpkgsetup/package.py
  U   zpkgtools/trunk/zpkgsetup/setup.py
  A   zpkgtools/trunk/zpkgsetup/tests/input/SETUP.cfg
  A   zpkgtools/trunk/zpkgsetup/tests/input/foo.c
  U   zpkgtools/trunk/zpkgsetup/tests/test_package.py
  U   zpkgtools/trunk/zpkgsetup/tests/test_setup.py

-=-
Modified: zpkgtools/trunk/doc/metadata.txt
===================================================================
--- zpkgtools/trunk/doc/metadata.txt	2005-08-25 17:05:52 UTC (rev 38090)
+++ zpkgtools/trunk/doc/metadata.txt	2005-08-25 17:06:36 UTC (rev 38091)
@@ -214,6 +214,9 @@
     ...
   </extension>
 
+Extensions which are not in packages but provided by simple
+collections are supported as well.
+
 The **<extension>** section can contain the settings described below.
 All of these can be repeated with the exception of the **language**
 setting.

Modified: zpkgtools/trunk/zpkgsetup/build_headers.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/build_headers.py	2005-08-25 17:05:52 UTC (rev 38090)
+++ zpkgtools/trunk/zpkgsetup/build_headers.py	2005-08-25 17:06:36 UTC (rev 38091)
@@ -44,7 +44,10 @@
         if not self.package_headers:
             return
         for header in self.package_headers:
-            dir = os.path.join(self.build_dir, header.package)
+            if header.package:
+                dir = os.path.join(self.build_dir, header.package)
+            else:
+                dir = self.build_dir
             self.mkpath(dir)
             srcfile = distutils.util.convert_path(header.path)
             outfile = os.path.join(

Modified: zpkgtools/trunk/zpkgsetup/install_headers.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/install_headers.py	2005-08-25 17:05:52 UTC (rev 38090)
+++ zpkgtools/trunk/zpkgsetup/install_headers.py	2005-08-25 17:06:36 UTC (rev 38091)
@@ -40,7 +40,10 @@
         self.mkpath(install_base)
 
         for header in headers:
-            install_dir = os.path.join(install_base, header.package)
+            if header.package:
+                install_dir = os.path.join(install_base, header.package)
+            else:
+                install_dir = install_base
             self.mkpath(install_dir)
             (out, _) = self.copy_file(header.path, install_dir)
             self.outfiles.append(out)

Modified: zpkgtools/trunk/zpkgsetup/package.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/package.py	2005-08-25 17:05:52 UTC (rev 38090)
+++ zpkgtools/trunk/zpkgsetup/package.py	2005-08-25 17:06:36 UTC (rev 38091)
@@ -122,10 +122,9 @@
 
     """
     pkginfo = read_package_info(directory, reldir)
-    if pkginfo.extension:
-        raise ValueError("extensions cannot be defined in collections")
-    pkginfo.extensions = []
-    pkginfo.package_headers = [Header(pkgname, path)
+    pkginfo.extensions = [create_extension(ext, None, reldir)
+                          for ext in pkginfo.extension]
+    pkginfo.package_headers = [Header(None, path)
                                for path in pkginfo.header]
     return pkginfo
 

Modified: zpkgtools/trunk/zpkgsetup/setup.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/setup.py	2005-08-25 17:05:52 UTC (rev 38090)
+++ zpkgtools/trunk/zpkgsetup/setup.py	2005-08-25 17:06:36 UTC (rev 38091)
@@ -163,6 +163,12 @@
         #
         parts = root.split("/")
         local_root = os.path.join(*parts)
+        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(
+                os.path.join(self._working_dir, local_root),
+                root)
+            self.scan_basic(pkginfo)
         prefix_len = len(os.path.join(local_root, ""))
         for root, dirs, files in os.walk(local_root):
             for d in dirs[:]:
@@ -170,7 +176,8 @@
                 initfn = os.path.join(root, d, "__init__.py")
                 if not os.path.isfile(initfn):
                     dirs.remove(d)
-            if package.PACKAGE_CONF in files:
+            if (package.PACKAGE_CONF in files
+                and "__init__.py" in files):
                 # scan this directory as a package:
                 pkgname = root[prefix_len:].replace(os.path.sep, ".")
                 local_full_path = os.path.join(self._working_dir, root)
@@ -193,7 +200,6 @@
         # load the package metadata
         pkginfo = package.loadPackageInfo(name, directory, reldir)
         self.scan_basic(pkginfo)
-        self.ext_modules.extend(pkginfo.extensions)
         self.add_package_dir(name, reldir)
 
         # scan the files in the directory:
@@ -272,6 +278,7 @@
         for fn in pkginfo.header:
             if fn not in self.headers:
                 self.headers.append(fn)
+        self.ext_modules.extend(pkginfo.extensions)
 
     def add_package_dir(self, pkgname, reldir):
         self.packages.append(pkgname)

Added: zpkgtools/trunk/zpkgsetup/tests/input/SETUP.cfg
===================================================================
--- zpkgtools/trunk/zpkgsetup/tests/input/SETUP.cfg	2005-08-25 17:05:52 UTC (rev 38090)
+++ zpkgtools/trunk/zpkgsetup/tests/input/SETUP.cfg	2005-08-25 17:06:36 UTC (rev 38091)
@@ -0,0 +1,3 @@
+<extension foo>
+  source foo.c
+</extension>


Property changes on: zpkgtools/trunk/zpkgsetup/tests/input/SETUP.cfg
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zpkgtools/trunk/zpkgsetup/tests/input/foo.c
===================================================================
--- zpkgtools/trunk/zpkgsetup/tests/input/foo.c	2005-08-25 17:05:52 UTC (rev 38090)
+++ zpkgtools/trunk/zpkgsetup/tests/input/foo.c	2005-08-25 17:06:36 UTC (rev 38091)
@@ -0,0 +1,16 @@
+/*  foo.c
+ *
+ *  This is a fake extension.  It won't actually be compiled.
+ */
+
+#include <Python.h>
+
+static PyMethodDef foo_methods[] = {
+    {NULL, NULL}
+};
+
+void
+initfoo(void)
+{
+    Py_InitModule("foo", foo_methods)
+}


Property changes on: zpkgtools/trunk/zpkgsetup/tests/input/foo.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: zpkgtools/trunk/zpkgsetup/tests/test_package.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/tests/test_package.py	2005-08-25 17:05:52 UTC (rev 38090)
+++ zpkgtools/trunk/zpkgsetup/tests/test_package.py	2005-08-25 17:06:36 UTC (rev 38091)
@@ -141,12 +141,13 @@
         eq(pkginfo.documentation, ["doc/README.txt"])
         eq(pkginfo.script, ["bin/runme.py"])
 
-    def test_collection_pkginfo_disallows_extensions(self):
+    def test_collection_pkginfo_allows_extensions(self):
         self.write_config("<extension foo>\n"
                           "  source  foo.c\n"
                           "</extension>\n")
-        self.assertRaises(ValueError, package.loadCollectionInfo,
-                          self.tmpdir, None)
+        pkginfo = package.loadCollectionInfo(self.tmpdir, ".")
+        self.assertEqual(len(pkginfo.extensions), 1)
+        self.assertEqual(pkginfo.extensions[0].name, "foo")
 
     def test_data_files_1(self):
         self.write_config("<data-files etc>\n"

Modified: zpkgtools/trunk/zpkgsetup/tests/test_setup.py
===================================================================
--- zpkgtools/trunk/zpkgsetup/tests/test_setup.py	2005-08-25 17:05:52 UTC (rev 38090)
+++ zpkgtools/trunk/zpkgsetup/tests/test_setup.py	2005-08-25 17:06:36 UTC (rev 38091)
@@ -58,14 +58,16 @@
         context = setup.SetupContext("collection", "0.1.2",
                                      os.path.join(top, "setup.py"))
         context.walk_packages("zpkgsetup/tests/input")
-        context.packages.sort()
-        self.assertEqual(context.ext_modules[0].name, "package2.sample")
+        exts = [ext.name for ext in context.ext_modules]
+        exts.sort()
+        self.assertEqual(exts, ["foo", "package2.sample"])
         #
         # See the comments in the walk_packages() function for an
         # explanation of the limitations of the method.  The following
         # check is commented out due to the limitation, but should be
         # enabled with a proper implementation.
         #
+        #context.packages.sort()
         #self.assertEqual(context.packages, ["package", "package2"])
         
 



More information about the Zope-CVS mailing list