[zpkg] SVN: zpkgtools/trunk/ - make it possible to specify support packages and the distribution class

Fred L. Drake, Jr. fdrake at gmail.com
Mon Sep 19 14:18:24 EDT 2005


Log message for revision 38525:
  - make it possible to specify support packages and the distribution class
    using the configuration file
  - allow support packages specified in the configuration file to include
    location information
  

Changed:
  U   zpkgtools/trunk/doc/zpkg.txt
  U   zpkgtools/trunk/zpkgtools/app.py
  U   zpkgtools/trunk/zpkgtools/config.py
  U   zpkgtools/trunk/zpkgtools/config.xml
  U   zpkgtools/trunk/zpkgtools/tests/test_app.py
  U   zpkgtools/trunk/zpkgtools/tests/test_config.py

-=-
Modified: zpkgtools/trunk/doc/zpkg.txt
===================================================================
--- zpkgtools/trunk/doc/zpkg.txt	2005-09-19 18:10:56 UTC (rev 38524)
+++ zpkgtools/trunk/doc/zpkg.txt	2005-09-19 18:18:23 UTC (rev 38525)
@@ -126,11 +126,8 @@
 Blank lines and comments (lines that start with **#** as the first
 non-blank character) are ignored.
 
-Four keys are currently defined for the configuration file:
-**build-application**, **collect-dependencies**,
-**include-support-code**, and **resource-map**.  There are also two
-section types that can be used as well, **<resources>** and
-**<exclude>**.
+There are several keys and sections which can be used in the
+configuration file.  Everything is optional.
 
 If **build-application** is set to **true**, then an application
 distribution is constructed instead of a conventional distutils
@@ -145,6 +142,13 @@
 should be used as the top-level collection to package if no collection
 is specified on the command line.
 
+The **distribution-class** setting is used to indicate that a
+particular class should be use to create the ``distutils``
+distribution object.  **zpkg** provides on that supports the **zpkg**
+extensions, but an alternate or further extended version can be used
+by setting this.  This is equivalent to the **--distribution**
+command-line option.
+
 The **include-support-code** key is used to control whether **zpkg**
 bundles the support code along with the resulting distribution.  The
 value is a boolean, where the strings **true** and **false** can be
@@ -192,7 +196,31 @@
 Note that all **<resources>** sections will be processed before any
 external maps are loaded, regardless of ordering.
 
-Optionally, there is an **<exclude>** section in which you can specify the
+The **<support-packages>** section can be used to add additional
+packages to the *Support/* directory of the generated distribution.
+Within this section, each key specifies a Python package which should
+be added to the support area.  If a value is given for the key, that
+is used as the location from which the resource should be loaded.  If
+no location is specified, the global resource map is used; this is
+equivalent to using the **--support** command-line option.
+
+For example, using this **<support-packages>** section::
+
+  <support-packages>
+    foo
+    bar  svn://svn.example.net/repo/foo/trunk/src/foo
+  </support-packages>
+
+would cause the ``foo`` package to be located using the global
+resource map, but the ``bar`` package to be loaded from the specied
+location, without regard for the global resource map.
+
+Note that when using the **<support-packages>** section, packages are
+always added to the *Support/* directory (they cannot be removed from
+the command line), but the **-s** and **-S** options still control
+whether the support directory is included in the distribution at all.
+
+There is an **<exclude>** section in which you can specify the
 packages/resources that should be excluded (in other words not loaded) from
 the package. Every line should specify one package. This is equivalent of
 specifying **-x** or **--exclude** for every excluded package.
@@ -211,7 +239,8 @@
   </exclude>
 
 Note that neither the **<exclude>** section nor the **-x** and
-**--exclude** command-line options support wildcards.
+**--exclude** command-line options support wildcards.  Exclusions do
+not affect the construction of the *Support/* directory.
 
 
 Resource Maps

Modified: zpkgtools/trunk/zpkgtools/app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/app.py	2005-09-19 18:10:56 UTC (rev 38524)
+++ zpkgtools/trunk/zpkgtools/app.py	2005-09-19 18:18:23 UTC (rev 38525)
@@ -100,6 +100,14 @@
         if not options.release_name:
             options.release_name = cf.release_name
 
+        pkgs = sets.Set()
+        for pkgname, location in options.support_packages:
+            pkgs.add(pkgname)
+        for pkgname, location in cf.support_packages.iteritems():
+            if pkgname not in pkgs:
+                options.support_packages.append((pkgname, location))
+                pkgs.add(pkgname)
+
     def error(self, message, rc=1):
         self.logger.critical(message)
         sys.exit(rc)
@@ -134,9 +142,15 @@
         else:
             self.destination = os.path.join(self.tmpdir, self.target_name)
         os.mkdir(self.destination)
-        self.support_packages = DEFAULT_SUPPORT_PACKAGES[:]
-        self.support_packages.extend(
-            [(pkg, None) for pkg in options.support_packages])
+        pkgs = sets.Set()
+        self.support_packages = []
+        for pkgname, location in options.support_packages:
+            if pkgname not in pkgs:
+                self.support_packages.append((pkgname, location))
+        for pkgname, location in DEFAULT_SUPPORT_PACKAGES:
+            if pkgname not in pkgs:
+                self.support_packages.append((pkgname, location))
+                pkgs.add(pkgname)
         for pkg in options.exclude_packages:
             self.exclude_packages.add(pkg)
 
@@ -655,6 +669,8 @@
         parser.error(str(e))
     options.program = prog
     options.args = args
+    options.support_packages = [
+        (pkgname, None) for pkgname in options.support_packages]
     if args:
         options.resource = args[0]
     else:

Modified: zpkgtools/trunk/zpkgtools/config.py
===================================================================
--- zpkgtools/trunk/zpkgtools/config.py	2005-09-19 18:10:56 UTC (rev 38524)
+++ zpkgtools/trunk/zpkgtools/config.py	2005-09-19 18:18:23 UTC (rev 38525)
@@ -53,6 +53,10 @@
         raise ValueError("resource-name does not support wildcards")
 
 
+def optional_location(value):
+    return value or None
+
+
 def resource_map(value):
     return value.map
 
@@ -85,6 +89,7 @@
         self.include_support_code = True
         self.default_collection = None
         self.release_name = None
+        self.support_packages = {}
 
     def finalize(self):
         """Load the location maps into `locations`."""
@@ -147,6 +152,9 @@
         for value in cf.location_maps:
             value = urlparse.urljoin(url, value)
             self.location_maps.append(value)
+        if cf.support_packages:
+            self.support_packages.update(cf.support_packages)
+        self.distribution_class = cf.distribution_class
 
 
 def defaultConfigurationPath():

Modified: zpkgtools/trunk/zpkgtools/config.xml
===================================================================
--- zpkgtools/trunk/zpkgtools/config.xml	2005-09-19 18:10:56 UTC (rev 38524)
+++ zpkgtools/trunk/zpkgtools/config.xml	2005-09-19 18:18:23 UTC (rev 38525)
@@ -79,4 +79,30 @@
        required="no"
        />
 
+  <key name="distribution-class"
+       datatype="dotted-name"
+       required="no"
+       />
+
+  <sectiontype
+      name="support-packages"
+      datatype="ZConfig.components.basic.mapping.mapping"
+      keytype="dotted-name"
+      >
+    <!-- Keys in the <support-packages> section name resources, but
+         those resources must be Python packages, so we use a
+         restricted keytype.
+         -->
+    <key name="+"
+         attribute="mapping"
+         datatype=".config.optional_location"
+         required="no"
+         />
+  </sectiontype>
+  <section name="*"
+           type="support-packages"
+           attribute="support_packages"
+           required="no"
+           />
+
 </schema>

Modified: zpkgtools/trunk/zpkgtools/tests/test_app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_app.py	2005-09-19 18:10:56 UTC (rev 38524)
+++ zpkgtools/trunk/zpkgtools/tests/test_app.py	2005-09-19 18:18:23 UTC (rev 38525)
@@ -256,13 +256,16 @@
 
     def test_support_packages(self):
         options = self.parse_args([])
-        self.assertEqual(options.support_packages, [])
+        self.assertEqual(options.support_packages,
+                         [])
         # one package:
         options = self.parse_args(["--support", "pkg"])
-        self.assertEqual(options.support_packages, ["pkg"])
+        self.assertEqual(options.support_packages,
+                         [("pkg", None)])
         # two packages
         options = self.parse_args(["--support", "pkg1", "--support=pkg2"])
-        self.assertEqual(options.support_packages, ["pkg1", "pkg2"])
+        self.assertEqual(options.support_packages,
+                         [("pkg1", None), ("pkg2", None)])
 
     def test_exclude_resources(self):
         options = self.parse_args([])

Modified: zpkgtools/trunk/zpkgtools/tests/test_config.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_config.py	2005-09-19 18:10:56 UTC (rev 38524)
+++ zpkgtools/trunk/zpkgtools/tests/test_config.py	2005-09-19 18:18:23 UTC (rev 38525)
@@ -87,6 +87,15 @@
         self.assertRaises(cfgparser.ConfigurationError,
                           self.load_text, "default-collection foo.*\n")
 
+        # distribution-class too many times
+        self.assertRaises(cfgparser.ConfigurationError,
+                          self.load_text, ("distribution-class foo\n"
+                                           "distribution-class foo\n"))
+
+        # distribution-class with a bad value
+        self.assertRaises(cfgparser.ConfigurationError,
+                          self.load_text, "distribution-class not-really\n")
+
         # release-name too many times
         self.assertRaises(cfgparser.ConfigurationError,
                           self.load_text, ("release-name foo\n"
@@ -96,6 +105,10 @@
         cf = self.load_text("default-collection foo\n")
         self.assertEqual(cf.default_collection, "foo")
 
+    def test_distribution_class(self):
+        cf = self.load_text("distribution-class foo.bar\n")
+        self.assertEqual(cf.distribution_class, "foo.bar")
+
     def test_release_name(self):
         cf = self.load_text("release-name foo\n")
         self.assertEqual(cf.release_name, "foo")
@@ -191,6 +204,27 @@
             "  reportlab.*\n"
             "</exclude>\n")
 
+    def test_support_packages(self):
+        cf = self.load_text(
+            "<support-packages>\n"
+            "  some.package\n"
+            "  another.package svn://svn.example.net/repo/somewhere/trunk\n"
+            "</support-packages>\n")
+        items = cf.support_packages.items()
+        items.sort()
+        self.assertEqual(
+            items,
+            [("another.package", "svn://svn.example.net/repo/somewhere/trunk"),
+             ("some.package", None)])
+
+    def test_support_packages_with_bad_key(self):
+        self.assertRaises(
+            cfgparser.ConfigurationError,
+            self.load_text,
+            "<support-packages>\n"
+            "  foo-bar \n"
+            "</support-packages>\n")
+
     def load_text(self, text, path=None, basedir=None):
         if path is None:
             if basedir is None:



More information about the zpkg mailing list