From 98f138a124aa388f82def1a64b2f006ad2b35842 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Mon, 25 Mar 2024 17:29:28 +0800 Subject: [PATCH] feat: add implementation property Signed-off-by: Frost Ming --- pdm.lock | 22 +++++++++++++++++++--- src/findpython/providers/winreg.py | 5 ++++- src/findpython/python.py | 18 ++++++++++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/pdm.lock b/pdm.lock index 5f32664..06d8b86 100644 --- a/pdm.lock +++ b/pdm.lock @@ -3,9 +3,8 @@ [metadata] groups = ["default", "tests"] -cross_platform = true -static_urls = false -lock_version = "4.3" +strategy = ["cross_platform", "inherit_metadata"] +lock_version = "4.4.1" content_hash = "sha256:6eb2efcbb7606a63e2aac268217a24edd3c8b7d908d0a537d3f896fc525b0a03" [[package]] @@ -13,6 +12,7 @@ name = "attrs" version = "22.1.0" requires_python = ">=3.5" summary = "Classes Without Boilerplate" +groups = ["tests"] files = [ {file = "attrs-22.1.0-py2.py3-none-any.whl", hash = "sha256:86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c"}, {file = "attrs-22.1.0.tar.gz", hash = "sha256:29adc2665447e5191d0e7c568fde78b21f9672d344281d0c6e1ab085429b22b6"}, @@ -23,6 +23,8 @@ name = "colorama" version = "0.4.5" requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" summary = "Cross-platform colored terminal text." +groups = ["tests"] +marker = "sys_platform == \"win32\"" files = [ {file = "colorama-0.4.5-py2.py3-none-any.whl", hash = "sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da"}, {file = "colorama-0.4.5.tar.gz", hash = "sha256:e6c6b4334fc50988a639d9b98aa429a0b57da6e17b9a44f0451f930b6967b7a4"}, @@ -33,6 +35,8 @@ name = "exceptiongroup" version = "1.1.0" requires_python = ">=3.7" summary = "Backport of PEP 654 (exception groups)" +groups = ["tests"] +marker = "python_version < \"3.11\"" files = [ {file = "exceptiongroup-1.1.0-py3-none-any.whl", hash = "sha256:327cbda3da756e2de031a3107b81ab7b3770a602c4d16ca618298c526f4bec1e"}, {file = "exceptiongroup-1.1.0.tar.gz", hash = "sha256:bcb67d800a4497e1b404c2dd44fca47d3b7a5e5433dbab67f96c1a685cdfdf23"}, @@ -43,6 +47,8 @@ name = "importlib-metadata" version = "4.12.0" requires_python = ">=3.7" summary = "Read metadata from Python packages" +groups = ["tests"] +marker = "python_version < \"3.8\"" dependencies = [ "typing-extensions>=3.6.4; python_version < \"3.8\"", "zipp>=0.5", @@ -56,6 +62,7 @@ files = [ name = "iniconfig" version = "1.1.1" summary = "iniconfig: brain-dead simple config-ini parsing" +groups = ["tests"] files = [ {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, @@ -66,6 +73,7 @@ name = "packaging" version = "23.0" requires_python = ">=3.7" summary = "Core utilities for Python packages" +groups = ["default", "tests"] files = [ {file = "packaging-23.0-py3-none-any.whl", hash = "sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2"}, {file = "packaging-23.0.tar.gz", hash = "sha256:b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97"}, @@ -76,6 +84,7 @@ name = "pluggy" version = "1.0.0" requires_python = ">=3.6" summary = "plugin and hook calling mechanisms for python" +groups = ["tests"] dependencies = [ "importlib-metadata>=0.12; python_version < \"3.8\"", ] @@ -89,6 +98,7 @@ name = "pytest" version = "7.2.1" requires_python = ">=3.7" summary = "pytest: simple powerful testing with Python" +groups = ["tests"] dependencies = [ "attrs>=19.2.0", "colorama; sys_platform == \"win32\"", @@ -109,6 +119,8 @@ name = "tomli" version = "2.0.1" requires_python = ">=3.7" summary = "A lil' TOML parser" +groups = ["tests"] +marker = "python_version < \"3.11\"" files = [ {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, @@ -119,6 +131,8 @@ name = "typing-extensions" version = "4.3.0" requires_python = ">=3.7" summary = "Backported and Experimental Type Hints for Python 3.7+" +groups = ["tests"] +marker = "python_version < \"3.8\"" files = [ {file = "typing_extensions-4.3.0-py3-none-any.whl", hash = "sha256:25642c956049920a5aa49edcdd6ab1e06d7e5d467fc00e0506c44ac86fbfca02"}, {file = "typing_extensions-4.3.0.tar.gz", hash = "sha256:e6d2677a32f47fc7eb2795db1dd15c1f34eff616bcaf2cfb5e997f854fa1c4a6"}, @@ -129,6 +143,8 @@ name = "zipp" version = "3.8.1" requires_python = ">=3.7" summary = "Backport of pathlib-compatible object wrapper for zip files" +groups = ["tests"] +marker = "python_version < \"3.8\"" files = [ {file = "zipp-3.8.1-py3-none-any.whl", hash = "sha256:47c40d7fe183a6f21403a199b3e4192cca5774656965b0a4988ad2f8feb5f009"}, {file = "zipp-3.8.1.tar.gz", hash = "sha256:05b45f1ee8f807d0cc928485ca40a07cb491cf092ff587c0df9cb1fd154848d2"}, diff --git a/src/findpython/providers/winreg.py b/src/findpython/providers/winreg.py index a1e2e80..f5c764c 100644 --- a/src/findpython/providers/winreg.py +++ b/src/findpython/providers/winreg.py @@ -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 @@ -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, ) diff --git a/src/findpython/python.py b/src/findpython/python.py index 9933a03..c638ba3 100644 --- a/src/findpython/python.py +++ b/src/findpython/python.py @@ -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.""" @@ -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 "".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."""