forked from platformio/platformio-core
Switch library manager to the new package manager
This commit is contained in:
1 parent
2dd69e21c0
commit
893ca1b328
30 files changed
+1318
-915
No files matched your search
@@ -20,7 +20,7 @@ import tempfile
|
||||
import click
|
||||
|
||||
from platformio import app, compat, fs, util
|
||||
from platformio.package.exception import PackageException
|
||||
from platformio.package.exception import MissingPackageManifestError, PackageException
|
||||
from platformio.package.meta import PackageSourceItem, PackageSpec
|
||||
from platformio.package.unpack import FileUnpacker
|
||||
from platformio.package.vcsclient import VCSClientFactory
|
||||
@@ -83,7 +83,7 @@ class PackageManagerInstallMixin(object):
|
||||
msg = "Installing %s" % click.style(spec.humanize(), fg="cyan")
|
||||
self.print_message(msg)
|
||||
|
||||
if spec.url:
|
||||
if spec.external:
|
||||
pkg = self.install_from_url(spec.url, spec, silent=silent)
|
||||
else:
|
||||
pkg = self.install_from_registry(spec, search_filters, silent=silent)
|
||||
@@ -152,7 +152,7 @@ class PackageManagerInstallMixin(object):
|
||||
assert os.path.isfile(dl_path)
|
||||
self.unpack(dl_path, tmp_dir)
|
||||
else:
|
||||
vcs = VCSClientFactory.newClient(tmp_dir, url)
|
||||
vcs = VCSClientFactory.new(tmp_dir, url)
|
||||
assert vcs.export()
|
||||
|
||||
root_dir = self.find_pkg_root(tmp_dir, spec)
|
||||
@@ -189,12 +189,20 @@ class PackageManagerInstallMixin(object):
|
||||
|
||||
# what to do with existing package?
|
||||
action = "overwrite"
|
||||
if dst_pkg.metadata and dst_pkg.metadata.spec.url:
|
||||
if tmp_pkg.metadata.spec.has_custom_name():
|
||||
action = "overwrite"
|
||||
dst_pkg = PackageSourceItem(
|
||||
os.path.join(self.package_dir, tmp_pkg.metadata.spec.name)
|
||||
)
|
||||
elif dst_pkg.metadata and dst_pkg.metadata.spec.external:
|
||||
if dst_pkg.metadata.spec.url != tmp_pkg.metadata.spec.url:
|
||||
action = "detach-existing"
|
||||
elif tmp_pkg.metadata.spec.url:
|
||||
elif tmp_pkg.metadata.spec.external:
|
||||
action = "detach-new"
|
||||
elif dst_pkg.metadata and dst_pkg.metadata.version != tmp_pkg.metadata.version:
|
||||
elif dst_pkg.metadata and (
|
||||
dst_pkg.metadata.version != tmp_pkg.metadata.version
|
||||
or dst_pkg.metadata.spec.owner != tmp_pkg.metadata.spec.owner
|
||||
):
|
||||
action = (
|
||||
"detach-existing"
|
||||
if tmp_pkg.metadata.version > dst_pkg.metadata.version
|
||||
@@ -231,7 +239,7 @@ class PackageManagerInstallMixin(object):
|
||||
tmp_pkg.get_safe_dirname(),
|
||||
tmp_pkg.metadata.version,
|
||||
)
|
||||
if tmp_pkg.metadata.spec.url:
|
||||
if tmp_pkg.metadata.spec.external:
|
||||
target_dirname = "%s@src-%s" % (
|
||||
tmp_pkg.get_safe_dirname(),
|
||||
hashlib.md5(
|
||||
@@ -247,3 +255,20 @@ class PackageManagerInstallMixin(object):
|
||||
_cleanup_dir(dst_pkg.path)
|
||||
shutil.move(tmp_pkg.path, dst_pkg.path)
|
||||
return PackageSourceItem(dst_pkg.path)
|
||||
|
||||
def get_installed(self):
|
||||
result = []
|
||||
for name in os.listdir(self.package_dir):
|
||||
pkg_dir = os.path.join(self.package_dir, name)
|
||||
if not os.path.isdir(pkg_dir):
|
||||
continue
|
||||
pkg = PackageSourceItem(pkg_dir)
|
||||
if not pkg.metadata:
|
||||
try:
|
||||
spec = self.build_legacy_spec(pkg_dir)
|
||||
pkg.metadata = self.build_metadata(pkg_dir, spec)
|
||||
except MissingPackageManifestError:
|
||||
pass
|
||||
if pkg.metadata:
|
||||
result.append(pkg)
|
||||
return result
|
||||
@@ -0,0 +1,57 @@
|
||||
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
|
||||
from platformio import fs
|
||||
from platformio.package.meta import PackageSourceItem, PackageSpec
|
||||
|
||||
|
||||
class PackageManagerLegacyMixin(object):
|
||||
def build_legacy_spec(self, pkg_dir):
|
||||
# find src manifest
|
||||
src_manifest_name = ".piopkgmanager.json"
|
||||
src_manifest_path = None
|
||||
for name in os.listdir(pkg_dir):
|
||||
if not os.path.isfile(os.path.join(pkg_dir, name, src_manifest_name)):
|
||||
continue
|
||||
src_manifest_path = os.path.join(pkg_dir, name, src_manifest_name)
|
||||
break
|
||||
|
||||
if src_manifest_path:
|
||||
src_manifest = fs.load_json(src_manifest_path)
|
||||
return PackageSpec(
|
||||
name=src_manifest.get("name"),
|
||||
url=src_manifest.get("url"),
|
||||
requirements=src_manifest.get("requirements"),
|
||||
)
|
||||
|
||||
# fall back to a package manifest
|
||||
manifest = self.load_manifest(pkg_dir)
|
||||
return PackageSpec(name=manifest.get("name"))
|
||||
|
||||
def legacy_load_manifest(self, pkg):
|
||||
assert isinstance(pkg, PackageSourceItem)
|
||||
manifest = self.load_manifest(pkg)
|
||||
manifest["__pkg_dir"] = pkg.path
|
||||
for key in ("name", "version"):
|
||||
if not manifest.get(key):
|
||||
manifest[key] = str(getattr(pkg.metadata, key))
|
||||
if pkg.metadata and pkg.metadata.spec and pkg.metadata.spec.external:
|
||||
manifest["__src_url"] = pkg.metadata.spec.url
|
||||
manifest["version"] = str(pkg.metadata.version)
|
||||
return manifest
|
||||
|
||||
def legacy_get_installed(self):
|
||||
return [self.legacy_load_manifest(pkg) for pkg in self.get_installed()]
|
||||
@@ -79,10 +79,10 @@ class RegistryFileMirrorsIterator(object):
|
||||
class PackageManageRegistryMixin(object):
|
||||
def install_from_registry(self, spec, search_filters=None, silent=False):
|
||||
if spec.owner and spec.name and not search_filters:
|
||||
package = self.fetch_registry_package(spec.owner, spec.name)
|
||||
package = self.fetch_registry_package(spec)
|
||||
if not package:
|
||||
raise UnknownPackageError(spec.humanize())
|
||||
version = self._pick_best_pkg_version(package["versions"], spec)
|
||||
version = self.pick_best_registry_version(package["versions"], spec)
|
||||
else:
|
||||
packages = self.search_registry_packages(spec, search_filters)
|
||||
if not packages:
|
||||
@@ -131,10 +131,33 @@ class PackageManageRegistryMixin(object):
|
||||
"items"
|
||||
]
|
||||
|
||||
def fetch_registry_package(self, owner, name):
|
||||
return self.get_registry_client_instance().get_package(
|
||||
self.pkg_type, owner, name
|
||||
)
|
||||
def fetch_registry_package(self, spec):
|
||||
result = None
|
||||
if spec.owner and spec.name:
|
||||
result = self.get_registry_client_instance().get_package(
|
||||
self.pkg_type, spec.owner, spec.name
|
||||
)
|
||||
if not result and (spec.id or (spec.name and not spec.owner)):
|
||||
packages = self.search_registry_packages(spec)
|
||||
if packages:
|
||||
result = self.get_registry_client_instance().get_package(
|
||||
self.pkg_type, packages[0]["owner"]["username"], packages[0]["name"]
|
||||
)
|
||||
if not result:
|
||||
raise UnknownPackageError(spec.humanize())
|
||||
return result
|
||||
|
||||
def reveal_registry_package_id(self, spec, silent=False):
|
||||
spec = self.ensure_spec(spec)
|
||||
if spec.id:
|
||||
return spec.id
|
||||
packages = self.search_registry_packages(spec)
|
||||
if not packages:
|
||||
raise UnknownPackageError(spec.humanize())
|
||||
if len(packages) > 1 and not silent:
|
||||
self.print_multi_package_issue(packages, spec)
|
||||
click.echo("")
|
||||
return packages[0]["id"]
|
||||
|
||||
@staticmethod
|
||||
def print_multi_package_issue(packages, spec):
|
||||
@@ -160,7 +183,7 @@ class PackageManageRegistryMixin(object):
|
||||
def find_best_registry_version(self, packages, spec):
|
||||
# find compatible version within the latest package versions
|
||||
for package in packages:
|
||||
version = self._pick_best_pkg_version([package["version"]], spec)
|
||||
version = self.pick_best_registry_version([package["version"]], spec)
|
||||
if version:
|
||||
return (package, version)
|
||||
|
||||
@@ -169,9 +192,13 @@ class PackageManageRegistryMixin(object):
|
||||
|
||||
# if the custom version requirements, check ALL package versions
|
||||
for package in packages:
|
||||
version = self._pick_best_pkg_version(
|
||||
version = self.pick_best_registry_version(
|
||||
self.fetch_registry_package(
|
||||
package["owner"]["username"], package["name"]
|
||||
PackageSpec(
|
||||
id=package["id"],
|
||||
owner=package["owner"]["username"],
|
||||
name=package["name"],
|
||||
)
|
||||
).get("versions"),
|
||||
spec,
|
||||
)
|
||||
@@ -180,11 +207,12 @@ class PackageManageRegistryMixin(object):
|
||||
time.sleep(1)
|
||||
return None
|
||||
|
||||
def _pick_best_pkg_version(self, versions, spec):
|
||||
def pick_best_registry_version(self, versions, spec=None):
|
||||
assert not spec or isinstance(spec, PackageSpec)
|
||||
best = None
|
||||
for version in versions:
|
||||
semver = PackageMetaData.to_semver(version["name"])
|
||||
if spec.requirements and semver not in spec.requirements:
|
||||
if spec and spec.requirements and semver not in spec.requirements:
|
||||
continue
|
||||
if not any(
|
||||
self.is_system_compatible(f.get("system")) for f in version["files"]
|
||||
|
||||
@@ -31,10 +31,7 @@ class PackageManagerUninstallMixin(object):
|
||||
self.unlock()
|
||||
|
||||
def _uninstall(self, pkg, silent=False, skip_dependencies=False):
|
||||
if not isinstance(pkg, PackageSourceItem):
|
||||
pkg = (
|
||||
PackageSourceItem(pkg) if os.path.isdir(pkg) else self.get_package(pkg)
|
||||
)
|
||||
pkg = self.get_package(pkg)
|
||||
if not pkg or not pkg.metadata:
|
||||
raise UnknownPackageError(pkg)
|
||||
|
||||
@@ -73,7 +70,7 @@ class PackageManagerUninstallMixin(object):
|
||||
if not silent:
|
||||
click.echo("[%s]" % click.style("OK", fg="green"))
|
||||
|
||||
return True
|
||||
return pkg
|
||||
|
||||
def _uninstall_dependencies(self, pkg, silent=False):
|
||||
assert isinstance(pkg, PackageSourceItem)
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
|
||||
import click
|
||||
|
||||
from platformio import util
|
||||
from platformio.package.exception import UnknownPackageError
|
||||
from platformio.package.meta import (
|
||||
PackageOutdatedResult,
|
||||
PackageSourceItem,
|
||||
PackageSpec,
|
||||
)
|
||||
from platformio.package.vcsclient import VCSBaseException, VCSClientFactory
|
||||
|
||||
|
||||
class PackageManagerUpdateMixin(object):
|
||||
def outdated(self, pkg, spec=None):
|
||||
assert isinstance(pkg, PackageSourceItem)
|
||||
assert not spec or isinstance(spec, PackageSpec)
|
||||
assert os.path.isdir(pkg.path) and pkg.metadata
|
||||
|
||||
# skip detached package to a specific version
|
||||
detached_conditions = [
|
||||
"@" in pkg.path,
|
||||
pkg.metadata.spec and not pkg.metadata.spec.external,
|
||||
not spec,
|
||||
]
|
||||
if all(detached_conditions):
|
||||
return PackageOutdatedResult(current=pkg.metadata.version, detached=True)
|
||||
|
||||
latest = None
|
||||
wanted = None
|
||||
if pkg.metadata.spec.external:
|
||||
latest = self._fetch_vcs_latest_version(pkg)
|
||||
else:
|
||||
try:
|
||||
reg_pkg = self.fetch_registry_package(pkg.metadata.spec)
|
||||
latest = (
|
||||
self.pick_best_registry_version(reg_pkg["versions"]) or {}
|
||||
).get("name")
|
||||
if spec:
|
||||
wanted = (
|
||||
self.pick_best_registry_version(reg_pkg["versions"], spec) or {}
|
||||
).get("name")
|
||||
if not wanted: # wrong library
|
||||
latest = None
|
||||
except UnknownPackageError:
|
||||
pass
|
||||
|
||||
return PackageOutdatedResult(
|
||||
current=pkg.metadata.version, latest=latest, wanted=wanted
|
||||
)
|
||||
|
||||
def _fetch_vcs_latest_version(self, pkg):
|
||||
vcs = None
|
||||
try:
|
||||
vcs = VCSClientFactory.new(pkg.path, pkg.metadata.spec.url, silent=True)
|
||||
except VCSBaseException:
|
||||
return None
|
||||
if not vcs.can_be_updated:
|
||||
return None
|
||||
return str(
|
||||
self.build_metadata(
|
||||
pkg.path, pkg.metadata.spec, vcs_revision=vcs.get_latest_revision()
|
||||
).version
|
||||
)
|
||||
|
||||
def update(self, pkg, spec=None, only_check=False, silent=False):
|
||||
pkg = self.get_package(pkg)
|
||||
if not pkg or not pkg.metadata:
|
||||
raise UnknownPackageError(pkg)
|
||||
|
||||
if not silent:
|
||||
click.echo(
|
||||
"{} {:<45} {:<30}".format(
|
||||
"Checking" if only_check else "Updating",
|
||||
click.style(pkg.metadata.spec.humanize(), fg="cyan"),
|
||||
"%s (%s)" % (pkg.metadata.version, spec.requirements)
|
||||
if spec and spec.requirements
|
||||
else str(pkg.metadata.version),
|
||||
),
|
||||
nl=False,
|
||||
)
|
||||
if not util.internet_on():
|
||||
if not silent:
|
||||
click.echo("[%s]" % (click.style("Off-line", fg="yellow")))
|
||||
return pkg
|
||||
|
||||
outdated = self.outdated(pkg, spec)
|
||||
if not silent:
|
||||
self.print_outdated_state(outdated)
|
||||
|
||||
up_to_date = any(
|
||||
[
|
||||
outdated.detached,
|
||||
not outdated.latest,
|
||||
outdated.latest and outdated.current == outdated.latest,
|
||||
outdated.wanted and outdated.current == outdated.wanted,
|
||||
]
|
||||
)
|
||||
if only_check or up_to_date:
|
||||
return pkg
|
||||
|
||||
try:
|
||||
self.lock()
|
||||
return self._update(pkg, outdated, silent=silent)
|
||||
finally:
|
||||
self.unlock()
|
||||
|
||||
@staticmethod
|
||||
def print_outdated_state(outdated):
|
||||
if outdated.detached:
|
||||
return click.echo("[%s]" % (click.style("Detached", fg="yellow")))
|
||||
if not outdated.latest or outdated.current == outdated.latest:
|
||||
return click.echo("[%s]" % (click.style("Up-to-date", fg="green")))
|
||||
if outdated.wanted and outdated.current == outdated.wanted:
|
||||
return click.echo(
|
||||
"[%s]"
|
||||
% (click.style("Incompatible (%s)" % outdated.latest, fg="yellow"))
|
||||
)
|
||||
return click.echo(
|
||||
"[%s]" % (click.style(str(outdated.wanted or outdated.latest), fg="red"))
|
||||
)
|
||||
|
||||
def _update(self, pkg, outdated, silent=False):
|
||||
if pkg.metadata.spec.external:
|
||||
vcs = VCSClientFactory.new(pkg.path, pkg.metadata.spec.url)
|
||||
assert vcs.update()
|
||||
pkg.metadata.version = self._fetch_vcs_latest_version(pkg)
|
||||
pkg.dump_meta()
|
||||
return pkg
|
||||
|
||||
new_pkg = self.install(
|
||||
PackageSpec(
|
||||
id=pkg.metadata.spec.id,
|
||||
owner=pkg.metadata.spec.owner,
|
||||
name=pkg.metadata.spec.name,
|
||||
requirements=outdated.wanted or outdated.latest,
|
||||
),
|
||||
silent=silent,
|
||||
)
|
||||
if new_pkg:
|
||||
old_pkg = self.get_package(
|
||||
PackageSpec(
|
||||
id=pkg.metadata.spec.id,
|
||||
owner=pkg.metadata.spec.owner,
|
||||
name=pkg.metadata.name,
|
||||
requirements=pkg.metadata.version,
|
||||
)
|
||||
)
|
||||
if old_pkg:
|
||||
self.uninstall(old_pkg, silent=silent, skip_dependencies=True)
|
||||
return new_pkg
|
||||
@@ -18,14 +18,17 @@ from datetime import datetime
|
||||
import click
|
||||
import semantic_version
|
||||
|
||||
from platformio import fs, util
|
||||
from platformio import util
|
||||
from platformio.commands import PlatformioCLI
|
||||
from platformio.compat import ci_strings_are_equal
|
||||
from platformio.package.exception import ManifestException, MissingPackageManifestError
|
||||
from platformio.package.lockfile import LockFile
|
||||
from platformio.package.manager._download import PackageManagerDownloadMixin
|
||||
from platformio.package.manager._install import PackageManagerInstallMixin
|
||||
from platformio.package.manager._legacy import PackageManagerLegacyMixin
|
||||
from platformio.package.manager._registry import PackageManageRegistryMixin
|
||||
from platformio.package.manager._uninstall import PackageManagerUninstallMixin
|
||||
from platformio.package.manager._update import PackageManagerUpdateMixin
|
||||
from platformio.package.manifest.parser import ManifestParserFactory
|
||||
from platformio.package.meta import (
|
||||
PackageMetaData,
|
||||
@@ -41,6 +44,8 @@ class BasePackageManager( # pylint: disable=too-many-public-methods
|
||||
PackageManageRegistryMixin,
|
||||
PackageManagerInstallMixin,
|
||||
PackageManagerUninstallMixin,
|
||||
PackageManagerUpdateMixin,
|
||||
PackageManagerLegacyMixin,
|
||||
):
|
||||
_MEMORY_CACHE = {}
|
||||
|
||||
@@ -83,10 +88,6 @@ class BasePackageManager( # pylint: disable=too-many-public-methods
|
||||
return True
|
||||
return util.items_in_list(value, util.get_systype())
|
||||
|
||||
@staticmethod
|
||||
def generate_rand_version():
|
||||
return datetime.now().strftime("0.0.0+%Y%m%d%H%M%S")
|
||||
|
||||
@staticmethod
|
||||
def ensure_dir_exists(path):
|
||||
if not os.path.isdir(path):
|
||||
@@ -162,27 +163,9 @@ class BasePackageManager( # pylint: disable=too-many-public-methods
|
||||
click.secho(str(e), fg="yellow")
|
||||
raise MissingPackageManifestError(", ".join(self.manifest_names))
|
||||
|
||||
def build_legacy_spec(self, pkg_dir):
|
||||
# find src manifest
|
||||
src_manifest_name = ".piopkgmanager.json"
|
||||
src_manifest_path = None
|
||||
for name in os.listdir(pkg_dir):
|
||||
if not os.path.isfile(os.path.join(pkg_dir, name, src_manifest_name)):
|
||||
continue
|
||||
src_manifest_path = os.path.join(pkg_dir, name, src_manifest_name)
|
||||
break
|
||||
|
||||
if src_manifest_path:
|
||||
src_manifest = fs.load_json(src_manifest_path)
|
||||
return PackageSpec(
|
||||
name=src_manifest.get("name"),
|
||||
url=src_manifest.get("url"),
|
||||
requirements=src_manifest.get("requirements"),
|
||||
)
|
||||
|
||||
# fall back to a package manifest
|
||||
manifest = self.load_manifest(pkg_dir)
|
||||
return PackageSpec(name=manifest.get("name"))
|
||||
@staticmethod
|
||||
def generate_rand_version():
|
||||
return datetime.now().strftime("0.0.0+%Y%m%d%H%M%S")
|
||||
|
||||
def build_metadata(self, pkg_dir, spec, vcs_revision=None):
|
||||
manifest = self.load_manifest(pkg_dir)
|
||||
@@ -192,7 +175,7 @@ class BasePackageManager( # pylint: disable=too-many-public-methods
|
||||
version=manifest.get("version"),
|
||||
spec=spec,
|
||||
)
|
||||
if not metadata.name or spec.is_custom_name():
|
||||
if not metadata.name or spec.has_custom_name():
|
||||
metadata.name = spec.name
|
||||
if vcs_revision:
|
||||
metadata.version = "%s+sha.%s" % (
|
||||
@@ -203,42 +186,27 @@ class BasePackageManager( # pylint: disable=too-many-public-methods
|
||||
metadata.version = self.generate_rand_version()
|
||||
return metadata
|
||||
|
||||
def get_installed(self):
|
||||
result = []
|
||||
for name in os.listdir(self.package_dir):
|
||||
pkg_dir = os.path.join(self.package_dir, name)
|
||||
if not os.path.isdir(pkg_dir):
|
||||
continue
|
||||
pkg = PackageSourceItem(pkg_dir)
|
||||
if not pkg.metadata:
|
||||
try:
|
||||
spec = self.build_legacy_spec(pkg_dir)
|
||||
pkg.metadata = self.build_metadata(pkg_dir, spec)
|
||||
except MissingPackageManifestError:
|
||||
pass
|
||||
if pkg.metadata:
|
||||
result.append(pkg)
|
||||
return result
|
||||
|
||||
def get_package(self, spec):
|
||||
def _ci_strings_are_equal(a, b):
|
||||
if a == b:
|
||||
return True
|
||||
if not a or not b:
|
||||
return False
|
||||
return a.strip().lower() == b.strip().lower()
|
||||
if isinstance(spec, PackageSourceItem):
|
||||
return spec
|
||||
|
||||
if not isinstance(spec, PackageSpec) and os.path.isdir(spec):
|
||||
for pkg in self.get_installed():
|
||||
if spec == pkg.path:
|
||||
return pkg
|
||||
return None
|
||||
|
||||
spec = self.ensure_spec(spec)
|
||||
best = None
|
||||
for pkg in self.get_installed():
|
||||
skip_conditions = [
|
||||
spec.owner
|
||||
and not _ci_strings_are_equal(spec.owner, pkg.metadata.spec.owner),
|
||||
spec.url and spec.url != pkg.metadata.spec.url,
|
||||
and not ci_strings_are_equal(spec.owner, pkg.metadata.spec.owner),
|
||||
spec.external and spec.url != pkg.metadata.spec.url,
|
||||
spec.id and spec.id != pkg.metadata.spec.id,
|
||||
not spec.id
|
||||
and not spec.url
|
||||
and not _ci_strings_are_equal(spec.name, pkg.metadata.name),
|
||||
and not spec.external
|
||||
and not ci_strings_are_equal(spec.name, pkg.metadata.name),
|
||||
]
|
||||
if any(skip_conditions):
|
||||
continue
|
||||
|
||||
@@ -21,7 +21,7 @@ from platformio.package.meta import PackageSpec, PackageType
|
||||
from platformio.project.helpers import get_project_global_lib_dir
|
||||
|
||||
|
||||
class LibraryPackageManager(BasePackageManager):
|
||||
class LibraryPackageManager(BasePackageManager): # pylint: disable=too-many-ancestors
|
||||
def __init__(self, package_dir=None):
|
||||
super(LibraryPackageManager, self).__init__(
|
||||
PackageType.LIBRARY, package_dir or get_project_global_lib_dir()
|
||||
|
||||
@@ -17,7 +17,7 @@ from platformio.package.meta import PackageType
|
||||
from platformio.project.config import ProjectConfig
|
||||
|
||||
|
||||
class PlatformPackageManager(BasePackageManager):
|
||||
class PlatformPackageManager(BasePackageManager): # pylint: disable=too-many-ancestors
|
||||
def __init__(self, package_dir=None):
|
||||
self.config = ProjectConfig.get_instance()
|
||||
super(PlatformPackageManager, self).__init__(
|
||||
|
||||
@@ -17,7 +17,7 @@ from platformio.package.meta import PackageType
|
||||
from platformio.project.config import ProjectConfig
|
||||
|
||||
|
||||
class ToolPackageManager(BasePackageManager):
|
||||
class ToolPackageManager(BasePackageManager): # pylint: disable=too-many-ancestors
|
||||
def __init__(self, package_dir=None):
|
||||
self.config = ProjectConfig.get_instance()
|
||||
super(ToolPackageManager, self).__init__(
|
||||
|
||||
@@ -250,7 +250,7 @@ class ManifestSchema(BaseSchema):
|
||||
def load_spdx_licenses():
|
||||
r = requests.get(
|
||||
"https://raw.githubusercontent.com/spdx/license-list-data"
|
||||
"/v3.9/json/licenses.json"
|
||||
"/v3.10/json/licenses.json"
|
||||
)
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
@@ -65,7 +65,44 @@ class PackageType(object):
|
||||
return None
|
||||
|
||||
|
||||
class PackageSpec(object):
|
||||
class PackageOutdatedResult(object):
|
||||
def __init__(self, current, latest=None, wanted=None, detached=False):
|
||||
self.current = current
|
||||
self.latest = latest
|
||||
self.wanted = wanted
|
||||
self.detached = detached
|
||||
|
||||
def __repr__(self):
|
||||
return (
|
||||
"PackageOutdatedResult <current={current} latest={latest} wanted={wanted} "
|
||||
"detached={detached}>".format(
|
||||
current=self.current,
|
||||
latest=self.latest,
|
||||
wanted=self.wanted,
|
||||
detached=self.detached,
|
||||
)
|
||||
)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if (
|
||||
value
|
||||
and name in ("current", "latest", "wanted")
|
||||
and not isinstance(value, semantic_version.Version)
|
||||
):
|
||||
value = semantic_version.Version(str(value))
|
||||
return super(PackageOutdatedResult, self).__setattr__(name, value)
|
||||
|
||||
def is_outdated(self, allow_incompatible=False):
|
||||
if self.detached or not self.latest or self.current == self.latest:
|
||||
return False
|
||||
if allow_incompatible:
|
||||
return self.current != self.latest
|
||||
if self.wanted:
|
||||
return self.current != self.wanted
|
||||
return True
|
||||
|
||||
|
||||
class PackageSpec(object): # pylint: disable=too-many-instance-attributes
|
||||
def __init__( # pylint: disable=redefined-builtin,too-many-arguments
|
||||
self, raw=None, owner=None, id=None, name=None, requirements=None, url=None
|
||||
):
|
||||
@@ -74,6 +111,7 @@ class PackageSpec(object):
|
||||
self.name = name
|
||||
self._requirements = None
|
||||
self.url = url
|
||||
self.raw = raw
|
||||
if requirements:
|
||||
self.requirements = requirements
|
||||
self._name_is_custom = False
|
||||
@@ -104,6 +142,10 @@ class PackageSpec(object):
|
||||
"requirements={requirements} url={url}>".format(**self.as_dict())
|
||||
)
|
||||
|
||||
@property
|
||||
def external(self):
|
||||
return bool(self.url)
|
||||
|
||||
@property
|
||||
def requirements(self):
|
||||
return self._requirements
|
||||
@@ -116,24 +158,24 @@ class PackageSpec(object):
|
||||
self._requirements = (
|
||||
value
|
||||
if isinstance(value, semantic_version.SimpleSpec)
|
||||
else semantic_version.SimpleSpec(value)
|
||||
else semantic_version.SimpleSpec(str(value))
|
||||
)
|
||||
|
||||
def humanize(self):
|
||||
result = ""
|
||||
if self.url:
|
||||
result = self.url
|
||||
elif self.id:
|
||||
result = "id:%d" % self.id
|
||||
else:
|
||||
result = ""
|
||||
elif self.name:
|
||||
if self.owner:
|
||||
result = self.owner + "/"
|
||||
result += self.name
|
||||
elif self.id:
|
||||
result = "id:%d" % self.id
|
||||
if self.requirements:
|
||||
result += " @ " + str(self.requirements)
|
||||
return result
|
||||
|
||||
def is_custom_name(self):
|
||||
def has_custom_name(self):
|
||||
return self._name_is_custom
|
||||
|
||||
def as_dict(self):
|
||||
@@ -145,6 +187,19 @@ class PackageSpec(object):
|
||||
url=self.url,
|
||||
)
|
||||
|
||||
def as_dependency(self):
|
||||
if self.url:
|
||||
return self.raw or self.url
|
||||
result = ""
|
||||
if self.name:
|
||||
result = "%s/%s" % (self.owner, self.name) if self.owner else self.name
|
||||
elif self.id:
|
||||
result = str(self.id)
|
||||
assert result
|
||||
if self.requirements:
|
||||
result = "%s@%s" % (result, self.requirements)
|
||||
return result
|
||||
|
||||
def _parse(self, raw):
|
||||
if raw is None:
|
||||
return
|
||||
|
||||
@@ -17,7 +17,11 @@ from os.path import join
|
||||
from subprocess import CalledProcessError, check_call
|
||||
from sys import modules
|
||||
|
||||
from platformio.exception import PlatformioException, UserSideException
|
||||
from platformio.package.exception import (
|
||||
PackageException,
|
||||
PlatformioException,
|
||||
UserSideException,
|
||||
)
|
||||
from platformio.proc import exec_command
|
||||
|
||||
try:
|
||||
@@ -26,9 +30,13 @@ except ImportError:
|
||||
from urlparse import urlparse
|
||||
|
||||
|
||||
class VCSBaseException(PackageException):
|
||||
pass
|
||||
|
||||
|
||||
class VCSClientFactory(object):
|
||||
@staticmethod
|
||||
def newClient(src_dir, remote_url, silent=False):
|
||||
def new(src_dir, remote_url, silent=False):
|
||||
result = urlparse(remote_url)
|
||||
type_ = result.scheme
|
||||
tag = None
|
||||
@@ -41,12 +49,15 @@ class VCSClientFactory(object):
|
||||
if "#" in remote_url:
|
||||
remote_url, tag = remote_url.rsplit("#", 1)
|
||||
if not type_:
|
||||
raise PlatformioException("VCS: Unknown repository type %s" % remote_url)
|
||||
obj = getattr(modules[__name__], "%sClient" % type_.title())(
|
||||
src_dir, remote_url, tag, silent
|
||||
)
|
||||
assert isinstance(obj, VCSClientBase)
|
||||
return obj
|
||||
raise VCSBaseException("VCS: Unknown repository type %s" % remote_url)
|
||||
try:
|
||||
obj = getattr(modules[__name__], "%sClient" % type_.title())(
|
||||
src_dir, remote_url, tag, silent
|
||||
)
|
||||
assert isinstance(obj, VCSClientBase)
|
||||
return obj
|
||||
except (AttributeError, AssertionError):
|
||||
raise VCSBaseException("VCS: Unknown repository type %s" % remote_url)
|
||||
|
||||
|
||||
class VCSClientBase(object):
|
||||
@@ -101,7 +112,7 @@ class VCSClientBase(object):
|
||||
check_call(args, **kwargs)
|
||||
return True
|
||||
except CalledProcessError as e:
|
||||
raise PlatformioException("VCS: Could not process command %s" % e.cmd)
|
||||
raise VCSBaseException("VCS: Could not process command %s" % e.cmd)
|
||||
|
||||
def get_cmd_output(self, args, **kwargs):
|
||||
args = [self.command] + args
|
||||
@@ -110,7 +121,7 @@ class VCSClientBase(object):
|
||||
result = exec_command(args, **kwargs)
|
||||
if result["returncode"] == 0:
|
||||
return result["out"].strip()
|
||||
raise PlatformioException(
|
||||
raise VCSBaseException(
|
||||
"VCS: Could not receive an output from `%s` command (%s)" % (args, result)
|
||||
)
|
||||
|
||||
@@ -227,7 +238,6 @@ class SvnClient(VCSClientBase):
|
||||
return self.run_cmd(args)
|
||||
|
||||
def update(self):
|
||||
|
||||
args = ["update"]
|
||||
return self.run_cmd(args)
|
||||
|
||||
@@ -239,4 +249,4 @@ class SvnClient(VCSClientBase):
|
||||
line = line.strip()
|
||||
if line.startswith("Revision:"):
|
||||
return line.split(":", 1)[1].strip()
|
||||
raise PlatformioException("Could not detect current SVN revision")
|
||||
raise VCSBaseException("Could not detect current SVN revision")
|
||||
Reference in new issue
Block a user