From e046cd58a4f4e2db1c43d861e28a12780f9a477e Mon Sep 17 00:00:00 2001 From: Icecreambobcat Date: Wed, 18 Mar 2026 18:53:04 +1100 Subject: [PATCH 1/2] Switch to importlib Removes the deprecated `pkg_resources` module in favour of `importlib.metadata`. This also fixes installations by `pipx` etc throwing a "could not determine version" error. --- pros/common/utils.py | 15 +++++++-------- pros/upgrade/manifests/upgrade_manifest_v2.py | 18 +++++++++++------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/pros/common/utils.py b/pros/common/utils.py index 294da89f..799c0822 100644 --- a/pros/common/utils.py +++ b/pros/common/utils.py @@ -27,19 +27,18 @@ def get_version(): except: pass try: - import pkg_resources + from importlib.metadata import distributions except ImportError: pass else: import pros.cli.main module = pros.cli.main.__name__ - for dist in pkg_resources.working_set: - scripts = dist.get_entry_map().get('console_scripts') or {} - for script_name, entry_point in iter(scripts.items()): - if entry_point.module_name == module: - ver = dist.version - if ver is not None: - return ver + for dist in distributions(): + for entry_point in dist.entry_points: + if entry_point.group == "console_scripts": + if entry_point.module == module: + if dist.version is not None: + return dist.version raise RuntimeError('Could not determine version') diff --git a/pros/upgrade/manifests/upgrade_manifest_v2.py b/pros/upgrade/manifests/upgrade_manifest_v2.py index b024aa3d..900d94f5 100644 --- a/pros/upgrade/manifests/upgrade_manifest_v2.py +++ b/pros/upgrade/manifests/upgrade_manifest_v2.py @@ -2,6 +2,8 @@ from enum import Enum from typing import * +from importlib.metadata import distributions + from pros.common import logger from .upgrade_manifest_v1 import UpgradeManifestV1 from ..instructions import UpgradeInstruction, UpgradeResult, NothingInstruction @@ -27,7 +29,6 @@ def __init__(self): self.platform_instructions: Dict[PlatformsV2, UpgradeInstruction] = {} self._platform: 'PlatformsV2' = None - self._last_file: Optional[str] = None @property @@ -50,11 +51,12 @@ def platform(self) -> 'PlatformsV2': self._platform = PlatformsV2.MacOS else: try: - from pip._vendor import pkg_resources - results = [p for p in pkg_resources.working_set if p.project_name.startswith('pros-cli')] - if any(results): - self._platform = PlatformsV2.Pip - except ImportError: + for dist in distributions(): + name = (dist.metadata.get("Name") or "").lower() + if name.startswith("pros-cli"): + self._platform = PlatformsV2.Pip + break + except Exception: pass if not self._platform: self._platform = PlatformsV2.Unknown @@ -65,7 +67,9 @@ def can_perform_upgrade(self) -> bool: return True def perform_upgrade(self) -> UpgradeResult: - instructions: UpgradeInstruction = self.platform_instructions.get(self.platform, NothingInstruction()) + instructions: UpgradeInstruction = self.platform_instructions.get( + self.platform, NothingInstruction() + ) logger(__name__).debug(self.__dict__) logger(__name__).debug(f'Platform: {self.platform}') logger(__name__).debug(instructions.__dict__) From b032626173374ba87e492f8774c91f45280fe10e Mon Sep 17 00:00:00 2001 From: Icecreambobcat Date: Wed, 18 Mar 2026 19:15:25 +1100 Subject: [PATCH 2/2] Apply copilot changes Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- pros/common/utils.py | 18 +++++++++++++++--- pros/upgrade/manifests/upgrade_manifest_v2.py | 6 +++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pros/common/utils.py b/pros/common/utils.py index 799c0822..d38b8cce 100644 --- a/pros/common/utils.py +++ b/pros/common/utils.py @@ -35,10 +35,22 @@ def get_version(): module = pros.cli.main.__name__ for dist in distributions(): for entry_point in dist.entry_points: + try: + entry_points = dist.entry_points + except Exception: + continue if entry_point.group == "console_scripts": - if entry_point.module == module: - if dist.version is not None: - return dist.version + ep_module = getattr(entry_point, "module", None) + if ep_module is None: + value = getattr(entry_point, "value", "") or "" + ep_module = value.split(":", 1)[0] if value else None + if ep_module == module: + try: + version = dist.version + except Exception: + continue + if version is not None: + return version raise RuntimeError('Could not determine version') diff --git a/pros/upgrade/manifests/upgrade_manifest_v2.py b/pros/upgrade/manifests/upgrade_manifest_v2.py index 900d94f5..40bd19d0 100644 --- a/pros/upgrade/manifests/upgrade_manifest_v2.py +++ b/pros/upgrade/manifests/upgrade_manifest_v2.py @@ -2,7 +2,6 @@ from enum import Enum from typing import * -from importlib.metadata import distributions from pros.common import logger from .upgrade_manifest_v1 import UpgradeManifestV1 @@ -51,6 +50,11 @@ def platform(self) -> 'PlatformsV2': self._platform = PlatformsV2.MacOS else: try: + try: + from importlib.metadata import distributions + except ImportError: + from importlib_metadata import distributions # type: ignore + for dist in distributions(): name = (dist.metadata.get("Name") or "").lower() if name.startswith("pros-cli"):