Skip to content

Commit

Permalink
Evaluate markers under environment with no extra
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMino committed May 18, 2022
1 parent 6da5d33 commit b94b8e7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Changelog
*unreleased*
~~~~~~~~~~~~

No unreleased changes.
* ``Marker.evaluate`` will now assume evaluation environment with empty ``extra``.
Evaluating markers like ``"extra == 'xyz'"`` without passing any extra in the
``environment`` will no longer raise an exception.

21.3 - 2021-11-17
~~~~~~~~~~~~~~~~~
Expand Down
11 changes: 0 additions & 11 deletions docs/markers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ Usage
>>> # Markers can be also used with extras, to pull in dependencies if
>>> # a certain extra is being installed
>>> extra = Marker('extra == "bar"')
>>> # Evaluating an extra marker with no environment is an error
>>> try:
... extra.evaluate()
... except UndefinedEnvironmentName:
... pass
>>> extra_environment = {'extra': ''}
>>> extra.evaluate(environment=extra_environment)
False
>>> extra_environment['extra'] = 'bar'
>>> extra.evaluate(environment=extra_environment)
True
>>> # You can do simple comparisons between marker objects:
>>> Marker("python_version > '3.6'") == Marker("python_version > '3.6'")
True
Expand Down
1 change: 1 addition & 0 deletions packaging/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def default_environment() -> Dict[str, str]:
iver = format_full_version(sys.implementation.version)
implementation_name = sys.implementation.name
return {
"extra": "",
"implementation_name": implementation_name,
"implementation_version": iver,
"os_name": os.name,
Expand Down
9 changes: 3 additions & 6 deletions tests/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Marker,
Node,
UndefinedComparison,
UndefinedEnvironmentName,
default_environment,
format_full_version,
)
Expand Down Expand Up @@ -110,6 +109,7 @@ def test_matches_expected(self):
)

assert environment == {
"extra": "",
"implementation_name": sys.implementation.name,
"implementation_version": iver,
"os_name": os.name,
Expand Down Expand Up @@ -253,11 +253,8 @@ def test_compare_markers_to_other_objects(self):
# Markers should not be comparable to other kinds of objects.
assert Marker("os_name == 'nt'") != "os_name == 'nt'"

def test_extra_with_no_extra_in_environment(self):
# We can't evaluate an extra if no extra is passed into the environment
m = Marker("extra == 'security'")
with pytest.raises(UndefinedEnvironmentName):
m.evaluate()
def test_environment_assumes_empty_extra(self):
assert Marker('extra == "im_valid"').evaluate() is False

@pytest.mark.parametrize(
("marker_string", "environment", "expected"),
Expand Down

0 comments on commit b94b8e7

Please sign in to comment.