Skip to content

Commit 98f138a

Browse files
committed
feat: add implementation property
Signed-off-by: Frost Ming <me@frostming.com>
1 parent 8e1837d commit 98f138a

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

pdm.lock

Lines changed: 19 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/findpython/providers/winreg.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import typing as t
55
from pathlib import Path
66

7+
from packaging.version import Version
8+
79
from findpython.providers.base import BaseProvider
810
from findpython.python import PythonVersion
911
from findpython.utils import WINDOWS
@@ -33,9 +35,10 @@ def find_pythons(self) -> t.Iterable[PythonVersion]:
3335
except AttributeError:
3436
continue
3537
if path.exists():
38+
version = getattr(version.info, "version", None)
3639
py_ver = self.version_maker(
3740
path,
38-
None,
41+
Version(version) if version else None,
3942
getattr(version.info, "sys_architecture", SYS_ARCHITECTURE),
4043
path,
4144
)

src/findpython/python.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ def real_path(self) -> Path:
6363
except OSError:
6464
return self.executable
6565

66+
@property
67+
def implementation(self) -> str:
68+
"""Return the implementation of the python."""
69+
script = "import platform; print(platform.python_implementation())"
70+
return _run_script(str(self.executable), script).strip()
71+
6672
@property
6773
def name(self) -> str:
6874
"""Return the name of the python."""
@@ -166,13 +172,21 @@ def __hash__(self) -> int:
166172
return hash(self.executable)
167173

168174
def __repr__(self) -> str:
169-
attrs = ("executable", "version", "architecture", "major", "minor", "patch")
175+
attrs = (
176+
"executable",
177+
"version",
178+
"architecture",
179+
"implementation",
180+
"major",
181+
"minor",
182+
"patch",
183+
)
170184
return "<PythonVersion {}>".format(
171185
", ".join(f"{attr}={getattr(self, attr)!r}" for attr in attrs)
172186
)
173187

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

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

0 commit comments

Comments
 (0)