[Checkins] SVN: z3c.recipe.depgraph/branches/sdouche-exclude-eggs/src/z3c/recipe/depgraph/recipe.py Added 2 options in the recipe:

Sébastien Douche sdouche at free.fr
Wed Oct 21 08:50:04 EDT 2009


Log message for revision 105191:
  Added 2 options in the recipe:
  - strict-eggs: only eggs in the eggs option
  - re-exclude: easy way to exclude a project (like zope.*, z3c.*, ...)
  

Changed:
  U   z3c.recipe.depgraph/branches/sdouche-exclude-eggs/src/z3c/recipe/depgraph/recipe.py

-=-
Modified: z3c.recipe.depgraph/branches/sdouche-exclude-eggs/src/z3c/recipe/depgraph/recipe.py
===================================================================
--- z3c.recipe.depgraph/branches/sdouche-exclude-eggs/src/z3c/recipe/depgraph/recipe.py	2009-10-21 12:21:46 UTC (rev 105190)
+++ z3c.recipe.depgraph/branches/sdouche-exclude-eggs/src/z3c/recipe/depgraph/recipe.py	2009-10-21 12:50:04 UTC (rev 105191)
@@ -1,4 +1,5 @@
 import os
+import re
 
 from zc.buildout import easy_install
 from zc.recipe.egg import Egg
@@ -22,10 +23,13 @@
         self.options = options
         self.egg = Egg(buildout, options['recipe'], options)
         exclude = self.options.get('exclude', '')
+        re_exclude = self.options.get('re-exclude', '')
         self.exclude = set(exclude.split())
+        self.re_exclude = set(re_exclude.split())
+        self.strict_egg = self.options.get('strict-egg', '').lower() in ('1', 'true', 'yes')
         self.output = self.options.get(
             'output', os.path.join(
-            self.buildout['buildout']['parts-directory'], self.name))
+                self.buildout['buildout']['parts-directory'], self.name))
         extras = self.options.get('extras', 'false')
         self.extras = extras.lower() in ('1', 'true', 'yes')
 
@@ -39,11 +43,34 @@
         variants = options.get('variants', 'base tred scc')
         variants = [v.strip() for v in variants.split()]
 
-        # Install an interpreter
-        packages = set([dist.project_name for dist in ws.by_key.values()])
-        packages = packages - EXCLUDE_PACKAGES - self.exclude
-        packages = list(packages)
+        def matcher(names, patterns):
+            names = set(names)
+            matched_names = set()
+            compiled_patterns = [re.compile(pattern) for pattern in patterns]
 
+            def match(name, compiled_patterns):
+                for pattern in compiled_patterns:
+                    if pattern.search(name):
+                         # matching one pattern is sufficient
+                        matched_names.add(name)
+                        return
+
+            for name in names:
+                match(name, compiled_patterns)
+            return matched_names
+
+        if self.strict_egg:
+            # strict_egg is set, return only specified eggs in the recipe
+            packages = reqs
+        else:
+            # Install an interpreter to find eggs
+            packages = set([dist.project_name for dist in ws.by_key.values()])
+            # Remove eggs listed in exclude option
+            packages = packages - EXCLUDE_PACKAGES - self.exclude
+            # Remove eggs listed in re-exclude option
+            packages = packages - matcher(packages, self.re_exclude)
+            packages = list(packages)
+
         # Allow to map distribution names to different package names
         pmap = dict()
         package_map = options.get('package-map', '').strip()
@@ -62,7 +89,7 @@
                 variants=variants,
                 extras=self.extras,
                 ),
-            )
+        )
 
         reqs = ['tl.eggdeps']
         scripts = {
@@ -72,7 +99,7 @@
         easy_install.scripts(
             reqs, ws, options['executable'], options['bin-directory'],
             scripts=scripts,
-            )
+        )
         return self.output
 
     def update(self):



More information about the checkins mailing list