[Zope-CVS] SVN: zpkgtools/trunk/ Implemented the ``<exclude>``
section, which is the conf file equivalent
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Aug 31 13:34:59 EDT 2005
Log message for revision 38202:
Implemented the ``<exclude>`` section, which is the conf file equivalent
of the `-x` and `--exclude` command line options.
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
A zpkgtools/trunk/zpkgtools/tests/input/exclude.cfg
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-08-31 17:17:07 UTC (rev 38201)
+++ zpkgtools/trunk/doc/zpkg.txt 2005-08-31 17:34:59 UTC (rev 38202)
@@ -172,7 +172,12 @@
Note that all ``<resources>`` sections will be processed before any
external maps are loaded, regardless of ordering.
+Optionally, there is a ``<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.
+
Resource Maps
-------------
Modified: zpkgtools/trunk/zpkgtools/app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/app.py 2005-08-31 17:17:07 UTC (rev 38201)
+++ zpkgtools/trunk/zpkgtools/app.py 2005-08-31 17:34:59 UTC (rev 38202)
@@ -88,6 +88,8 @@
if cf.application:
self.options.application = True
+ self.exclude_packages = sets.Set(cf.exclude_packages)
+
# XXX Hack: This should be part of BuilderApplication
if options.include_support_code is None:
options.include_support_code = cf.include_support_code
@@ -135,7 +137,6 @@
self.support_packages = DEFAULT_SUPPORT_PACKAGES[:]
self.support_packages.extend(
[(pkg, None) for pkg in options.support_packages])
- self.exclude_packages = sets.Set()
for pkg in options.exclude_packages:
if pkg not in self.exclude_packages:
self.exclude_packages.add(pkg)
@@ -146,7 +147,7 @@
This method does everything needed to knit a distribution
together; it should be refactored substantially.
"""
- dep_sources = {}
+ dep_sources = {}
top = self.get_component(self.resource, self.resource_url)
top.write_package(self.destination)
distclass = self.options.distribution_class
Modified: zpkgtools/trunk/zpkgtools/config.py
===================================================================
--- zpkgtools/trunk/zpkgtools/config.py 2005-08-31 17:17:07 UTC (rev 38201)
+++ zpkgtools/trunk/zpkgtools/config.py 2005-08-31 17:34:59 UTC (rev 38202)
@@ -38,6 +38,10 @@
return value.map
+def exclude(value):
+ return value.mapping.keys()
+
+
class Configuration:
"""Configuration settings for **zpkg**.
@@ -48,6 +52,8 @@
- `include_support_code`: Indicates whether support code should
be included in distributions.
+
+ - `exclude_packages`: Resources to exclude from the package.
"""
def __init__(self):
@@ -56,6 +62,7 @@
self.collect_dependencies = False
self.location_maps = []
self.locations = locationmap.LocationMap()
+ self.exclude_packages = []
self.include_support_code = True
self.default_collection = None
@@ -115,6 +122,7 @@
self.default_collection = cf.default_collection
self.include_support_code = cf.include_support_code
self.resource_maps = cf.resource_maps
+ self.exclude_packages = cf.exclude_packages
for value in cf.location_maps:
value = urlparse.urljoin(url, value)
self.location_maps.append(value)
Modified: zpkgtools/trunk/zpkgtools/config.xml
===================================================================
--- zpkgtools/trunk/zpkgtools/config.xml 2005-08-31 17:17:07 UTC (rev 38201)
+++ zpkgtools/trunk/zpkgtools/config.xml 2005-08-31 17:34:59 UTC (rev 38202)
@@ -33,6 +33,24 @@
</description>
</multikey>
+ <sectiontype name="exclude"
+ datatype=".config.exclude"
+ keytype=".config.non_empty_string"
+ >
+ <key name="+"
+ attribute="mapping"
+ type=".config.non_empty_string"
+ />
+ </sectiontype>
+
+ <section type="exclude"
+ attribute="exclude_packages"
+ >
+ <description>
+ A list of packages that are excluded from the collection.
+ </description>
+ </section>
+
<key name="build-application"
datatype="boolean"
required="no"
Added: zpkgtools/trunk/zpkgtools/tests/input/exclude.cfg
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/input/exclude.cfg 2005-08-31 17:17:07 UTC (rev 38201)
+++ zpkgtools/trunk/zpkgtools/tests/input/exclude.cfg 2005-08-31 17:34:59 UTC (rev 38202)
@@ -0,0 +1,5 @@
+# Test file for exclude section
+<exclude>
+ foo.bar
+ blah
+</exclude>
\ No newline at end of file
Modified: zpkgtools/trunk/zpkgtools/tests/test_app.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_app.py 2005-08-31 17:17:07 UTC (rev 38201)
+++ zpkgtools/trunk/zpkgtools/tests/test_app.py 2005-08-31 17:34:59 UTC (rev 38202)
@@ -411,6 +411,19 @@
# convert package_map to URL so relative names are resolved properly
return "file://" + urllib.pathname2url(package_map)
+ def test_creating_complete_exclude_resources_list(self):
+ config = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+ "input", "exclude.cfg")
+ package_map = self.createPackageMap()
+
+ app = self.createApplication(
+ ["-x", "foo.baz", "--exclude", "this",
+ "-C", config, "-m", package_map, "package"])
+ excluded = list(app.exclude_packages)
+ excluded.sort()
+ self.assertEqual(excluded,
+ ["blah", "foo.bar", "foo.baz", "this"])
+
def test_building_distribution_tree_only(self):
# This builds a package and checks that the tree_only flag
# causes the application to build a tree in the current
Modified: zpkgtools/trunk/zpkgtools/tests/test_config.py
===================================================================
--- zpkgtools/trunk/zpkgtools/tests/test_config.py 2005-08-31 17:17:07 UTC (rev 38201)
+++ zpkgtools/trunk/zpkgtools/tests/test_config.py 2005-08-31 17:34:59 UTC (rev 38202)
@@ -152,6 +152,27 @@
finally:
os.unlink(path)
+ def test_exclude_packages(self):
+ cf = config.Configuration()
+ fd, path = tempfile.mkstemp(".conf", text=True)
+ f = os.fdopen(fd, "w+")
+ f.write(
+ "<exclude>\n"
+ " reportlab\n"
+ " zope.app\n"
+ " zpkgsetup\n"
+ "</exclude>\n")
+ f.close()
+ where = os.path.dirname(path)
+ whereurl = urlutils.file_url(where)
+ try:
+ cf.loadPath(path)
+ cf.exclude_packages.sort()
+ self.assertEqual(cf.exclude_packages,
+ ['reportlab', 'zope.app', 'zpkgsetup'])
+ finally:
+ os.unlink(path)
+
def load_text(self, text, path=None, basedir=None):
if path is None:
if basedir is None:
More information about the Zope-CVS
mailing list