From ebdf1ff8de76a2884d4698d81193630602c3cdca Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Sun, 12 Feb 2023 11:14:20 -0500 Subject: [PATCH] Flexibile argument specification when specifying multiple cateogires. (#5606) * Flexibile argument specification when specifying multiple categories. * fix lint * add test and news fragment. --- news/5570.bugfix.rst | 1 + pipenv/cli/command.py | 6 ++++-- pipenv/cli/options.py | 3 ++- tests/integration/test_install_categories.py | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 news/5570.bugfix.rst diff --git a/news/5570.bugfix.rst b/news/5570.bugfix.rst new file mode 100644 index 0000000000..5db7dc2419 --- /dev/null +++ b/news/5570.bugfix.rst @@ -0,0 +1 @@ +Fix ``--categories`` argument inconsistency between requirements command and install/sync by allowing comma seperated values or spaces. diff --git a/pipenv/cli/command.py b/pipenv/cli/command.py index 5eef271c7b..f0cbcc91e0 100644 --- a/pipenv/cli/command.py +++ b/pipenv/cli/command.py @@ -1,4 +1,5 @@ import os +import re import sys from pipenv import environments @@ -21,6 +22,7 @@ uninstall_options, verbose_option, ) +from pipenv.utils.dependencies import get_lockfile_section_using_pipfile_category from pipenv.utils.environment import load_dot_env from pipenv.utils.processes import subprocess_run from pipenv.vendor.click import ( @@ -779,11 +781,11 @@ def requirements( echo(" ".join([prefix, package_index["url"]])) deps = {} - categories_list = categories.split(",") if categories else [] + categories_list = re.split(r", *| ", categories) if categories else [] if categories_list: for category in categories_list: - category = category.strip() + category = get_lockfile_section_using_pipfile_category(category.strip()) deps.update(lockfile.get(category, {})) else: if dev or dev_only: diff --git a/pipenv/cli/options.py b/pipenv/cli/options.py index feba8e8a8e..e3fe51cfb5 100644 --- a/pipenv/cli/options.py +++ b/pipenv/cli/options.py @@ -1,4 +1,5 @@ import os +import re from pipenv.project import Project from pipenv.utils.internet import is_valid_url @@ -235,7 +236,7 @@ def categories_option(f): def callback(ctx, param, value): state = ctx.ensure_object(State) if value: - for opt in value.split(" "): + for opt in re.split(r", *| ", value): state.installstate.categories.append(opt) return value diff --git a/tests/integration/test_install_categories.py b/tests/integration/test_install_categories.py index b1a8864337..736f550d31 100644 --- a/tests/integration/test_install_categories.py +++ b/tests/integration/test_install_categories.py @@ -18,7 +18,8 @@ def test_basic_category_install(pipenv_instance_private_pypi): @pytest.mark.categories @pytest.mark.install -def test_multiple_category_install(pipenv_instance_private_pypi): +@pytest.mark.parametrize('categories', ["prereq other", "prereq, other"]) +def test_multiple_category_install(pipenv_instance_private_pypi, categories): with pipenv_instance_private_pypi() as p: c = p.pipenv('install six --categories="prereq other"') assert c.returncode == 0