Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
ffe568cb
Commit
ffe568cb
authored
Apr 05, 2016
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #530 from s-t-e-v-e-n-k/fix-extra-markers-requires
Restore evaluating environment markers in WorkingSet
parents
9803058d
1cdd9408
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
11 deletions
+85
-11
pkg_resources/__init__.py
pkg_resources/__init__.py
+11
-3
pkg_resources/tests/test_resources.py
pkg_resources/tests/test_resources.py
+74
-5
setuptools/tests/test_egg_info.py
setuptools/tests/test_egg_info.py
+0
-3
No files found.
pkg_resources/__init__.py
View file @
ffe568cb
...
@@ -791,6 +791,8 @@ class WorkingSet(object):
...
@@ -791,6 +791,8 @@ class WorkingSet(object):
# key -> dist
# key -> dist
best = {}
best = {}
to_activate = []
to_activate = []
# Map requirement to the extras that require it
extra_req_mapping = {}
# Mapping of requirement to set of distributions that required it;
# Mapping of requirement to set of distributions that required it;
# useful for reporting info about conflicts.
# useful for reporting info about conflicts.
...
@@ -804,9 +806,14 @@ class WorkingSet(object):
...
@@ -804,9 +806,14 @@ class WorkingSet(object):
continue
continue
# If the req has a marker, evaluate it -- skipping the req if
# If the req has a marker, evaluate it -- skipping the req if
# it evaluates to False.
# it evaluates to False.
# https://github.com/pypa/setuptools/issues/523
if req.marker:
_issue_523_bypass = True
result = []
if not _issue_523_bypass and req.marker and not req.marker.evaluate():
if req in extra_req_mapping:
for extra in extra_req_mapping[req] or ['']:
result.append(req.marker.evaluate({'
extra
': extra}))
else:
result.append(req.marker.evaluate())
if not any(result):
continue
continue
dist = best.get(req.key)
dist = best.get(req.key)
if dist is None:
if dist is None:
...
@@ -840,6 +847,7 @@ class WorkingSet(object):
...
@@ -840,6 +847,7 @@ class WorkingSet(object):
# Register the new requirements needed by req
# Register the new requirements needed by req
for new_requirement in new_requirements:
for new_requirement in new_requirements:
required_by[new_requirement].add(req.project_name)
required_by[new_requirement].add(req.project_name)
extra_req_mapping[new_requirement] = req.extras
processed[req] = True
processed[req] = True
...
...
pkg_resources/tests/test_resources.py
View file @
ffe568cb
...
@@ -171,16 +171,85 @@ class TestDistro:
...
@@ -171,16 +171,85 @@ class TestDistro:
msg
=
'Foo 0.9 is installed but Foo==1.2 is required'
msg
=
'Foo 0.9 is installed but Foo==1.2 is required'
assert
vc
.
value
.
report
()
==
msg
assert
vc
.
value
.
report
()
==
msg
@
pytest
.
mark
.
xfail
(
reason
=
"Functionality disabled; see #523"
)
def
test_environment_marker_evaluation_negative
(
self
):
def
test_environment_markers
(
self
):
"""Environment markers are evaluated at resolution time."""
"""
Environment markers are evaluated at resolution time.
"""
ad
=
pkg_resources
.
Environment
([])
ad
=
pkg_resources
.
Environment
([])
ws
=
WorkingSet
([])
ws
=
WorkingSet
([])
res
=
ws
.
resolve
(
parse_requirements
(
"Foo;python_version<'2'"
),
ad
)
res
=
ws
.
resolve
(
parse_requirements
(
"Foo;python_version<'2'"
),
ad
)
assert
list
(
res
)
==
[]
assert
list
(
res
)
==
[]
def
test_environment_marker_evaluation_positive
(
self
):
ad
=
pkg_resources
.
Environment
([])
ws
=
WorkingSet
([])
Foo
=
Distribution
.
from_filename
(
"/foo_dir/Foo-1.2.dist-info"
)
ad
.
add
(
Foo
)
res
=
ws
.
resolve
(
parse_requirements
(
"Foo;python_version>='2'"
),
ad
)
assert
list
(
res
)
==
[
Foo
]
def
test_marker_evaluation_with_extras
(
self
):
"""Extras are also evaluated as markers at resolution time."""
ad
=
pkg_resources
.
Environment
([])
ws
=
WorkingSet
([])
# Metadata needs to be native strings due to cStringIO behaviour in
# 2.6, so use str().
Foo
=
Distribution
.
from_filename
(
"/foo_dir/Foo-1.2.dist-info"
,
metadata
=
Metadata
((
"METADATA"
,
str
(
"Provides-Extra: baz
\
n
"
"Requires-Dist: quux; extra=='baz'"
)))
)
ad
.
add
(
Foo
)
assert
list
(
ws
.
resolve
(
parse_requirements
(
"Foo"
),
ad
))
==
[
Foo
]
quux
=
Distribution
.
from_filename
(
"/foo_dir/quux-1.0.dist-info"
)
ad
.
add
(
quux
)
res
=
list
(
ws
.
resolve
(
parse_requirements
(
"Foo[baz]"
),
ad
))
assert
res
==
[
Foo
,
quux
]
def
test_marker_evaluation_with_multiple_extras
(
self
):
ad
=
pkg_resources
.
Environment
([])
ws
=
WorkingSet
([])
# Metadata needs to be native strings due to cStringIO behaviour in
# 2.6, so use str().
Foo
=
Distribution
.
from_filename
(
"/foo_dir/Foo-1.2.dist-info"
,
metadata
=
Metadata
((
"METADATA"
,
str
(
"Provides-Extra: baz
\
n
"
"Requires-Dist: quux; extra=='baz'
\
n
"
"Provides-Extra: bar
\
n
"
"Requires-Dist: fred; extra=='bar'
\
n
"
)))
)
ad
.
add
(
Foo
)
quux
=
Distribution
.
from_filename
(
"/foo_dir/quux-1.0.dist-info"
)
ad
.
add
(
quux
)
fred
=
Distribution
.
from_filename
(
"/foo_dir/fred-0.1.dist-info"
)
ad
.
add
(
fred
)
res
=
list
(
ws
.
resolve
(
parse_requirements
(
"Foo[baz,bar]"
),
ad
))
assert
sorted
(
res
)
==
[
fred
,
quux
,
Foo
]
def
test_marker_evaluation_with_extras_loop
(
self
):
ad
=
pkg_resources
.
Environment
([])
ws
=
WorkingSet
([])
# Metadata needs to be native strings due to cStringIO behaviour in
# 2.6, so use str().
a
=
Distribution
.
from_filename
(
"/foo_dir/a-0.2.dist-info"
,
metadata
=
Metadata
((
"METADATA"
,
str
(
"Requires-Dist: c[a]"
)))
)
b
=
Distribution
.
from_filename
(
"/foo_dir/b-0.3.dist-info"
,
metadata
=
Metadata
((
"METADATA"
,
str
(
"Requires-Dist: c[b]"
)))
)
c
=
Distribution
.
from_filename
(
"/foo_dir/c-1.0.dist-info"
,
metadata
=
Metadata
((
"METADATA"
,
str
(
"Provides-Extra: a
\
n
"
"Requires-Dist: b;extra=='a'
\
n
"
"Provides-Extra: b
\
n
"
"Requires-Dist: foo;extra=='b'"
)))
)
foo
=
Distribution
.
from_filename
(
"/foo_dir/foo-0.1.dist-info"
)
for
dist
in
(
a
,
b
,
c
,
foo
):
ad
.
add
(
dist
)
res
=
list
(
ws
.
resolve
(
parse_requirements
(
"a"
),
ad
))
assert
res
==
[
a
,
c
,
b
,
foo
]
def
testDistroDependsOptions
(
self
):
def
testDistroDependsOptions
(
self
):
d
=
self
.
distRequires
(
"""
d
=
self
.
distRequires
(
"""
Twisted>=1.5
Twisted>=1.5
...
...
setuptools/tests/test_egg_info.py
View file @
ffe568cb
...
@@ -104,7 +104,6 @@ class TestEggInfo(object):
...
@@ -104,7 +104,6 @@ class TestEggInfo(object):
'setup.py'
:
setup_script
,
'setup.py'
:
setup_script
,
})
})
@
pytest
.
mark
.
xfail
(
reason
=
"Functionality disabled; see #523"
)
def
test_install_requires_with_markers
(
self
,
tmpdir_cwd
,
env
):
def
test_install_requires_with_markers
(
self
,
tmpdir_cwd
,
env
):
self
.
_setup_script_with_requires
(
self
.
_setup_script_with_requires
(
"""install_requires=["barbazquux;python_version<'2'"],"""
)
"""install_requires=["barbazquux;python_version<'2'"],"""
)
...
@@ -115,14 +114,12 @@ class TestEggInfo(object):
...
@@ -115,14 +114,12 @@ class TestEggInfo(object):
requires_txt
).
read
().
split
(
'
\
n
'
)
requires_txt
).
read
().
split
(
'
\
n
'
)
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
@
pytest
.
mark
.
xfail
(
reason
=
"Functionality disabled; see #523"
)
def
test_setup_requires_with_markers
(
self
,
tmpdir_cwd
,
env
):
def
test_setup_requires_with_markers
(
self
,
tmpdir_cwd
,
env
):
self
.
_setup_script_with_requires
(
self
.
_setup_script_with_requires
(
"""setup_requires=["barbazquux;python_version<'2'"],"""
)
"""setup_requires=["barbazquux;python_version<'2'"],"""
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
)
self
.
_run_install_command
(
tmpdir_cwd
,
env
)
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
assert
glob
.
glob
(
os
.
path
.
join
(
env
.
paths
[
'lib'
],
'barbazquux*'
))
==
[]
@
pytest
.
mark
.
xfail
(
reason
=
"Functionality disabled; see #523"
)
def
test_tests_require_with_markers
(
self
,
tmpdir_cwd
,
env
):
def
test_tests_require_with_markers
(
self
,
tmpdir_cwd
,
env
):
self
.
_setup_script_with_requires
(
self
.
_setup_script_with_requires
(
"""tests_require=["barbazquux;python_version<'2'"],"""
)
"""tests_require=["barbazquux;python_version<'2'"],"""
)
...
...
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