[Zope-CVS] SVN: zpkgtools/trunk/ - add support for a
default-collection configuration key that specifies the
Fred L. Drake, Jr.
fdrake at gmail.com
Mon Aug 29 11:15:02 EDT 2005
Log message for revision 38138:
- add support for a default-collection configuration key that specifies the
resource to be packaged if not specified on the command line
- relax the test for non-Python-package packaging components; instead of
requiring SETUP.cfg, allow DEPENDENCIES.cfg or PACKAGE.cfg to be sufficient
Changed:
U zpkgtools/trunk/doc/collections.txt
U zpkgtools/trunk/doc/zpkg.txt
U zpkgtools/trunk/zpkgtools/app.py
U zpkgtools/trunk/zpkgtools/config.py
A zpkgtools/trunk/zpkgtools/tests/input/package.conf
U zpkgtools/trunk/zpkgtools/tests/test_app.py
U zpkgtools/trunk/zpkgtools/tests/test_config.py
-=-
Modified: zpkgtools/trunk/doc/collections.txt
===================================================================
--- zpkgtools/trunk/doc/collections.txt 2005-08-29 14:39:01 UTC (rev 38137)
+++ zpkgtools/trunk/doc/collections.txt 2005-08-29 15:15:02 UTC (rev 38138)
@@ -94,9 +94,11 @@
`SETUP.cfg`
Information about what's included in the distrubution, primarily for
- use by a `setup.py` script. For components that aren't Python
- packages, this file is required.
+ use by a `setup.py` script.
+For components that aren't Python packages, at least one of
+`DEPENDENCIES.cfg`, `PACKAGE.cfg`, or `SETUP.cfg` is required.
+
Additional information on these files can be found in `Metadata
Descriptions for Distributions <metadata.html>`_.
Modified: zpkgtools/trunk/doc/zpkg.txt
===================================================================
--- zpkgtools/trunk/doc/zpkg.txt 2005-08-29 14:39:01 UTC (rev 38137)
+++ zpkgtools/trunk/doc/zpkg.txt 2005-08-29 15:15:02 UTC (rev 38138)
@@ -128,6 +128,10 @@
added to the distribution if they can be located. This is the same as
using the **-c** option on the command line.
+The ``default-collection`` value is used to specify a resource that
+should be used as the top-level collection to package if no collection
+is specified on the command line.
+
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
Modified: zpkgtools/trunk/zpkgtools/app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/app.py 2005-08-29 14:39:01 UTC (rev 38137)
+++ zpkgtools/trunk/zpkgtools/app.py 2005-08-29 15:15:02 UTC (rev 38138)
@@ -86,6 +86,10 @@
# XXX Hack: This should be part of BuilderApplication
if options.include_support_code is None:
options.include_support_code = cf.include_support_code
+ if options.resource is None:
+ if not cf.default_collection:
+ self.error("no resource to package specified")
+ options.resource = cf.default_collection
def error(self, message, rc=1):
self.logger.critical(message)
@@ -385,8 +389,7 @@
#
# Check that this package is valid:
#
- setup_cfg = os.path.join(self.source, package.PACKAGE_CONF)
- if self.is_python_package() or os.path.isfile(setup_cfg):
+ if self.is_python_package() or self.has_packaging_data():
return
raise zpkgtools.Error(
"%r is an invalid distribution component: all components must"
@@ -447,6 +450,17 @@
dir = self.source
return os.path.isfile(os.path.join(dir, "__init__.py"))
+ def has_packaging_data(self):
+ """Return True iff this component contains packaging metadata."""
+ # Should PUBLICATION.cfg count toword this?
+ dir = self.source
+ for fn in (package.PACKAGE_CONF,
+ include.PACKAGE_CONF,
+ "DEPENDENCIES.cfg"):
+ if os.path.isfile(os.path.join(dir, fn)):
+ return True
+ return False
+
def write_package(self, destination):
self.destination = destination
if not os.path.exists(destination):
@@ -624,11 +638,14 @@
" (dependencies will be ignored)"))
options, args = parser.parse_args(argv[1:])
- if len(args) != 1:
- parser.error("wrong number of arguments")
+ if len(args) > 1:
+ parser.error("too many arguments")
options.program = prog
options.args = args
- options.resource = args[0]
+ if args:
+ options.resource = args[0]
+ else:
+ options.resource = None
if options.revision_tag and not options.version:
options.version = version_from_tagname(options.revision_tag)
if not options.version:
Modified: zpkgtools/trunk/zpkgtools/config.py
===================================================================
--- zpkgtools/trunk/zpkgtools/config.py 2005-08-29 14:39:01 UTC (rev 38137)
+++ zpkgtools/trunk/zpkgtools/config.py 2005-08-29 15:15:02 UTC (rev 38138)
@@ -59,6 +59,7 @@
"include-support-code": boolean,
"collect-dependencies": boolean,
"build-application": boolean,
+ "default-collection": non_empty_string,
}, ["resources"], None))
self.base = urlutils.file_url(filename)
self.filename = filename
@@ -105,6 +106,7 @@
self.location_maps = []
self.locations = locationmap.LocationMap()
self.include_support_code = True
+ self.default_collection = None
def finalize(self):
"""Load the location maps into `locations`."""
@@ -169,6 +171,12 @@
"build-application can be specified at most once")
if cf.build_application:
self.application = cf.build_application[0]
+ # default-collection
+ if len(cf.default_collection) > 1:
+ raise cfgparser.ConfigurationError(
+ "default-collection can be specified at most once")
+ if cf.default_collection:
+ self.default_collection = cf.default_collection[0]
def defaultConfigurationPath():
Added: zpkgtools/trunk/zpkgtools/tests/input/package.conf
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/input/package.conf 2005-08-29 14:39:01 UTC (rev 38137)
+++ zpkgtools/trunk/zpkgtools/tests/input/package.conf 2005-08-29 15:15:02 UTC (rev 38138)
@@ -0,0 +1,6 @@
+# This configuration file is used from zpkgtools.tests.test_app, test
+# class BuilderApplicationTestCase, in the
+# test_building_default_collection() and
+# test_building_default_collection_override() methods.
+
+default-collection package
Property changes on: zpkgtools/trunk/zpkgtools/tests/input/package.conf
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: zpkgtools/trunk/zpkgtools/tests/test_app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_app.py 2005-08-29 14:39:01 UTC (rev 38137)
+++ zpkgtools/trunk/zpkgtools/tests/test_app.py 2005-08-29 15:15:02 UTC (rev 38138)
@@ -419,19 +419,51 @@
app = self.createApplication(
["-f", "-t", "-m", package_map, "package"])
app.run()
- # make sure the local tree is present and looks like one of
- # our distributions:
- self.assert_(os.path.isdir("package-0.0.0"))
- self.assert_(os.path.isdir(os.path.join("package-0.0.0", "package")))
- self.assert_(os.path.isdir(os.path.join("package-0.0.0", "Support")))
- self.assert_(isfile("package-0.0.0", "setup.py"))
- self.assert_(isfile("package-0.0.0", "setup.cfg"))
- self.assert_(isfile("package-0.0.0", "MANIFEST"))
- self.assert_(isfile("package-0.0.0", "Support", "MANIFEST"))
- self.assert_(isfile("package-0.0.0", "Support", "README.txt"))
- self.assert_(isfile("package-0.0.0", "Support", "setup.py"))
- shutil.rmtree("package-0.0.0")
+ self.check_package_tree("package")
+ def test_building_default_collection(self):
+ # Test that a configuration's setting of a default collection
+ # is used to actually determine what's built.
+ config = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+ "input", "package.conf")
+ package_map = self.createPackageMap()
+ app = self.createApplication(
+ ["-C", config, "-t", "-m", package_map])
+ app.run()
+ self.check_package_tree("package")
+
+ def test_building_default_collection_override(self):
+ # Test that a configuration's setting of a default collection
+ # can be overridden to actually determine what's built.
+ import logging
+ root_logger = logging.getLogger()
+ root_logger.addHandler(logging.StreamHandler())
+ config = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+ "input", "package.conf")
+ package_map = self.createPackageMap()
+ app = self.createApplication(
+ ["-C", config, "-t", "-m", package_map, "collection-1"])
+ app.run()
+ self.check_package_tree("collection-1")
+
+ def check_package_tree(self, name, version="0.0.0"):
+ # Make sure the local tree is present and looks like one of
+ # our distributions; this relies on the tree being built
+ # unpacked (the -t option).
+ pd = "%s-%s" % (name, version)
+ self.assert_(os.path.isdir(pd))
+ try:
+ self.assert_(os.path.isdir(os.path.join(pd, name)))
+ self.assert_(os.path.isdir(os.path.join(pd, "Support")))
+ self.assert_(isfile(pd, "setup.py"))
+ self.assert_(isfile(pd, "setup.cfg"))
+ self.assert_(isfile(pd, "MANIFEST"))
+ self.assert_(isfile(pd, "Support", "MANIFEST"))
+ self.assert_(isfile(pd, "Support", "README.txt"))
+ self.assert_(isfile(pd, "Support", "setup.py"))
+ finally:
+ shutil.rmtree(pd)
+
def test_adding_extra_support_code(self):
package_map = self.createPackageMap()
app = self.createApplication(
Modified: zpkgtools/trunk/zpkgtools/tests/test_config.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_config.py 2005-08-29 14:39:01 UTC (rev 38137)
+++ zpkgtools/trunk/zpkgtools/tests/test_config.py 2005-08-29 15:15:02 UTC (rev 38138)
@@ -43,6 +43,7 @@
self.assert_(not cf.collect_dependencies)
self.assertEqual(len(cf.locations), 0)
self.assertEqual(len(cf.location_maps), 0)
+ self.assert_(not cf.default_collection)
def test_loadPath(self):
path = os.path.join(here, "zpkg-ok.conf")
@@ -77,6 +78,15 @@
self.load_text, ("include-support-code false\n"
"include-support-code false\n"))
+ # default-collection too many times
+ self.assertRaises(cfgparser.ConfigurationError,
+ self.load_text, ("default-collection foo\n"
+ "default-collection foo\n"))
+
+ def test_default_collection(self):
+ cf = self.load_text("default-collection foo\n")
+ self.assertEqual(cf.default_collection, "foo")
+
def test_loadPath_no_such_file(self):
path = os.path.join(here, "no-such-file")
cf = config.Configuration()
More information about the Zope-CVS
mailing list