Flexibile argument specification when specifying multiple cateogires. (#5606)

* Flexibile argument specification when specifying multiple categories.

* fix lint

* add test and news fragment.
This commit is contained in:
Matt Davis
2023-02-12 11:14:20 -05:00
committed by GitHub
parent 3e35f95f04
commit ebdf1ff8de
4 changed files with 9 additions and 4 deletions
+1
View File
@@ -0,0 +1 @@
Fix ``--categories`` argument inconsistency between requirements command and install/sync by allowing comma seperated values or spaces.
+4 -2
View File
@@ -1,4 +1,5 @@
import os
import re
import sys
from pipenv import environments
@@ -21,6 +22,7 @@ from pipenv.cli.options import (
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:
+2 -1
View File
@@ -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
+2 -1
View File
@@ -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