mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 01:57:13 +02:00
Allow custom system for the package manager API
This commit is contained in:
@ -41,7 +41,7 @@ class PackageManagerRegistryMixin:
|
|||||||
if not package or not version:
|
if not package or not version:
|
||||||
raise UnknownPackageError(spec.humanize())
|
raise UnknownPackageError(spec.humanize())
|
||||||
|
|
||||||
pkgfile = self._pick_compatible_pkg_file(version["files"]) if version else None
|
pkgfile = self.pick_compatible_pkg_file(version["files"]) if version else None
|
||||||
if not pkgfile:
|
if not pkgfile:
|
||||||
raise UnknownPackageError(spec.humanize())
|
raise UnknownPackageError(spec.humanize())
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ class PackageManagerRegistryMixin:
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
return (None, None)
|
return (None, None)
|
||||||
|
|
||||||
def filter_incompatible_registry_versions(self, versions, spec=None):
|
def get_compatible_registry_versions(self, versions, spec=None, custom_system=None):
|
||||||
assert not spec or isinstance(spec, PackageSpec)
|
assert not spec or isinstance(spec, PackageSpec)
|
||||||
result = []
|
result = []
|
||||||
for version in versions:
|
for version in versions:
|
||||||
@ -170,22 +170,27 @@ class PackageManagerRegistryMixin:
|
|||||||
if spec and spec.requirements and semver not in spec.requirements:
|
if spec and spec.requirements and semver not in spec.requirements:
|
||||||
continue
|
continue
|
||||||
if not any(
|
if not any(
|
||||||
self.is_system_compatible(f.get("system")) for f in version["files"]
|
self.is_system_compatible(f.get("system"), custom_system=custom_system)
|
||||||
|
for f in version["files"]
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
result.append(version)
|
result.append(version)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def pick_best_registry_version(self, versions, spec=None):
|
def pick_best_registry_version(self, versions, spec=None, custom_system=None):
|
||||||
best = None
|
best = None
|
||||||
for version in self.filter_incompatible_registry_versions(versions, spec):
|
for version in self.get_compatible_registry_versions(
|
||||||
|
versions, spec, custom_system
|
||||||
|
):
|
||||||
semver = cast_version_to_semver(version["name"])
|
semver = cast_version_to_semver(version["name"])
|
||||||
if not best or (semver > cast_version_to_semver(best["name"])):
|
if not best or (semver > cast_version_to_semver(best["name"])):
|
||||||
best = version
|
best = version
|
||||||
return best
|
return best
|
||||||
|
|
||||||
def _pick_compatible_pkg_file(self, version_files):
|
def pick_compatible_pkg_file(self, version_files, custom_system=None):
|
||||||
for item in version_files:
|
for item in version_files:
|
||||||
if self.is_system_compatible(item.get("system")):
|
if self.is_system_compatible(
|
||||||
|
item.get("system"), custom_system=custom_system
|
||||||
|
):
|
||||||
return item
|
return item
|
||||||
return None
|
return None
|
||||||
|
@ -116,10 +116,10 @@ class BasePackageManager( # pylint: disable=too-many-public-methods,too-many-in
|
|||||||
self._MEMORY_CACHE.clear()
|
self._MEMORY_CACHE.clear()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_system_compatible(value):
|
def is_system_compatible(value, custom_system=None):
|
||||||
if not value or "*" in value:
|
if not value or "*" in value:
|
||||||
return True
|
return True
|
||||||
return util.items_in_list(value, util.get_systype())
|
return util.items_in_list(value, custom_system or util.get_systype())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ensure_dir_exists(path):
|
def ensure_dir_exists(path):
|
||||||
|
Reference in New Issue
Block a user