From 79f327a5063d287e38c4870660529d6e0204c397 Mon Sep 17 00:00:00 2001 From: John Maximilian <2e0byo@gmail.com> Date: Thu, 7 Mar 2024 12:53:35 +0000 Subject: [PATCH 1/4] test: all group exclusion cases. --- tests/cli/test_install.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/cli/test_install.py b/tests/cli/test_install.py index a26a906b9e..b0b1792567 100644 --- a/tests/cli/test_install.py +++ b/tests/cli/test_install.py @@ -314,22 +314,34 @@ def test_fix_package_type_and_update(fixture_project, pdm, working_set): assert "test-package-type-fixer" not in working_set -def test_install_all_with_excluded_groups(project, working_set, pdm): +exclusion_cases = [ + pytest.param(("-G", ":all", "--without", "tz,ssl"), id="-G :all --without tz,ssl"), + pytest.param(("-G", ":all", "--without", "tz", "--without", "ssl"), id="-G :all --without tz --without ssl"), + pytest.param(("--with", ":all", "--without", "tz,ssl"), id="--with all --without tz,ssl"), + pytest.param(("--with", ":all", "--without", "tz", "--without", "ssl"), id="--with all --without tz --without ssl"), + pytest.param(("--without", "tz", "--without", "ssl"), id="--without tz --without ssl"), + pytest.param(("--without", "tz,ssl"), id="--without tz,ssl"), +] + + +@pytest.mark.parametrize("args", exclusion_cases) +def test_install_all_with_excluded_groups(project, working_set, pdm, args): project.add_dependencies({"urllib3": parse_requirement("urllib3")}, "url") project.add_dependencies({"pytz": parse_requirement("pytz")}, "tz") project.add_dependencies({"pyopenssl": parse_requirement("pyopenssl")}, "ssl") - pdm(["install", "-G", ":all", "--without", "tz,ssl"], obj=project, strict=True) + pdm(["install", *args], obj=project, strict=True) assert "urllib3" in working_set assert "pytz" not in working_set assert "pyopenssl" not in working_set -def test_sync_all_with_excluded_groups(project, working_set, pdm): +@pytest.mark.parametrize("args", exclusion_cases) +def test_sync_all_with_excluded_groups(project, working_set, pdm, args): project.add_dependencies({"urllib3": parse_requirement("urllib3")}, "url") project.add_dependencies({"pytz": parse_requirement("pytz")}, "tz") project.add_dependencies({"pyopenssl": parse_requirement("pyopenssl")}, "ssl") pdm(["lock", "-G:all"], obj=project, strict=True) - pdm(["sync", "-G", ":all", "--without", "url,tz"], obj=project, strict=True) - assert "urllib3" not in working_set + pdm(["sync", *args], obj=project, strict=True) + assert "urllib3" in working_set assert "pytz" not in working_set - assert "pyopenssl" in working_set + assert "pyopenssl" not in working_set From 3e59ac2629e7a20946686de6a24ad58ddfc894d2 Mon Sep 17 00:00:00 2001 From: John Maximilian <2e0byo@gmail.com> Date: Thu, 7 Mar 2024 13:08:26 +0000 Subject: [PATCH 2/4] fix: make --without imply --with :all unless explicit groups given. --- src/pdm/cli/filters.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pdm/cli/filters.py b/src/pdm/cli/filters.py index 0fdaf23502..7382eb0ad1 100644 --- a/src/pdm/cli/filters.py +++ b/src/pdm/cli/filters.py @@ -32,6 +32,8 @@ def __init__( @classmethod def from_options(cls, project: Project, options: argparse.Namespace) -> GroupSelection: + if getattr(options, "excluded_groups", None) and not options.groups: + options.groups = [":all"] if "group" in options: return cls(project, group=options.group, dev=options.dev) return cls( From 08c7600c853b80914a70e1fc94f450113e001771 Mon Sep 17 00:00:00 2001 From: John Maximilian <2e0byo@gmail.com> Date: Thu, 7 Mar 2024 13:14:37 +0000 Subject: [PATCH 3/4] chore: news. --- news/2670.bugfix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/2670.bugfix.md diff --git a/news/2670.bugfix.md b/news/2670.bugfix.md new file mode 100644 index 0000000000..035e594729 --- /dev/null +++ b/news/2670.bugfix.md @@ -0,0 +1 @@ +Made --without imply --with :all. From e16f9394eb0a43ac65252367a9dd30a6be91ef15 Mon Sep 17 00:00:00 2001 From: John Maximilian <2e0byo@gmail.com> Date: Thu, 7 Mar 2024 16:21:50 +0000 Subject: [PATCH 4/4] fix: if --prod/--dev parsed, don't imply --with all. --- src/pdm/cli/filters.py | 2 +- tests/cli/test_install.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/pdm/cli/filters.py b/src/pdm/cli/filters.py index 7382eb0ad1..8c8f31dc94 100644 --- a/src/pdm/cli/filters.py +++ b/src/pdm/cli/filters.py @@ -32,7 +32,7 @@ def __init__( @classmethod def from_options(cls, project: Project, options: argparse.Namespace) -> GroupSelection: - if getattr(options, "excluded_groups", None) and not options.groups: + if getattr(options, "excluded_groups", None) and not options.groups and options.dev is None: options.groups = [":all"] if "group" in options: return cls(project, group=options.group, dev=options.dev) diff --git a/tests/cli/test_install.py b/tests/cli/test_install.py index b0b1792567..4686fc9796 100644 --- a/tests/cli/test_install.py +++ b/tests/cli/test_install.py @@ -345,3 +345,23 @@ def test_sync_all_with_excluded_groups(project, working_set, pdm, args): assert "urllib3" in working_set assert "pytz" not in working_set assert "pyopenssl" not in working_set + + +def test_excluded_groups_ignored_if_prod_passed(project, working_set, pdm): + project.add_dependencies({"urllib3": parse_requirement("urllib3")}, "url") + project.add_dependencies({"pytz": parse_requirement("pytz")}, "tz") + project.add_dependencies({"pyopenssl": parse_requirement("pyopenssl")}, "ssl") + pdm(["install", "--prod", "--without", "ssl"], obj=project, strict=True) + assert "urllib3" not in working_set + assert "pytz" not in working_set + assert "pyopenssl" not in working_set + + +def test_excluded_groups_ignored_if_dev_passed(project, working_set, pdm): + project.add_dependencies({"urllib3": parse_requirement("urllib3")}, "url") + project.add_dependencies({"pytz": parse_requirement("pytz")}, "tz") + project.add_dependencies({"pyopenssl": parse_requirement("pyopenssl")}, "ssl") + pdm(["install", "--dev", "--without", "ssl"], obj=project, strict=True) + assert "urllib3" not in working_set + assert "pytz" not in working_set + assert "pyopenssl" not in working_set