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/3862.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip `requires-python` when a Pipfile `[requires]` table has no python version, instead of writing `>=None`.
6 changes: 5 additions & 1 deletion src/pdm/formats/pipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ def convert(project: Project, filename: PathLike, options: Namespace | None) ->
if "pipenv" in data and "allow_prereleases" in data["pipenv"]:
settings.setdefault("resolution", {})["allow-prereleases"] = data["pipenv"]["allow_prereleases"]
if "requires" in data:
# `[requires]` may carry only other markers, e.g. `platform_system`. Writing
# the missing version out anyway produced `requires-python = ">=None"`, which
# is not a valid specifier and breaks the generated pyproject.toml.
python_version = data["requires"].get("python_full_version") or data["requires"].get("python_version")
result["requires-python"] = f">={python_version}"
if python_version:
result["requires-python"] = f">={python_version}"
if "source" in data:
settings["source"] = data["source"]
result["dependencies"] = make_array( # type: ignore[assignment]
Expand Down
16 changes: 16 additions & 0 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ def test_convert_pipfile(project):
assert settings["source"][0]["url"] == "https://pypi.python.org/simple"


@pytest.mark.parametrize(
"requires",
[
"", # an empty [requires] table
'platform_system = "Linux"\n', # only non-python markers
],
)
def test_convert_pipfile_requires_without_python(project, requires):
"""`[requires]` without a python key used to emit `requires-python = ">=None"`."""
pipfile_path = project.root / "Pipfile"
pipfile_path.write_text(f"[requires]\n{requires}", encoding="utf-8")
result, _ = pipfile.convert(project, pipfile_path, None)

assert "requires-python" not in result


@pytest.mark.parametrize("is_dev", [True, False])
def test_convert_requirements_file(project, is_dev):
golden_file = FIXTURES / "requirements.txt"
Expand Down
Loading