From 0baff50c7c24559f2863e2a3fb513e1e431285ff Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Tue, 10 Sep 2024 15:41:16 +0800 Subject: [PATCH] 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 * add test Signed-off-by: Frost Ming * add news Signed-off-by: Frost Ming * improve the test Signed-off-by: Frost Ming --- news/3152.bugfix.md | 1 + pdm.lock | 10 +++++----- pyproject.toml | 2 +- src/pdm/cli/commands/export.py | 9 ++++++++- tests/cli/test_others.py | 15 +++++++++++++-- 5 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 news/3152.bugfix.md diff --git a/news/3152.bugfix.md b/news/3152.bugfix.md new file mode 100644 index 0000000000..159b3f149e --- /dev/null +++ b/news/3152.bugfix.md @@ -0,0 +1 @@ +Now when `--no-markers` is used, the exported requirements can only work on the current platform. diff --git a/pdm.lock b/pdm.lock index 6dc62015c2..e7f787732d 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "all", "cookiecutter", "copier", "doc", "keyring", "pytest", "template", "test", "tox", "workflow"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:ebd43a389ae69bf0178c67d859dc2de063316e6d9727265153393563f93ad317" +content_hash = "sha256:bd8cd44205f546193ad7c31fd24ab10f181d68938d1e6149feaf908a2890fa7a" [[metadata.targets]] requires_python = ">=3.8" @@ -2120,14 +2120,14 @@ files = [ [[package]] name = "truststore" -version = "0.8.0" -requires_python = ">= 3.10" +version = "0.9.2" +requires_python = ">=3.10" summary = "Verify certificates using native system trust stores" groups = ["default"] marker = "python_version >= \"3.10\"" files = [ - {file = "truststore-0.8.0-py3-none-any.whl", hash = "sha256:e37a5642ae9fc48caa8f120b6283d77225d600d224965a672c9e8ef49ce4bb4c"}, - {file = "truststore-0.8.0.tar.gz", hash = "sha256:dc70da89634944a579bfeec70a7a4523c53ffdb3cf52d1bb4a431fda278ddb96"}, + {file = "truststore-0.9.2-py3-none-any.whl", hash = "sha256:04559916f8810cc1a5ecc41f215eddc988746067b754fc0995da7a2ceaf54735"}, + {file = "truststore-0.9.2.tar.gz", hash = "sha256:a1dee0d0575ff22d2875476343783a5d64575419974e228f3248772613c3d993"}, ] [[package]] diff --git a/pyproject.toml b/pyproject.toml index dcc98ee50e..5761376cf6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ dependencies = [ "python-dotenv>=0.15", "resolvelib>=1.0.1", "installer<0.8,>=0.7", - "truststore; python_version >= \"3.10\"", + "truststore>=0.9; python_version >= \"3.10\"", "tomli>=1.1.0; python_version < \"3.11\"", "importlib-resources>=5; python_version < \"3.9\"", "importlib-metadata>=3.6; python_version < \"3.10\"", diff --git a/src/pdm/cli/commands/export.py b/src/pdm/cli/commands/export.py index 6959ab8bc3..f3e53806f1 100644 --- a/src/pdm/cli/commands/export.py +++ b/src/pdm/cli/commands/export.py @@ -68,7 +68,9 @@ def handle(self, project: Project, options: argparse.Namespace) -> None: options.hashes = False selection = GroupSelection.from_options(project, options) if options.markers is False: - project.core.ui.deprecated("The --no-markers option is deprecated and has no effect.") + project.core.ui.warn( + "The --no-markers option is on, the exported requirements can only work on the current platform" + ) packages: Iterable[Requirement] | Iterable[Candidate] if options.pyproject: 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: groups = set(selection) packages = [] seen_extras: set[str] = set() + this_spec = project.environment.spec for candidate in candidates: if groups.isdisjoint(candidate.req.groups): continue @@ -97,6 +100,10 @@ def handle(self, project: Project, options: argparse.Namespace) -> None: continue elif candidate.req.extras: continue + if not options.markers and candidate.req.marker: + if not candidate.req.marker.matches(this_spec): + continue + candidate.req.marker = None packages.append(candidate) # type: ignore[arg-type] content = FORMATS[options.format].export(project, packages, options) diff --git a/tests/cli/test_others.py b/tests/cli/test_others.py index 4bf1aa5d6e..14bfa47bd1 100644 --- a/tests/cli/test_others.py +++ b/tests/cli/test_others.py @@ -234,9 +234,20 @@ def test_show_update_hint(pdm, project, monkeypatch): @pytest.mark.usefixtures("repository") def test_export_with_platform_markers(pdm, project): - pdm(["add", "--no-sync", 'urllib3; sys_platform == "fake"'], obj=project, strict=True) + pdm( + ["add", "--no-sync", 'urllib3; sys_platform == "fake"', 'idna; python_version >= "3.7"'], + obj=project, + strict=True, + ) result = pdm(["export", "--no-hashes"], obj=project, strict=True) - assert 'urllib3==1.22; sys_platform == "fake"' in result.output.splitlines() + result_lines = result.output.splitlines() + assert 'urllib3==1.22; sys_platform == "fake"' in result_lines + assert 'idna==2.7; python_version >= "3.7"' in result_lines + + result = pdm(["export", "--no-hashes", "--no-markers"], obj=project, strict=True) + result_lines = result.output.splitlines() + assert not any(line.startswith("urllib3") for line in result_lines) + assert "idna==2.7" in result_lines @pytest.mark.usefixtures("repository", "vcs")