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

fix: test against the latest findpython #1518

Merged
merged 1 commit into from
Nov 16, 2022
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/1516.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the test failure with the latest `findpython` installed.
8 changes: 4 additions & 4 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 5 additions & 11 deletions src/pdm/cli/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@
set_env_in_reg,
translate_groups,
)
from pdm.exceptions import (
InvalidPyVersion,
NoPythonVersion,
PdmUsageError,
ProjectError,
)
from pdm.exceptions import NoPythonVersion, PdmUsageError, ProjectError
from pdm.formats import FORMATS
from pdm.formats.base import array_of_inline_tables, make_array, make_inline_table
from pdm.models.backends import BuildBackend
Expand Down Expand Up @@ -579,8 +574,10 @@ def do_use(
python = python.strip()

def version_matcher(py_version: PythonInfo) -> bool:
return ignore_requires_python or project.python_requires.contains(
str(py_version.version), True
return (
ignore_requires_python
or py_version.valid
and project.python_requires.contains(str(py_version.version), True)
)

if not project.cache_dir.exists():
Expand Down Expand Up @@ -642,9 +639,6 @@ def version_matcher(py_version: PythonInfo) -> bool:
if python:
use_cache.set(python, selected_python.path.as_posix())

if not selected_python.valid:
path = str(selected_python.path)
raise InvalidPyVersion(f"Invalid Python interpreter: {path}")
if not save:
return selected_python
old_python = (
Expand Down
11 changes: 7 additions & 4 deletions src/pdm/models/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any

from findpython import PythonVersion
from packaging.version import Version
from packaging.version import InvalidVersion, Version

from pdm.compat import cached_property

Expand Down Expand Up @@ -72,6 +72,9 @@ def for_tag(self) -> str:

@property
def identifier(self) -> str:
if os.name == "nt" and self.is_32bit:
return f"{self.major}.{self.minor}-32"
return f"{self.major}.{self.minor}"
try:
if os.name == "nt" and self.is_32bit:
return f"{self.major}.{self.minor}-32"
return f"{self.major}.{self.minor}"
except InvalidVersion:
return "unknown"
4 changes: 2 additions & 2 deletions tests/cli/test_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

from pdm.cli import actions
from pdm.exceptions import InvalidPyVersion
from pdm.exceptions import NoPythonVersion
from pdm.models.caches import JSONFileCache


Expand Down Expand Up @@ -54,7 +54,7 @@ def test_use_invalid_wrapper_python(project):
shim_path = project.root.joinpath("python_shim.sh")
shim_path.write_text(wrapper_script)
shim_path.chmod(0o755)
with pytest.raises(InvalidPyVersion):
with pytest.raises(NoPythonVersion):
actions.do_use(project, shim_path.as_posix())


Expand Down