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

Ensure version contains an operator when defined #5765

Merged
merged 3 commits into from
Jul 4, 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/5765.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes regression on Pipfile requirements syntax. Ensure default operator is provided to requirement lib to avoid crash.
6 changes: 5 additions & 1 deletion pipenv/vendor/requirementslib/models/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from pipenv.patched.pip._internal.req.req_install import InstallRequirement
from pipenv.patched.pip._internal.utils.temp_dir import global_tempdir_manager
from pipenv.patched.pip._internal.utils.urls import path_to_url, url_to_path
from pipenv.patched.pip._vendor.distlib.util import cached_property
from pipenv.patched.pip._vendor.distlib.util import cached_property, COMPARE_OP
from pipenv.patched.pip._vendor.packaging.markers import Marker
from pipenv.patched.pip._vendor.packaging.requirements import Requirement as PackagingRequirement
from pipenv.patched.pip._vendor.packaging.specifiers import (
Expand Down Expand Up @@ -2544,6 +2544,10 @@ def from_pipfile(cls, name, pipfile):
if hasattr(pipfile, "keys"):
_pipfile = dict(pipfile).copy()
_pipfile["version"] = get_version(pipfile)

# We ensure version contains an operator. Default to equals (==)
if _pipfile["version"] and COMPARE_OP.match(_pipfile["version"]) is None:
_pipfile["version"] = "=={}".format(_pipfile["version"])
vcs = next(iter([vcs for vcs in VCS_LIST if vcs in _pipfile]), None)
if vcs:
_pipfile["vcs"] = vcs
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/test_install_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ def test_install_without_dev(pipenv_instance_private_pypi):
assert c.returncode == 0


@pytest.mark.basic
@pytest.mark.install
def test_install_with_version_req_default_operator(pipenv_instance_pypi):
"""Ensure that running `pipenv install` work when spec is package = "X.Y.Z". """
with pipenv_instance_pypi(chdir=True) as p:
with open(p.pipfile_path, "w") as f:
contents = """
[packages]
fastapi = "0.95.0"
""".strip()
f.write(contents)
c = p.pipenv("install")
assert c.returncode == 0
assert "fastapi" in p.pipfile["packages"]


@pytest.mark.basic
@pytest.mark.install
def test_install_without_dev_section(pipenv_instance_pypi):
Expand Down
Loading