Skip to content

Commit

Permalink
Flexibile argument specification when specifying multiple cateogires. (
Browse files Browse the repository at this point in the history
…#5606)

* Flexibile argument specification when specifying multiple categories.

* fix lint

* add test and news fragment.
  • Loading branch information
matteius committed Feb 12, 2023
1 parent 3e35f95 commit ebdf1ff
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/5570.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``--categories`` argument inconsistency between requirements command and install/sync by allowing comma seperated values or spaces.
6 changes: 4 additions & 2 deletions pipenv/cli/command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import sys

from pipenv import environments
Expand All @@ -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 (
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion pipenv/cli/options.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re

from pipenv.project import Project
from pipenv.utils.internet import is_valid_url
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_install_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ebdf1ff

Please sign in to comment.