-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
requirements command improvements, fixes issue 5755. (#5757)
* requirements command improvements, fixes issue 5755. * editable is not a pip arg * Apply suggestions from code review Co-authored-by: Michael Marino <[email protected]> * Update pipenv/routines/requirements.py Co-authored-by: Michael Marino <[email protected]> * fix test * add news fragment. --------- Co-authored-by: Michael Marino <[email protected]>
- Loading branch information
Showing
4 changed files
with
86 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix regression in ``requirements`` command that was causing package installs after upgrade to ``requirementslib==3.0.0``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import re | ||
import sys | ||
|
||
from pipenv.utils.dependencies import get_lockfile_section_using_pipfile_category | ||
from pipenv.vendor import click | ||
|
||
|
||
def requirements_from_deps(deps, include_hashes=True, include_markers=True): | ||
pip_packages = [] | ||
|
||
for package_name, package_info in deps.items(): | ||
# Handling git repositories | ||
if "git" in package_info: | ||
git = package_info["git"] | ||
ref = package_info.get("ref", "") | ||
extras = ( | ||
"[{}]".format(",".join(package_info.get("extras", []))) | ||
if "extras" in package_info | ||
else "" | ||
) | ||
pip_package = f"{package_name}{extras} @ git+{git}@{ref}" | ||
else: | ||
# Handling packages with hashes and markers | ||
version = package_info.get("version", "").replace("==", "") | ||
hashes = ( | ||
" --hash={}".format(" --hash=".join(package_info["hashes"])) | ||
if include_hashes and "hashes" in package_info | ||
else "" | ||
) | ||
markers = ( | ||
"; {}".format(package_info["markers"]) | ||
if include_markers and "markers" in package_info | ||
else "" | ||
) | ||
pip_package = f"{package_name}=={version}{hashes}{markers}" | ||
|
||
# Append to the list | ||
pip_packages.append(pip_package) | ||
|
||
# pip_packages contains the pip-installable lines | ||
return pip_packages | ||
|
||
|
||
def generate_requirements( | ||
project, | ||
dev=False, | ||
dev_only=False, | ||
include_hashes=False, | ||
include_markers=True, | ||
categories="", | ||
): | ||
lockfile = project.load_lockfile(expand_env_vars=False) | ||
|
||
for i, package_index in enumerate(lockfile["_meta"]["sources"]): | ||
prefix = "-i" if i == 0 else "--extra-index-url" | ||
click.echo(" ".join([prefix, package_index["url"]])) | ||
|
||
deps = {} | ||
categories_list = re.split(r", *| ", categories) if categories else [] | ||
|
||
if categories_list: | ||
for category in categories_list: | ||
category = get_lockfile_section_using_pipfile_category(category.strip()) | ||
deps.update(lockfile.get(category, {})) | ||
else: | ||
if dev or dev_only: | ||
deps.update(lockfile["develop"]) | ||
if not dev_only: | ||
deps.update(lockfile["default"]) | ||
|
||
pip_installable_lines = requirements_from_deps( | ||
deps, include_hashes=include_hashes, include_markers=include_markers | ||
) | ||
|
||
for line in pip_installable_lines: | ||
click.echo(line) | ||
|
||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters