Skip to content

Commit ea82bae

Browse files
authored
Fix extras not being included for pypi packages in requirements command (#5784)
* Fix extras not being included for pypi packages in requirements command * fix for issue with requirements command not handling file based requirements. * add news fragment
1 parent 374b706 commit ea82bae

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

news/5784.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix regressions in the ``requirements`` command related to standard index extras and handling of local file requirements.

pipenv/routines/requirements.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,17 @@ def requirements_from_deps(deps, include_hashes=True, include_markers=True):
1919
else ""
2020
)
2121
pip_package = f"{package_name}{extras} @ git+{git}@{ref}"
22+
# Handling file-sourced packages
23+
elif "file" in package_info or "path" in package_info:
24+
file = package_info.get("file") or package_info.get("path")
25+
extras = (
26+
"[{}]".format(",".join(package_info.get("extras", [])))
27+
if "extras" in package_info
28+
else ""
29+
)
30+
pip_package = f"{file}{extras}"
2231
else:
23-
# Handling packages with hashes and markers
32+
# Handling packages from standard pypi like indexes
2433
version = package_info.get("version", "").replace("==", "")
2534
hashes = (
2635
" --hash={}".format(" --hash=".join(package_info["hashes"]))
@@ -32,7 +41,12 @@ def requirements_from_deps(deps, include_hashes=True, include_markers=True):
3241
if include_markers and "markers" in package_info
3342
else ""
3443
)
35-
pip_package = f"{package_name}=={version}{markers}{hashes}"
44+
extras = (
45+
"[{}]".format(",".join(package_info.get("extras", [])))
46+
if "extras" in package_info
47+
else ""
48+
)
49+
pip_package = f"{package_name}{extras}=={version}{markers}{hashes}"
3650

3751
# Append to the list
3852
pip_packages.append(pip_package)

tests/integration/test_requirements.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from pipenv.utils.shell import temp_environ
6-
6+
from pipenv.routines.requirements import requirements_from_deps
77

88
@pytest.mark.requirements
99
def test_requirements_generates_requirements_from_lockfile(pipenv_instance_pypi):
@@ -192,6 +192,7 @@ def test_requirements_markers_get_excluded(pipenv_instance_pypi):
192192
assert c.returncode == 0
193193
assert markers not in c.stdout
194194

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

224+
223225
def test_requirements_generates_requirements_from_lockfile_without_env_var_expansion(
224226
pipenv_instance_pypi,
225227
):
@@ -250,3 +252,48 @@ def test_requirements_generates_requirements_from_lockfile_without_env_var_expan
250252
"-i https://${redacted_user}:${redacted_pwd}@private_source.org"
251253
in c.stdout
252254
)
255+
256+
257+
@pytest.mark.requirements
258+
@pytest.mark.parametrize(
259+
"deps, include_hashes, include_markers, expected",
260+
[
261+
(
262+
{
263+
"django-storages": {
264+
"version": "==1.12.3",
265+
"extras": ["azure"]
266+
}
267+
},
268+
True,
269+
True,
270+
["django-storages[azure]==1.12.3"]
271+
),
272+
(
273+
{
274+
"evotum-cripto": {
275+
"file": "https://gitlab.com/eVotUM/Cripto-py/-/archive/develop/Cripto-py-develop.zip"
276+
}
277+
},
278+
True,
279+
True,
280+
["https://gitlab.com/eVotUM/Cripto-py/-/archive/develop/Cripto-py-develop.zip"]
281+
),
282+
(
283+
{
284+
"pyjwt": {
285+
"git": "https://github.com/jpadilla/pyjwt.git",
286+
"ref": "7665aa625506a11bae50b56d3e04413a3dc6fdf8",
287+
"extras": ["crypto"]
288+
}
289+
},
290+
True,
291+
True,
292+
["pyjwt[crypto] @ git+https://github.com/jpadilla/pyjwt.git@7665aa625506a11bae50b56d3e04413a3dc6fdf8"]
293+
)
294+
]
295+
)
296+
def test_requirements_from_deps(deps, include_hashes, include_markers, expected):
297+
result = requirements_from_deps(deps, include_hashes, include_markers)
298+
assert result == expected
299+

0 commit comments

Comments
 (0)