[Zope-CVS] SVN: zpkgtools/trunk/ fix automatic inclusion of support metadata

Fred L. Drake, Jr. fred at zope.com
Tue Jun 22 15:35:09 EDT 2004


Log message for revision 25943:
fix automatic inclusion of support metadata


-=-
Modified: zpkgtools/trunk/doc/TODO.txt
===================================================================
--- zpkgtools/trunk/doc/TODO.txt	2004-06-22 18:33:56 UTC (rev 25942)
+++ zpkgtools/trunk/doc/TODO.txt	2004-06-22 19:33:00 UTC (rev 25943)
@@ -7,10 +7,6 @@
 
 - Package assembler script and distribution runtime
 
-  - When building a distribution that specifies explicit inclusions,
-    the packaging metadata (`*.cfg` except `PACKAGE.cfg`) files should
-    be included automatically.
-
   - We should have a way to express dependence on particular versions
     of Python, and a way to say which is preferred.  (This can be used
     when building an "application" distribution since that has some

Modified: zpkgtools/trunk/zpkgtools/app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/app.py	2004-06-22 18:33:56 UTC (rev 25942)
+++ zpkgtools/trunk/zpkgtools/app.py	2004-06-22 19:33:00 UTC (rev 25943)
@@ -406,7 +406,7 @@
                          publication.PUBLICATION_CONF,
                          "DEPENDENCIES.cfg"):
             dstname = os.path.join(destination, self.name, metafile)
-            srcname = os.path.join(self.source, self.name, metafile)
+            srcname = os.path.join(self.source, metafile)
             if os.path.exists(srcname) and not os.path.exists(dstname):
                 self.ip.copy_file(srcname, dstname)
 

Modified: zpkgtools/trunk/zpkgtools/include.py
===================================================================
--- zpkgtools/trunk/zpkgtools/include.py	2004-06-22 18:33:56 UTC (rev 25942)
+++ zpkgtools/trunk/zpkgtools/include.py	2004-06-22 19:33:00 UTC (rev 25943)
@@ -84,6 +84,12 @@
             config = parser.load()
         finally:
             f.close()
+        if config.collection.excludes:
+            # XXX should make sure PACKAGE_CONF isn't already excluded
+            config.collection.excludes.append(PACKAGE_CONF)
+        elif not config.collection.includes:
+            # Nothing included or excluded; simply exclude PACKAGE_CONF:
+            config.collection.excludes.append(PACKAGE_CONF)
     else:
         config = schema.getConfiguration()
     return config
@@ -276,7 +282,8 @@
                     self.filename)
             for fn in expansions:
                 suffix = fn[len(prefix):]
-                excludes.append(suffix)
+                if suffix not in excludes:
+                    excludes.append(suffix)
         self.excludes[:] = excludes
 
 
@@ -370,6 +377,9 @@
                 if specs.collection:
                     specs.collection.cook()
                     self.createDistributionTree(destdir, specs.collection)
+                    # Don't recurse into any directories here; those
+                    # were handled by the inner call to
+                    # self.createDistributionTree().
                     del dirs[:]
                     continue
 

Modified: zpkgtools/trunk/zpkgtools/tests/test_app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_app.py	2004-06-22 18:33:56 UTC (rev 25942)
+++ zpkgtools/trunk/zpkgtools/tests/test_app.py	2004-06-22 19:33:00 UTC (rev 25943)
@@ -21,6 +21,7 @@
 
 from StringIO import StringIO
 
+from zpkgsetup import package
 from zpkgsetup import publication
 from zpkgsetup.tests import tempfileapi as tempfile
 
@@ -272,7 +273,70 @@
         self.assertRaises(zpkgtools.Error,
                           app.Component, "mypkg", self.mypkg_url, self.ip)
 
+    def test_component_metadata_is_copied_by_default(self):
+        self.write_app_file(publication.PUBLICATION_CONF,
+                            "Metadata-Version: 1.1\n"
+                            "Name: mypkg\n")
+        self.write_app_file(include.PACKAGE_CONF,
+                            "# nothing to specify\n")
+        self.write_app_file(package.PACKAGE_CONF,
+                            "# nothing to specify\n")
+        #
+        c = app.Component("mypkg", self.mypkg_url, self.ip)
+        dest = tempfile.mkdtemp(prefix="test-app-dest-")
+        try:
+            c.write_package(dest)
+            c.write_manifest()
+            c.write_setup_cfg()
+            c.write_setup_py(version='1.2.3')
+            # done writing; make sure the expected metadata files are
+            # present:
+            pkgdest = os.path.join(dest, c.name)
+            self.assert_(isfile(pkgdest, publication.PUBLICATION_CONF))
+            self.assert_(isfile(pkgdest, package.PACKAGE_CONF))
+            self.failIf(os.path.exists(os.path.join(pkgdest,
+                                                    include.PACKAGE_CONF)))
+        finally:
+            shutil.rmtree(dest)
 
+    def test_component_metadata_is_copied_with_inclusions(self):
+        self.write_app_file(publication.PUBLICATION_CONF,
+                            "Metadata-Version: 1.1\n"
+                            "Name: mypkg\n")
+        self.write_app_file(include.PACKAGE_CONF,
+                            "<collection>\n"
+                            "  README.txt README\n"
+                            "</collection>\n")
+        self.write_app_file(package.PACKAGE_CONF,
+                            "# nothing to specify\n")
+        self.write_app_file("README",
+                            "some text\n")
+        #
+        c = app.Component("mypkg", self.mypkg_url, self.ip)
+        dest = tempfile.mkdtemp(prefix="test-app-dest-")
+        try:
+            c.write_package(dest)
+            c.write_manifest()
+            c.write_setup_cfg()
+            c.write_setup_py(version='1.2.3')
+            # done writing; make sure the expected metadata files are
+            # present:
+            pkgdest = os.path.join(dest, c.name)
+            self.assert_(isfile(pkgdest, publication.PUBLICATION_CONF))
+            self.assert_(isfile(pkgdest, package.PACKAGE_CONF))
+            self.assert_(isfile(pkgdest, "README.txt"))
+            self.failIf(os.path.exists(os.path.join(pkgdest,
+                                                    include.PACKAGE_CONF)))
+        finally:
+            shutil.rmtree(dest)
+
+
+def isfile(path, *args):
+    if args:
+        path = os.path.join(path, *args)
+    return os.path.isfile(path)
+
+
 def test_suite():
     suite = unittest.makeSuite(CommandLineTestCase)
     suite.addTest(unittest.makeSuite(ComponentTestCase))

Modified: zpkgtools/trunk/zpkgtools/tests/test_include.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_include.py	2004-06-22 18:33:56 UTC (rev 25942)
+++ zpkgtools/trunk/zpkgtools/tests/test_include.py	2004-06-22 19:33:00 UTC (rev 25943)
@@ -136,9 +136,10 @@
             """)
         specs = include.load(self.source)
         # These are "uncooked", so wildcards haven't been expanded.
-        self.assertEqual(len(specs.collection.excludes), 2)
+        self.assertEqual(len(specs.collection.excludes), 3)
         self.assert_("foobar.txt" in specs.collection.excludes)
         self.assert_("doc/todo-*.txt" in specs.collection.excludes)
+        self.assert_(include.PACKAGE_CONF in specs.collection.excludes)
         # Now populate the source dir:
         self.write_file("foobar.txt", "some text\n")
         docdir = join(self.source, "doc")
@@ -148,13 +149,29 @@
             self.write_file(join("doc", "todo-2.txt"), "something else\n")
             # And check that cooking finds produces the right thing:
             specs.collection.cook()
-            self.assertEqual(len(specs.collection.excludes), 3)
+            self.assertEqual(len(specs.collection.excludes), 4)
             self.assert_("foobar.txt" in specs.collection.excludes)
             self.assert_("doc/todo-1.txt" in specs.collection.excludes)
             self.assert_("doc/todo-2.txt" in specs.collection.excludes)
+            self.assert_(include.PACKAGE_CONF in specs.collection.excludes)
         finally:
             shutil.rmtree(docdir)
 
+    def test_exclusions_with_explicit_package_conf(self):
+        self.write_file(include.PACKAGE_CONF, """\
+            <collection>
+              %s -
+            </collection>
+            """ % include.PACKAGE_CONF)
+        specs = include.load(self.source)
+        self.assertEqual(len(specs.collection.excludes), 2)
+        self.assert_(include.PACKAGE_CONF in specs.collection.excludes)
+
+        # Check the cooked collection:
+        specs.collection.cook()
+        self.assertEqual(len(specs.collection.excludes), 1)
+        self.assert_(include.PACKAGE_CONF in specs.collection.excludes)
+
     def test_unmatched_wildcards_in_exclusions(self):
         self.write_file(include.PACKAGE_CONF, """\
             <collection>




More information about the Zope-CVS mailing list