Skip to content
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/6164.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pipenv only supports absolute python version. If the user specifies a Python version with inequality signs like >=3.12, <3.12 in the [requires] field, the code has been modified to explicitly express in an error log that absolute versioning must be used.
10 changes: 10 additions & 0 deletions pipenv/utils/virtualenv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import contextlib
import os
import re
import shutil
import sys
from pathlib import Path
Expand Down Expand Up @@ -237,6 +238,15 @@ def abort(msg=""):
# Find out which python is desired.
if not python:
python = project.required_python_version
if python:
range_pattern = r"^[<>]=?|!="
if re.search(range_pattern, python):
err.print(
f"[bold red]Error[/bold red]: Python version range specifier '[cyan]{python}[/cyan]' is not supported. "
"[yellow]Please use an absolute version number or specify the path to the Python executable on Pipfile.[/yellow]"
)
sys.exit(1)

if not python:
python = project.s.PIPENV_DEFAULT_PYTHON_VERSION
path_to_python = find_a_system_python(python)
Expand Down
58 changes: 58 additions & 0 deletions tests/integration/test_install_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,64 @@ def test_create_pipfile_requires_python_full_version(pipenv_instance_private_pyp
'python_version': python_version
}

@pytest.mark.basic
@pytest.mark.install
@pytest.mark.virtualenv
def test_install_with_pipfile_including_exact_python_version(pipenv_instance_pypi):
valid_version = f"{sys.version_info.major}.{sys.version_info.minor}"

with pipenv_instance_pypi() as p:
with open(p.pipfile_path, 'w') as f:
f.write(f"""
[[source]]
url = "https://test.pypi.org/simple"
verify_ssl = true
name = "testpypi"

[packages]
pytz = "*"

[requires]
python_version = "{valid_version}"
""")

c = p.pipenv("install")
assert c.returncode == 0
assert os.path.isfile(p.pipfile_path)
assert p.pipfile["requires"]["python_version"] == valid_version

c = p.pipenv("--rm")
assert c.returncode == 0

@pytest.mark.basic
@pytest.mark.install
@pytest.mark.virtualenv
def test_install_with_pipfile_including_invalid_python_version(pipenv_instance_pypi):
invalid_versions = [
f">={sys.version_info.major}.{sys.version_info.minor}",
f"<={sys.version_info.major}.{sys.version_info.minor}",
f">{sys.version_info.major}.{sys.version_info.minor}",
f"<{sys.version_info.major}.{sys.version_info.minor}",
]

with pipenv_instance_pypi() as p:
for version in invalid_versions:
with open(p.pipfile_path, 'w') as f:
f.write(f"""
[[source]]
url = "https://test.pypi.org/simple"
verify_ssl = true
name = "testpypi"

[packages]
pytz = "*"

[requires]
python_version = "{version}"
""")
c = p.pipenv("install")
assert c.returncode != 0


@pytest.mark.basic
@pytest.mark.install
Expand Down