Skip to content
Open
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
27 changes: 19 additions & 8 deletions pros/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,30 @@ 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:
try:
entry_points = dist.entry_points
except Exception:
continue
if entry_point.group == "console_scripts":
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')


Expand Down
22 changes: 15 additions & 7 deletions pros/upgrade/manifests/upgrade_manifest_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from enum import Enum
from typing import *


from pros.common import logger
from .upgrade_manifest_v1 import UpgradeManifestV1
from ..instructions import UpgradeInstruction, UpgradeResult, NothingInstruction
Expand All @@ -27,7 +28,6 @@ def __init__(self):
self.platform_instructions: Dict[PlatformsV2, UpgradeInstruction] = {}

self._platform: 'PlatformsV2' = None

self._last_file: Optional[str] = None

@property
Expand All @@ -50,11 +50,17 @@ 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:
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"):
self._platform = PlatformsV2.Pip
break
except Exception:
pass
Comment thread
Icecreambobcat marked this conversation as resolved.
if not self._platform:
self._platform = PlatformsV2.Unknown
Expand All @@ -65,7 +71,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__)
Expand Down