Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/group exclusion #2670

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2670.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Made --without imply --with :all.
2 changes: 2 additions & 0 deletions src/pdm/cli/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 and options.dev is None:
options.groups = [":all"]
if "group" in options:
return cls(project, group=options.group, dev=options.dev)
return cls(
Expand Down
42 changes: 37 additions & 5 deletions tests/cli/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,22 +314,54 @@ 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)
pdm(["sync", *args], obj=project, strict=True)
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" 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
Loading