Skip to content

Commit 5d49b39

Browse files
authoredDec 15, 2023
fix: failure to handle extra if env is not empty but does not have extra (pdm-project#1)
* build(pdm): add test settings and expose test script * fix(markers): ensure `SingleMarker` handling works when environment does not have `extra` but is not empty
1 parent 088c53a commit 5d49b39

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed
 

‎pyproject.toml

+10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ dev = [
5858
"pytest>=7.4.3",
5959
]
6060

61+
[tool.pdm.scripts]
62+
test = "pytest"
63+
64+
[tool.pytest.ini_options]
65+
addopts = "-ra"
66+
testpaths = [
67+
"src/",
68+
"tests/",
69+
]
70+
6171
[tool.pyright]
6272
venvPath = "."
6373
venv = ".venv"

‎src/dep_logic/markers/single.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def only(self, *marker_names: str) -> BaseMarker:
4646

4747
def evaluate(self, environment: dict[str, str] | None = None) -> bool:
4848
pkg_marker = _Marker(str(self))
49-
if self.name != "extra" or not environment:
49+
if self.name != "extra" or not environment or "extra" not in environment:
5050
return pkg_marker.evaluate(environment)
5151
extras = [extra] if isinstance(extra := environment["extra"], str) else extra
5252
assert isinstance(self, MarkerExpression)

‎tests/marker/test_evaluation.py

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def test_evaluates(
107107
# single extra
108108
("extra != 'security'", {"extra": "quux"}, True),
109109
("extra != 'security'", {"extra": "security"}, False),
110+
("extra != 'security'", {}, True),
111+
("extra != 'security'", {"platform_machine": "x86_64"}, True),
110112
# normalization
111113
("extra == 'Security.1'", {"extra": "security-1"}, True),
112114
("extra == 'a'", {}, False),

0 commit comments

Comments
 (0)
Please sign in to comment.