Permalink
Browse files

ENH: added ability to specify stricter requirements; added better che…

…cking for consistency of requirements

git-svn-id: https://svn.enthought.com/svn/enthought/Enstaller/trunk@24021 651a555e-23ca-0310-84fe-ca9f7c59d2ea
  • Loading branch information...
1 parent 9b90aa2 commit 556c8692e9607ca265c9525564f6e83444f1a4af ischnell committed Jul 2, 2009
Showing with 56 additions and 6 deletions.
  1. +2 −3 enstaller/indexed_repo/chain.py
  2. +38 −0 enstaller/indexed_repo/requirement.py
  3. +16 −3 setuptools/command/bdist_egg.py
@@ -8,7 +8,7 @@
import metadata
import utils
-from requirement import Req, add_Reqs_to_spec
+from requirement import Req, add_Reqs_to_spec, strictest
@@ -176,9 +176,8 @@ def _add_reqs(reqs, req):
for name in names:
# get all requirements for the name
rs = [r for r in reqs if r.name == name]
- rs.sort(key=lambda r: r.strictness)
# add the requirement with greatest strictness
- res.add(rs[-1])
+ res.add(strictest(rs))
return res
@@ -103,3 +103,41 @@ def dist_as_req(dist, strictness=3):
if strictness >= 3:
req_string += '-%s' % build
return Req(req_string)
+
+
+def strictest(reqs):
+ """
+ Given a some requirements, returns the strictest.
+ The function also makes sure that the requirements are consistent:
+ Examples:
+
+ >>> strictest([Req('vtk 5.4.0'), Req('vtk'), Req('vtk 5.4.0-2')])
+ Req('vtk 5.4.0-2')
+
+ >>> strictest([Req('vtk 5.4.0'), Req('vtk'), Req('vtk 5.2.0')])
+ Traceback (most recent call last):
+ ...
+ Exception: Inconsitent requirements: [Req('vtk 5.4.0'), Req('vtk 5.2.0')]
+
+ """
+ # FIXME:
+ # add handling multiple version, as well as cases like:
+ # strictest([Req('bar'), Req('foo 1.0'), Req('foo 1.4-2')])
+
+ # For each strictness, make sure we have 0 or 1 requirements
+ for strict in [1, 2, 3]:
+ # The requirements with strictness s
+ rss = [r for r in reqs if r.strictness == strict]
+ if len(rss) > 1:
+ raise Exception("Inconsitent requirements: %r" % rss)
+
+ # sort by strictness
+ reqs.sort(key=lambda r: r.strictness)
+
+ # return the requirement with greatest strictness
+ return reqs[-1]
+
+
+if __name__ == '__main__':
+ import doctest
+ doctest.testmod()
@@ -28,6 +28,7 @@ def write_spec_depend(egg_info):
egg_info is the path to the EGG-INFO directory
"""
from enstaller.indexed_repo.metadata import data_from_spec
+ from enstaller.indexed_repo.utils import split_old_version
pkg_info = open(os.path.join(egg_info, 'PKG-INFO')).read()
@@ -40,13 +41,25 @@ def write_spec_depend(egg_info):
spec[var] = pat.search(pkg_info).group(1)
requires_txt = os.path.join(egg_info, 'requires.txt')
- pat = re.compile(r'[\w\-.]+')
+ pat = re.compile(r'''([\w\-.]+) # name
+ (?:[\s=<>]*([\w.]+))? # version
+ ''', re.X)
pkgs = set()
if os.path.isfile(requires_txt):
for line in open(requires_txt):
- m = pat.match(line.strip())
+ line = line.strip()
+ m = pat.match(line)
if m:
- pkgs.add(m.group())
+ # Construct the new requirement string
+ r = m.group(1)
+ if m.lastindex == 2:
+ version, build = split_old_version(m.group(2))
+ r += ' %s' % version
+ if build is not None:
+ r += '-%i' % build
+ pkgs.add(r)
+ else:
+ print "WARNING: requirement %r not recognized" % line
spec['packages'] = list(pkgs)
spec_dir = os.path.join(egg_info, 'spec')

0 comments on commit 556c869

Please sign in to comment.