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 cda2a0a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
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
1 change: 1 addition & 0 deletions packaging/markers.py
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
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 cda2a0a

Please sign in to comment.