Skip to content

Commit 0baff50

Browse files
authored
fix: allow no-marker option to work in pdm export command (#3152)
* fix: allow no-marker option to work in pdm export command Signed-off-by: Frost Ming <[email protected]> * add test Signed-off-by: Frost Ming <[email protected]> * add news Signed-off-by: Frost Ming <[email protected]> * improve the test Signed-off-by: Frost Ming <[email protected]>
1 parent cfa4913 commit 0baff50

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

news/3152.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Now when `--no-markers` is used, the exported requirements can only work on the current platform.

pdm.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies = [
2828
"python-dotenv>=0.15",
2929
"resolvelib>=1.0.1",
3030
"installer<0.8,>=0.7",
31-
"truststore; python_version >= \"3.10\"",
31+
"truststore>=0.9; python_version >= \"3.10\"",
3232
"tomli>=1.1.0; python_version < \"3.11\"",
3333
"importlib-resources>=5; python_version < \"3.9\"",
3434
"importlib-metadata>=3.6; python_version < \"3.10\"",

src/pdm/cli/commands/export.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def handle(self, project: Project, options: argparse.Namespace) -> None:
6868
options.hashes = False
6969
selection = GroupSelection.from_options(project, options)
7070
if options.markers is False:
71-
project.core.ui.deprecated("The --no-markers option is deprecated and has no effect.")
71+
project.core.ui.warn(
72+
"The --no-markers option is on, the exported requirements can only work on the current platform"
73+
)
7274
packages: Iterable[Requirement] | Iterable[Candidate]
7375
if options.pyproject:
7476
packages = [r for group in selection for r in project.get_dependencies(group)]
@@ -86,6 +88,7 @@ def handle(self, project: Project, options: argparse.Namespace) -> None:
8688
groups = set(selection)
8789
packages = []
8890
seen_extras: set[str] = set()
91+
this_spec = project.environment.spec
8992
for candidate in candidates:
9093
if groups.isdisjoint(candidate.req.groups):
9194
continue
@@ -97,6 +100,10 @@ def handle(self, project: Project, options: argparse.Namespace) -> None:
97100
continue
98101
elif candidate.req.extras:
99102
continue
103+
if not options.markers and candidate.req.marker:
104+
if not candidate.req.marker.matches(this_spec):
105+
continue
106+
candidate.req.marker = None
100107
packages.append(candidate) # type: ignore[arg-type]
101108

102109
content = FORMATS[options.format].export(project, packages, options)

tests/cli/test_others.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,20 @@ def test_show_update_hint(pdm, project, monkeypatch):
234234

235235
@pytest.mark.usefixtures("repository")
236236
def test_export_with_platform_markers(pdm, project):
237-
pdm(["add", "--no-sync", 'urllib3; sys_platform == "fake"'], obj=project, strict=True)
237+
pdm(
238+
["add", "--no-sync", 'urllib3; sys_platform == "fake"', 'idna; python_version >= "3.7"'],
239+
obj=project,
240+
strict=True,
241+
)
238242
result = pdm(["export", "--no-hashes"], obj=project, strict=True)
239-
assert 'urllib3==1.22; sys_platform == "fake"' in result.output.splitlines()
243+
result_lines = result.output.splitlines()
244+
assert 'urllib3==1.22; sys_platform == "fake"' in result_lines
245+
assert 'idna==2.7; python_version >= "3.7"' in result_lines
246+
247+
result = pdm(["export", "--no-hashes", "--no-markers"], obj=project, strict=True)
248+
result_lines = result.output.splitlines()
249+
assert not any(line.startswith("urllib3") for line in result_lines)
250+
assert "idna==2.7" in result_lines
240251

241252

242253
@pytest.mark.usefixtures("repository", "vcs")

0 commit comments

Comments
 (0)