Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
distutils.versionpredicate.VersionPredicate Class Reference

List of all members.

Public Member Functions

def __init__
def __str__
def satisfied_by

Public Attributes

 pred

Detailed Description

Parse and test package version predicates.

>>> v = VersionPredicate('pyepat.abc (>1.0, <3333.3a1, !=1555.1b3)')

The `name` attribute provides the full dotted name that is given::

>>> v.name
'pyepat.abc'

The str() of a `VersionPredicate` provides a normalized
human-readable version of the expression::

>>> print(v)
pyepat.abc (> 1.0, < 3333.3a1, != 1555.1b3)

The `satisfied_by()` method can be used to determine with a given
version number is included in the set described by the version
restrictions::

>>> v.satisfied_by('1.1')
True
>>> v.satisfied_by('1.4')
True
>>> v.satisfied_by('1.0')
False
>>> v.satisfied_by('4444.4')
False
>>> v.satisfied_by('1555.1b3')
False

`VersionPredicate` is flexible in accepting extra whitespace::

>>> v = VersionPredicate(' pat( ==  0.1  )  ')
>>> v.name
'pat'
>>> v.satisfied_by('0.1')
True
>>> v.satisfied_by('0.2')
False

If any version numbers passed in do not conform to the
restrictions of `StrictVersion`, a `ValueError` is raised::

>>> v = VersionPredicate('p1.p2.p3.p4(>=1.0, <=1.3a1, !=1.2zb3)')
Traceback (most recent call last):
  ...
ValueError: invalid version number '1.2zb3'

It the module or package name given does not conform to what's
allowed as a legal module or package name, `ValueError` is
raised::

>>> v = VersionPredicate('foo-bar')
Traceback (most recent call last):
  ...
ValueError: expected parenthesized list: '-bar'

>>> v = VersionPredicate('foo bar (12.21)')
Traceback (most recent call last):
  ...
ValueError: expected parenthesized list: 'bar (12.21)'

Definition at line 31 of file versionpredicate.py.


Constructor & Destructor Documentation

def distutils.versionpredicate.VersionPredicate.__init__ (   self,
  versionPredicateStr 
)
Parse a version predicate string.

Definition at line 96 of file versionpredicate.py.

00096 
00097     def __init__(self, versionPredicateStr):
00098         """Parse a version predicate string.
00099         """
00100         # Fields:
00101         #    name:  package name
00102         #    pred:  list of (comparison string, StrictVersion)
00103 
00104         versionPredicateStr = versionPredicateStr.strip()
00105         if not versionPredicateStr:
00106             raise ValueError("empty package restriction")
00107         match = re_validPackage.match(versionPredicateStr)
00108         if not match:
00109             raise ValueError("bad package name in %r" % versionPredicateStr)
00110         self.name, paren = match.groups()
00111         paren = paren.strip()
00112         if paren:
00113             match = re_paren.match(paren)
00114             if not match:
00115                 raise ValueError("expected parenthesized list: %r" % paren)
00116             str = match.groups()[0]
00117             self.pred = [splitUp(aPred) for aPred in str.split(",")]
00118             if not self.pred:
00119                 raise ValueError("empty parenthesized list in %r"
00120                                  % versionPredicateStr)
00121         else:
00122             self.pred = []

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

Definition at line 123 of file versionpredicate.py.

00123 
00124     def __str__(self):
00125         if self.pred:
00126             seq = [cond + " " + str(ver) for cond, ver in self.pred]
00127             return self.name + " (" + ", ".join(seq) + ")"
00128         else:
00129             return self.name

Here is the call graph for this function:

True if version is compatible with all the predicates in self.
The parameter version must be acceptable to the StrictVersion
constructor.  It may be either a string or StrictVersion.

Definition at line 130 of file versionpredicate.py.

00130 
00131     def satisfied_by(self, version):
00132         """True if version is compatible with all the predicates in self.
00133         The parameter version must be acceptable to the StrictVersion
00134         constructor.  It may be either a string or StrictVersion.
00135         """
00136         for cond, ver in self.pred:
00137             if not compmap[cond](version, ver):
00138                 return False
00139         return True
00140 


Member Data Documentation

Definition at line 116 of file versionpredicate.py.


The documentation for this class was generated from the following file: