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 extras not being included for pypi packages in requirements command #5784

Merged
merged 4 commits into from
Jul 9, 2023
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/5784.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix regressions in the ``requirements`` command related to standard index extras and handling of local file requirements.
18 changes: 16 additions & 2 deletions pipenv/routines/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ def requirements_from_deps(deps, include_hashes=True, include_markers=True):
else ""
)
pip_package = f"{package_name}{extras} @ git+{git}@{ref}"
# Handling file-sourced packages
elif "file" in package_info or "path" in package_info:
file = package_info.get("file") or package_info.get("path")
extras = (
"[{}]".format(",".join(package_info.get("extras", [])))
if "extras" in package_info
else ""
)
pip_package = f"{file}{extras}"
else:
# Handling packages with hashes and markers
# Handling packages from standard pypi like indexes
version = package_info.get("version", "").replace("==", "")
hashes = (
" --hash={}".format(" --hash=".join(package_info["hashes"]))
Expand All @@ -32,7 +41,12 @@ def requirements_from_deps(deps, include_hashes=True, include_markers=True):
if include_markers and "markers" in package_info
else ""
)
pip_package = f"{package_name}=={version}{markers}{hashes}"
extras = (
"[{}]".format(",".join(package_info.get("extras", [])))
if "extras" in package_info
else ""
)
pip_package = f"{package_name}{extras}=={version}{markers}{hashes}"

# Append to the list
pip_packages.append(pip_package)
Expand Down
49 changes: 48 additions & 1 deletion tests/integration/test_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from pipenv.utils.shell import temp_environ

from pipenv.routines.requirements import requirements_from_deps

@pytest.mark.requirements
def test_requirements_generates_requirements_from_lockfile(pipenv_instance_pypi):
Expand Down Expand Up @@ -192,6 +192,7 @@ def test_requirements_markers_get_excluded(pipenv_instance_pypi):
assert c.returncode == 0
assert markers not in c.stdout


@pytest.mark.requirements
def test_requirements_hashes_get_included(pipenv_instance_pypi):
package, version, markers = "werkzeug", "==2.1.2", "python_version >= '3.7'"
Expand Down Expand Up @@ -220,6 +221,7 @@ def test_requirements_hashes_get_included(pipenv_instance_pypi):
assert c.returncode == 0
assert f'{package}{version}; {markers} --hash={first_hash} --hash={second_hash}' in c.stdout


def test_requirements_generates_requirements_from_lockfile_without_env_var_expansion(
pipenv_instance_pypi,
):
Expand Down Expand Up @@ -250,3 +252,48 @@ def test_requirements_generates_requirements_from_lockfile_without_env_var_expan
"-i https://${redacted_user}:${redacted_pwd}@private_source.org"
in c.stdout
)


@pytest.mark.requirements
@pytest.mark.parametrize(
"deps, include_hashes, include_markers, expected",
[
(
{
"django-storages": {
"version": "==1.12.3",
"extras": ["azure"]
}
},
True,
True,
["django-storages[azure]==1.12.3"]
),
(
{
"evotum-cripto": {
"file": "https://gitlab.com/eVotUM/Cripto-py/-/archive/develop/Cripto-py-develop.zip"
}
},
True,
True,
["https://gitlab.com/eVotUM/Cripto-py/-/archive/develop/Cripto-py-develop.zip"]
),
(
{
"pyjwt": {
"git": "https://github.com/jpadilla/pyjwt.git",
"ref": "7665aa625506a11bae50b56d3e04413a3dc6fdf8",
"extras": ["crypto"]
}
},
True,
True,
["pyjwt[crypto] @ git+https://github.com/jpadilla/pyjwt.git@7665aa625506a11bae50b56d3e04413a3dc6fdf8"]
)
]
)
def test_requirements_from_deps(deps, include_hashes, include_markers, expected):
result = requirements_from_deps(deps, include_hashes, include_markers)
assert result == expected

Loading