Skip to content

Commit 6bc0d25

Browse files
authored
Fix for skip-lock installing wrong package version when pipfile entry is not a dict (#6289)
* Fix for skip-lock installing wrong package version when pipfile entry is not a dict * add test case x2
1 parent 94b0db6 commit 6bc0d25

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

news/6288.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes issue with --skip-lock not providing pip the proper package specifier when version was a string (issue did not impact dict with version key).

pipenv/routines/install.py

-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ def do_install_dependencies(
487487
install_req, markers, req_line = install_req_from_pipfile(
488488
req_name, pipfile_entry
489489
)
490-
req_line = f"{req_line}; {markers}" if markers else f"{req_line}"
491490
deps_list.append(
492491
(
493492
install_req,

pipenv/utils/dependencies.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,8 @@ def install_req_from_pipfile(name: str, pipfile: Dict[str, Any]) -> Tuple[Any, A
11521152
vcs = next(iter([vcs for vcs in VCS_LIST if pipfile.startswith(f"{vcs}+")]), None)
11531153
if vcs is not None:
11541154
_pipfile[vcs] = pipfile
1155+
else: # normal named requirement
1156+
_pipfile["version"] = pipfile
11551157

11561158
extras = _pipfile.get("extras", [])
11571159
extras_str = f"[{','.join(extras)}]" if extras else ""
@@ -1213,8 +1215,6 @@ def handle_non_vcs_requirement(
12131215
return file_path_from_pipfile(_pipfile["file"], _pipfile)
12141216
else:
12151217
version = get_version(_pipfile)
1216-
if version and not is_star(version) and COMPARE_OP.match(version) is None:
1217-
version = f"=={version}"
12181218
if is_star(version) or version == "==*":
12191219
version = ""
12201220

tests/integration/test_install_twists.py

+69
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,72 @@ def test_install_skip_lock(pipenv_instance_private_pypi):
351351
assert c.returncode == 0
352352
c = p.pipenv('run python -c "import six"')
353353
assert c.returncode == 0
354+
355+
356+
@pytest.mark.install
357+
@pytest.mark.skip_lock
358+
def test_skip_lock_installs_correct_version(pipenv_instance_pypi):
359+
"""Ensure --skip-lock installs the exact version specified in Pipfile."""
360+
with pipenv_instance_pypi() as p:
361+
with open(p.pipfile_path, "w") as f:
362+
contents = """
363+
[[source]]
364+
url = "https://pypi.org/simple"
365+
verify_ssl = true
366+
name = "pypi"
367+
368+
[packages]
369+
gunicorn = "==20.0.2"
370+
""".strip()
371+
f.write(contents)
372+
373+
# Install with --skip-lock
374+
c = p.pipenv("install --skip-lock")
375+
assert c.returncode == 0
376+
377+
# Verify installed version matches Pipfile specification
378+
c = p.pipenv("run pip freeze")
379+
assert c.returncode == 0
380+
381+
# Find gunicorn in pip freeze output
382+
packages = [line.strip() for line in c.stdout.split("\n")]
383+
gunicorn_line = next(line for line in packages if line.startswith("gunicorn"))
384+
385+
assert gunicorn_line == "gunicorn==20.0.2"
386+
387+
388+
@pytest.mark.install
389+
@pytest.mark.skip_lock
390+
def test_skip_lock_respects_markers(pipenv_instance_pypi):
391+
"""Ensure --skip-lock correctly handles packages with markers."""
392+
with pipenv_instance_pypi() as p:
393+
with open(p.pipfile_path, "w") as f:
394+
contents = """
395+
[[source]]
396+
url = "https://pypi.org/simple"
397+
verify_ssl = true
398+
name = "pypi"
399+
400+
[packages]
401+
# Use python version markers since they're platform-independent
402+
simplejson = {version = "==3.17.2", markers = "python_version < '4'"}
403+
urllib3 = {version = "==1.26.6", markers = "python_version < '2'"}
404+
""".strip()
405+
f.write(contents)
406+
407+
# Install with --skip-lock
408+
c = p.pipenv("install --skip-lock")
409+
assert c.returncode == 0
410+
411+
# Verify installed versions match markers
412+
c = p.pipenv("run pip freeze")
413+
assert c.returncode == 0
414+
packages = [line.strip() for line in c.stdout.split("\n")]
415+
416+
# simplejson should be installed (python_version < '4' is always True for Python 3.x)
417+
simplejson_line = next((line for line in packages if line.startswith("simplejson")), None)
418+
assert simplejson_line == "simplejson==3.17.2"
419+
420+
# urllib3 should not be installed (python_version < '2' is always False for Python 3.x)
421+
urllib3_line = next((line for line in packages if line.startswith("urllib3")), None)
422+
assert urllib3_line is None

0 commit comments

Comments
 (0)