Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.buildout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Rafael Monnerat
slapos.buildout
Commits
8059b73a
Commit
8059b73a
authored
Nov 30, 2012
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Versions in versions sections can now be simple constraints, like
>=2.0dev in addition to being simple versions.
parent
57ebdeda
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
163 additions
and
18 deletions
+163
-18
CHANGES.rst
CHANGES.rst
+6
-0
src/zc/buildout/easy_install.py
src/zc/buildout/easy_install.py
+108
-16
src/zc/buildout/easy_install.txt
src/zc/buildout/easy_install.txt
+2
-2
src/zc/buildout/tests.py
src/zc/buildout/tests.py
+47
-0
No files found.
CHANGES.rst
View file @
8059b73a
Change History
Change History
**************
**************
2.0.0a5 (2012-??-??)
====================
- Versions in versions sections can now be simple constraints, like
>=2.0dev in addition to being simple versions.
2.0.0a4 (2012-11-19)
2.0.0a4 (2012-11-19)
====================
====================
...
...
src/zc/buildout/easy_install.py
View file @
8059b73a
...
@@ -67,11 +67,6 @@ buildout_and_distribute_path = [
...
@@ -67,11 +67,6 @@ buildout_and_distribute_path = [
pkg_resources
.
Requirement
.
parse
(
'zc.buildout'
)).
location
,
pkg_resources
.
Requirement
.
parse
(
'zc.buildout'
)).
location
,
]
]
class
IncompatibleVersionError
(
zc
.
buildout
.
UserError
):
"""A specified version is incompatible with a given requirement.
"""
FILE_SCHEME
=
re
.
compile
(
'file://'
,
re
.
I
).
match
FILE_SCHEME
=
re
.
compile
(
'file://'
,
re
.
I
).
match
class
AllowHostsPackageIndex
(
setuptools
.
package_index
.
PackageIndex
):
class
AllowHostsPackageIndex
(
setuptools
.
package_index
.
PackageIndex
):
...
@@ -548,17 +543,9 @@ class Installer:
...
@@ -548,17 +543,9 @@ class Installer:
def
_constrain
(
self
,
requirement
):
def
_constrain
(
self
,
requirement
):
version
=
self
.
_versions
.
get
(
requirement
.
project_name
)
constraint
=
self
.
_versions
.
get
(
requirement
.
project_name
)
if
version
:
if
constraint
:
if
version
not
in
requirement
:
requirement
=
_constrained_requirement
(
constraint
,
requirement
)
logger
.
error
(
"The version, %s, is not consistent with the "
"requirement, %r."
,
version
,
str
(
requirement
))
raise
IncompatibleVersionError
(
"Bad version"
,
version
)
requirement
=
pkg_resources
.
Requirement
.
parse
(
"%s[%s] ==%s"
%
(
requirement
.
project_name
,
','
.
join
(
requirement
.
extras
),
version
))
return
requirement
return
requirement
...
@@ -1290,3 +1277,108 @@ def redo_pyc(egg):
...
@@ -1290,3 +1277,108 @@ def redo_pyc(egg):
call_subprocess
(
args
)
call_subprocess
(
args
)
def
_constrained_requirement
(
constraint
,
requirement
):
return
pkg_resources
.
Requirement
.
parse
(
"%s[%s]%s"
%
(
requirement
.
project_name
,
','
.
join
(
requirement
.
extras
),
_constrained_requirement_constraint
(
constraint
,
requirement
)
)
)
class
IncompatibleConstraintError
(
zc
.
buildout
.
UserError
):
"""A specified version is incompatible with a given requirement.
"""
def
bad_constraint
(
constraint
,
requirement
):
logger
.
error
(
"The constraint, %s, is not consistent with the "
"requirement, %r."
,
constraint
,
str
(
requirement
))
raise
IncompatibleConstraintError
(
"Bad constraint"
,
constraint
,
requirement
)
_parse_constraint
=
re
.
compile
(
r'([<>]=?)(\
S+)
').match
_comparef = {
'
>
' : lambda x, y: x > y,
'
>=
': lambda x, y: x >= y,
'
<
' : lambda x, y: x < y,
'
<=
': lambda x, y: x <= y,
}
_opop = {'
<
': '
>
', '
>
': '
<
'}
_opeqop = {'
<
': '
>=
', '
>
': '
<=
'}
def _constrained_requirement_constraint(constraint, requirement):
# Simple cases:
# No specs tp merge with:
if not requirement.specs:
if not constraint[0] in '
<=>
':
constraint = '
==
' + constraint
return constraint
# Simple single-version constraint:
if constraint[0] not in '
<>
':
if constraint.startswith('
=
'):
assert constraint.startswith('
==
')
constraint = constraint[2:]
if constraint in requirement:
return '
==
'+constraint
bad_constraint(constraint, requirement)
# OK, we have a complex constraint (<. <=, >=, or >) and specs.
# In many cases, the spec needs to filter constraints.
# In other cases, the constraints need to limit the constraint.
specs = requirement.specs
cop, cv = _parse_constraint(constraint).group(1, 2)
pcv = pkg_resources.parse_version(cv)
# Special case, all of the specs are == specs:
if not [op for (op, v) in specs if op != '
==
']:
# There aren'
t
any
non
-==
specs
.
# See if any of the specs satisfy the constraint:
specs
=
[
op
+
v
for
(
op
,
v
)
in
specs
if
_comparef
[
cop
](
pkg_resources
.
parse_version
(
v
),
pcv
)]
if
specs
:
return
','
.
join
(
specs
)
bad_constraint
(
constraint
,
requirement
)
cop0
=
cop
[
0
]
# Normalize specs by splitting >= and <= specs. We meed tp do this
# becaise these have really weird semantics. Also cache parsed
# versions, which we'll need for comparisons:
specs
=
[]
for
op
,
v
in
requirement
.
specs
:
pv
=
pkg_resources
.
parse_version
(
v
)
if
op
==
_opeqop
[
cop0
]:
specs
.
append
((
op
[
0
],
v
,
pv
))
specs
.
append
((
'=='
,
v
,
pv
))
else
:
specs
.
append
((
op
,
v
,
pv
))
# Error if there are opposite specs that conflict with the constraint
# and there are no equal specs that satisfy the constraint:
if
[
v
for
(
op
,
v
,
pv
)
in
specs
if
op
==
_opop
[
cop0
]
and
_comparef
[
_opop
[
cop0
]](
pv
,
pcv
)
]:
eqspecs
=
[
op
+
v
for
(
op
,
v
,
pv
)
in
specs
if
_comparef
[
cop
](
pv
,
pcv
)]
if
eqspecs
:
# OK, we do, use these:
return
','
.
join
(
eqspecs
)
bad_constraint
(
constraint
,
requirement
)
# We have a combination of range constraints and eq specs that
# satisfy the requirement.
# Return the constraint + the filtered specs
return
','
.
join
(
op
+
v
for
(
op
,
v
)
in
(
[(
cop
,
cv
)]
+
[(
op
,
v
)
for
(
op
,
v
,
pv
)
in
specs
if
_comparef
[
cop
](
pv
,
pcv
)]
)
)
src/zc/buildout/easy_install.txt
View file @
8059b73a
...
@@ -242,13 +242,13 @@ we'll get an error:
...
@@ -242,13 +242,13 @@ we'll get an error:
... versions = dict(demo='0.2', demoneeded='1.0'))
... versions = dict(demo='0.2', demoneeded='1.0'))
Traceback (most recent call last):
Traceback (most recent call last):
...
...
Incompatible
VersionError: Bad version
0.2
Incompatible
ConstraintError: Bad constraint 0.2 demo>
0.2
>>> print_(handler)
>>> print_(handler)
zc.buildout.easy_install DEBUG
zc.buildout.easy_install DEBUG
Installing 'demo >0.2'.
Installing 'demo >0.2'.
zc.buildout.easy_install ERROR
zc.buildout.easy_install ERROR
The
version
, 0.2, is not consistent with the requirement, 'demo>0.2'.
The
constraint
, 0.2, is not consistent with the requirement, 'demo>0.2'.
>>> handler.clear()
>>> handler.clear()
...
...
src/zc/buildout/tests.py
View file @
8059b73a
...
@@ -2648,6 +2648,53 @@ def increment_on_command_line():
...
@@ -2648,6 +2648,53 @@ def increment_on_command_line():
recipe='zc.buildout:debug'
recipe='zc.buildout:debug'
"""
"""
def
test_constrained_requirement
():
"""
zc.buildout.easy_install._constrained_requirement(constraint, requitement)
Transforms an environment by applying a constraint.
Here's a table of examples:
>>> from zc.buildout.easy_install import IncompatibleConstraintError
>>> examples = [
... # original, constraint, transformed
... ('x', '1', 'x==1'),
... ('x>1', '2', 'x==2'),
... ('x>3', '2', IncompatibleConstraintError),
... ('x>1', '>2', 'x>2'),
... ('x>1', '>=2', 'x>=2'),
... ('x<1', '>2', IncompatibleConstraintError),
... ('x<=1', '>=1', 'x>=1,<1,==1'),
... ('x<3', '>1', 'x>1,<3'),
... ('x==2', '>1', 'x==2'),
... ('x==2', '>=2', 'x==2'),
... ('x[y]', '1', 'x[y]==1'),
... ('x[y]>1', '2', 'x[y]==2'),
... ('x<3', '2', 'x==2'),
... ('x<1', '2', IncompatibleConstraintError),
... ('x<3', '<2', 'x<2'),
... ('x<3', '<=2', 'x<=2'),
... ('x>3', '<2', IncompatibleConstraintError),
... ('x>=1', '<=1', 'x<=1,>1,==1'),
... ('x<3', '>1', 'x>1,<3'),
... ('x==2', '<3', 'x==2'),
... ('x==2', '<=2', 'x==2'),
... ('x[y]<3', '2', 'x[y]==2'),
... ]
>>> from zc.buildout.easy_install import _constrained_requirement
>>> for o, c, e in examples:
... try:
... o = pkg_resources.Requirement.parse(o)
... if isinstance(e, str):
... e = pkg_resources.Requirement.parse(e)
... g = _constrained_requirement(c, o)
... except IncompatibleConstraintError:
... g = IncompatibleConstraintError
... if g != e:
... print_('failed', o, c, g, '!=', e)
"""
######################################################################
######################################################################
def
create_sample_eggs
(
test
,
executable
=
sys
.
executable
):
def
create_sample_eggs
(
test
,
executable
=
sys
.
executable
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment