Exemple #1
0
def test_update_with_metadata(isolated_pio_core, tmpdir_factory):
    storage_dir = tmpdir_factory.mktemp("storage")
    lm = LibraryPackageManager(str(storage_dir))

    # test non SemVer in registry
    pkg = lm.install("RadioHead @ <1.90", silent=True)
    outdated = lm.outdated(pkg)
    assert str(outdated.current) == "1.89.0"
    assert outdated.latest > semantic_version.Version("1.100.0")

    pkg = lm.install("ArduinoJson @ 5.10.1", silent=True)
    # tesy latest
    outdated = lm.outdated(pkg)
    assert str(outdated.current) == "5.10.1"
    assert outdated.wanted is None
    assert outdated.latest > outdated.current
    assert outdated.latest > semantic_version.Version("5.99.99")

    # test wanted
    outdated = lm.outdated(pkg, PackageSpec("ArduinoJson@~5"))
    assert str(outdated.current) == "5.10.1"
    assert str(outdated.wanted) == "5.13.4"
    assert outdated.latest > semantic_version.Version("6.16.0")

    # update to the wanted 5.x
    new_pkg = lm.update("ArduinoJson@^5", PackageSpec("ArduinoJson@^5"), silent=True)
    assert str(new_pkg.metadata.version) == "5.13.4"
    # check that old version is removed
    assert len(lm.get_installed()) == 2

    # update to the latest
    lm = LibraryPackageManager(str(storage_dir))
    pkg = lm.update("ArduinoJson", silent=True)
    assert pkg.metadata.version == outdated.latest
Exemple #2
0
def lib_update(  # pylint: disable=too-many-arguments
    ctx, libraries, only_check, dry_run, silent, json_output
):
    storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY]
    only_check = dry_run or only_check
    json_result = {}
    for storage_dir in storage_dirs:
        if not json_output:
            print_storage_header(storage_dirs, storage_dir)
        lib_deps = ctx.meta.get(CTX_META_STORAGE_LIBDEPS_KEY, {}).get(storage_dir, [])
        lm = LibraryPackageManager(storage_dir)
        _libraries = libraries or lib_deps or lm.get_installed()

        if only_check and json_output:
            result = []
            for library in _libraries:
                spec = None
                pkg = None
                if isinstance(library, PackageItem):
                    pkg = library
                else:
                    spec = PackageSpec(library)
                    pkg = lm.get_package(spec)
                if not pkg:
                    continue
                outdated = lm.outdated(pkg, spec)
                if not outdated.is_outdated(allow_incompatible=True):
                    continue
                manifest = lm.legacy_load_manifest(pkg)
                manifest["versionWanted"] = (
                    str(outdated.wanted) if outdated.wanted else None
                )
                manifest["versionLatest"] = (
                    str(outdated.latest) if outdated.latest else None
                )
                result.append(manifest)
            json_result[storage_dir] = result
        else:
            for library in _libraries:
                to_spec = (
                    None if isinstance(library, PackageItem) else PackageSpec(library)
                )
                try:
                    lm.update(
                        library, to_spec=to_spec, only_check=only_check, silent=silent
                    )
                except UnknownPackageError as e:
                    if library not in lib_deps:
                        raise e

    if json_output:
        return click.echo(
            dump_json_to_unicode(
                json_result[storage_dirs[0]] if len(storage_dirs) == 1 else json_result
            )
        )

    return True
Exemple #3
0
def test_update_without_metadata(isolated_pio_core, tmpdir_factory):
    storage_dir = tmpdir_factory.mktemp("storage")
    storage_dir.join("legacy-package").mkdir().join("library.json").write(
        '{"name": "AsyncMqttClient-esphome", "version": "0.8"}')
    storage_dir.join("legacy-dep").mkdir().join("library.json").write(
        '{"name": "AsyncTCP-esphome", "version": "1.1.1"}')
    lm = LibraryPackageManager(str(storage_dir))
    pkg = lm.get_package("AsyncMqttClient-esphome")
    outdated = lm.outdated(pkg)
    assert len(lm.get_installed()) == 2
    assert str(pkg.metadata.version) == "0.8.0"
    assert outdated.latest > semantic_version.Version("0.8.0")

    # update
    lm = LibraryPackageManager(str(storage_dir))
    new_pkg = lm.update(pkg, silent=True)
    assert len(lm.get_installed()) == 3
    assert new_pkg.metadata.spec.owner == "ottowinter"