Skip to content

Commit

Permalink
feat: add implementation property
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed Mar 25, 2024
1 parent 8e1837d commit 98f138a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
22 changes: 19 additions & 3 deletions pdm.lock

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

5 changes: 4 additions & 1 deletion src/findpython/providers/winreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import typing as t
from pathlib import Path

from packaging.version import Version

from findpython.providers.base import BaseProvider
from findpython.python import PythonVersion
from findpython.utils import WINDOWS
Expand Down Expand Up @@ -33,9 +35,10 @@ def find_pythons(self) -> t.Iterable[PythonVersion]:
except AttributeError:
continue
if path.exists():
version = getattr(version.info, "version", None)
py_ver = self.version_maker(
path,
None,
Version(version) if version else None,
getattr(version.info, "sys_architecture", SYS_ARCHITECTURE),
path,
)
Expand Down
18 changes: 16 additions & 2 deletions src/findpython/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def real_path(self) -> Path:
except OSError:
return self.executable

@property
def implementation(self) -> str:
"""Return the implementation of the python."""
script = "import platform; print(platform.python_implementation())"
return _run_script(str(self.executable), script).strip()

@property
def name(self) -> str:
"""Return the name of the python."""
Expand Down Expand Up @@ -166,13 +172,21 @@ def __hash__(self) -> int:
return hash(self.executable)

def __repr__(self) -> str:
attrs = ("executable", "version", "architecture", "major", "minor", "patch")
attrs = (
"executable",
"version",
"architecture",
"implementation",
"major",
"minor",
"patch",
)
return "<PythonVersion {}>".format(
", ".join(f"{attr}={getattr(self, attr)!r}" for attr in attrs)
)

def __str__(self) -> str:
return f"{self.name} {self.version} @ {self.executable}"
return f"{self.implementation:>9}@{self.version}: {self.executable}"

def _get_version(self) -> Version:
"""Get the version of the python."""
Expand Down

0 comments on commit 98f138a

Please sign in to comment.