mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
add category cmd line option
This commit is contained in:
+11
-6
@@ -1,3 +1,4 @@
|
||||
from gc import is_finalized
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -85,7 +86,7 @@ def cli(
|
||||
|
||||
load_dot_env(state.project, quiet=state.quiet)
|
||||
|
||||
from ..core import (
|
||||
from pipenv.core import (
|
||||
cleanup_virtualenv,
|
||||
do_clear,
|
||||
do_py,
|
||||
@@ -740,8 +741,9 @@ def verify(state):
|
||||
)
|
||||
@option("--hash", is_flag=True, default=False, help="Add package hashes.")
|
||||
@option("--exclude-markers", is_flag=True, default=False, help="Exclude markers.")
|
||||
@option("--category", is_flag=False, default='', help="Only add requirement of the specified category.")
|
||||
@pass_state
|
||||
def requirements(state, dev=False, dev_only=False, hash=False, exclude_markers=False):
|
||||
def requirements(state, dev=False, dev_only=False, hash=False, exclude_markers=False, category=''):
|
||||
|
||||
from pipenv.utils.dependencies import convert_deps_to_pip
|
||||
|
||||
@@ -753,10 +755,13 @@ def requirements(state, dev=False, dev_only=False, hash=False, exclude_markers=F
|
||||
|
||||
deps = {}
|
||||
|
||||
if dev or dev_only:
|
||||
deps.update(lockfile["develop"])
|
||||
if not dev_only:
|
||||
deps.update(lockfile["default"])
|
||||
if category:
|
||||
deps.update(lockfile.get(category, {}))
|
||||
else:
|
||||
if dev or dev_only:
|
||||
deps.update(lockfile["develop"])
|
||||
if not dev_only:
|
||||
deps.update(lockfile["default"])
|
||||
|
||||
pip_deps = convert_deps_to_pip(
|
||||
deps,
|
||||
|
||||
@@ -72,6 +72,41 @@ def test_requirements_generates_requirements_from_lockfile_multiple_sources(pipe
|
||||
assert '--extra-index-url https://some_other_source.org' in c.stdout
|
||||
|
||||
|
||||
@pytest.mark.requirements
|
||||
def test_requirements_generates_requirements_from_lockfile_from_a_category(pipenv_instance_private_pypi):
|
||||
with pipenv_instance_private_pypi(chdir=True) as p:
|
||||
packages = ('six', '1.12.0')
|
||||
dev_packages = ('itsdangerous', '1.1.0')
|
||||
test_packages = ('pytest', '7.1.3')
|
||||
with open(p.pipfile_path, 'w') as f:
|
||||
contents = f"""
|
||||
[[source]]
|
||||
name = "pypi"
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
[packages]
|
||||
{packages[0]}= "=={packages[1]}"
|
||||
[dev-packages]
|
||||
{dev_packages[0]}= "=={dev_packages[1]}"
|
||||
[test-packages]
|
||||
{test_packages[0]}= "=={test_packages[1]}"
|
||||
""".strip()
|
||||
f.write(contents)
|
||||
l = p.pipenv('lock')
|
||||
assert l.returncode == 0
|
||||
|
||||
c = p.pipenv('requirements --dev-only')
|
||||
assert c.returncode == 0
|
||||
assert f'{packages[0]}=={packages[1]}' not in c.stdout
|
||||
assert f'{test_packages[0]}=={test_packages[1]}' not in c.stdout
|
||||
assert f'{dev_packages[0]}=={dev_packages[1]}' in c.stdout
|
||||
|
||||
d = p.pipenv('requirements --category test')
|
||||
assert d.returncode == 0
|
||||
assert f'{packages[0]}=={packages[1]}' not in d.stdout
|
||||
assert f'{dev_packages[0]}=={dev_packages[1]}' not in c.stdout
|
||||
assert f'{test_packages[0]}=={test_packages[1]}' in d.stdout
|
||||
|
||||
@pytest.mark.requirements
|
||||
def test_requirements_with_git_requirements(pipenv_instance_pypi):
|
||||
req_name, req_hash = 'example-repo', 'cc858e89f19bc0dbd70983f86b811ab625dc9292'
|
||||
|
||||
Reference in New Issue
Block a user