Beispiel #1
0
def test_install_from_registry(isolated_pio_core, tmpdir_factory):
    # Libraries
    lm = LibraryPackageManager(str(tmpdir_factory.mktemp("lib-storage")))
    # library with dependencies
    lm.install("AsyncMqttClient-esphome @ 0.8.4", silent=True)
    assert len(lm.get_installed()) == 3
    pkg = lm.get_package("AsyncTCP-esphome")
    assert pkg.metadata.spec.owner == "ottowinter"
    assert not lm.get_package("non-existing-package")
    # mbed library
    assert lm.install("wolfSSL", silent=True)
    assert len(lm.get_installed()) == 4
    # case sensitive author name
    assert lm.install("DallasTemperature", silent=True)
    assert lm.get_package("OneWire").metadata.version.major >= 2
    assert len(lm.get_installed()) == 6

    # test conflicted names
    lm = LibraryPackageManager(str(tmpdir_factory.mktemp("conflicted-storage")))
    lm.install("[email protected]", silent=True)
    lm.install("[email protected]", silent=True)
    assert len(lm.get_installed()) == 2

    # Tools
    tm = ToolPackageManager(str(tmpdir_factory.mktemp("tool-storage")))
    pkg = tm.install("platformio/tool-stlink @ ~1.10400.0", silent=True)
    manifest = tm.load_manifest(pkg)
    assert tm.is_system_compatible(manifest.get("system"))
    assert util.get_systype() in manifest.get("system", [])

    # Test unknown
    with pytest.raises(UnknownPackageError):
        tm.install("unknown-package-tool @ 9.1.1", silent=True)
    with pytest.raises(UnknownPackageError):
        tm.install("owner/unknown-package-tool", silent=True)
Beispiel #2
0
def test_install_force(isolated_pio_core, tmpdir_factory):
    lm = LibraryPackageManager(str(tmpdir_factory.mktemp("lib-storage")))
    # install #64 ArduinoJson
    pkg = lm.install("64 @ ^5", silent=True)
    assert pkg.metadata.version.major == 5
    # try install the latest without specification
    pkg = lm.install("64", silent=True)
    assert pkg.metadata.version.major == 5
    assert len(lm.get_installed()) == 1
    # re-install the latest
    pkg = lm.install(64, silent=True, force=True)
    assert len(lm.get_installed()) == 1
    assert pkg.metadata.version.major > 5
Beispiel #3
0
def test_install_lib_depndencies(isolated_pio_core, tmpdir_factory):
    tmp_dir = tmpdir_factory.mktemp("tmp")

    src_dir = tmp_dir.join("lib-with-deps").mkdir()
    root_dir = src_dir.mkdir("root")
    root_dir.mkdir("src").join("main.cpp").write("#include <stdio.h>")
    root_dir.join("library.json").write("""
{
  "name": "lib-with-deps",
  "version": "2.0.0",
  "dependencies": [
    {
      "owner": "bblanchon",
      "name": "ArduinoJson",
      "version": "^6.16.1"
    },
    {
      "name": "external-repo",
      "version": "https://github.com/milesburton/Arduino-Temperature-Control-Library.git#4a0ccc1"
    }
  ]
}
""")

    lm = LibraryPackageManager(str(tmpdir_factory.mktemp("lib-storage")))
    lm.install("file://%s" % str(src_dir), silent=True)
    installed = lm.get_installed()
    assert len(installed) == 4
    assert set(["external-repo", "ArduinoJson", "lib-with-deps",
                "OneWire"]) == set(p.metadata.name for p in installed)
Beispiel #4
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
Beispiel #5
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
Beispiel #6
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"
Beispiel #7
0
def test_install_from_url(isolated_pio_core, tmpdir_factory):
    tmp_dir = tmpdir_factory.mktemp("tmp")
    storage_dir = tmpdir_factory.mktemp("storage")
    lm = LibraryPackageManager(str(storage_dir))

    # install from local directory
    src_dir = tmp_dir.join("local-lib-dir").mkdir()
    src_dir.join("main.cpp").write("")
    spec = PackageSpec("file://%s" % src_dir)
    pkg = lm.install(spec, silent=True)
    assert os.path.isfile(os.path.join(pkg.path, "main.cpp"))
    manifest = lm.load_manifest(pkg)
    assert manifest["name"] == "local-lib-dir"
    assert manifest["version"].startswith("0.0.0+")
    assert spec == pkg.metadata.spec

    # install from local archive
    src_dir = tmp_dir.join("archive-src").mkdir()
    root_dir = src_dir.mkdir("root")
    root_dir.mkdir("src").join("main.cpp").write("#include <stdio.h>")
    root_dir.join("library.json").write(
        '{"name": "manifest-lib-name", "version": "2.0.0"}'
    )
    tarball_path = PackagePacker(str(src_dir)).pack(str(tmp_dir))
    spec = PackageSpec("file://%s" % tarball_path)
    pkg = lm.install(spec, silent=True)
    assert os.path.isfile(os.path.join(pkg.path, "src", "main.cpp"))
    assert pkg == lm.get_package(spec)
    assert spec == pkg.metadata.spec

    # install from registry
    src_dir = tmp_dir.join("registry-1").mkdir()
    src_dir.join("library.properties").write(
        """
name = wifilib
version = 5.2.7
"""
    )
    spec = PackageSpec("company/wifilib @ ^5")
    pkg = lm.install_from_url("file://%s" % src_dir, spec)
    assert str(pkg.metadata.version) == "5.2.7"

    # check package folder names
    lm.memcache_reset()
    assert ["local-lib-dir", "manifest-lib-name", "wifilib"] == [
        os.path.basename(pkg.path) for pkg in lm.get_installed()
    ]
Beispiel #8
0
def test_uninstall(isolated_pio_core, tmpdir_factory):
    tmp_dir = tmpdir_factory.mktemp("tmp")
    storage_dir = tmpdir_factory.mktemp("storage")
    lm = LibraryPackageManager(str(storage_dir))

    # foo @ 1.0.0
    pkg_dir = tmp_dir.join("foo").mkdir()
    pkg_dir.join("library.json").write('{"name": "foo", "version": "1.0.0"}')
    foo_1_0_0_pkg = lm.install_from_url("file://%s" % pkg_dir, "foo")
    # foo @ 1.3.0
    pkg_dir = tmp_dir.join("foo-1.3.0").mkdir()
    pkg_dir.join("library.json").write('{"name": "foo", "version": "1.3.0"}')
    lm.install_from_url("file://%s" % pkg_dir, "foo")
    # bar
    pkg_dir = tmp_dir.join("bar").mkdir()
    pkg_dir.join("library.json").write('{"name": "bar", "version": "1.0.0"}')
    bar_pkg = lm.install("file://%s" % pkg_dir, silent=True)

    assert len(lm.get_installed()) == 3
    assert os.path.isdir(os.path.join(str(storage_dir), "foo"))
    assert os.path.isdir(os.path.join(str(storage_dir), "[email protected]"))

    # check detaching
    assert lm.uninstall("FOO", silent=True)
    assert len(lm.get_installed()) == 2
    assert os.path.isdir(os.path.join(str(storage_dir), "foo"))
    assert not os.path.isdir(os.path.join(str(storage_dir), "[email protected]"))

    # uninstall the rest
    assert lm.uninstall(foo_1_0_0_pkg.path, silent=True)
    assert lm.uninstall(bar_pkg, silent=True)

    assert not lm.get_installed()

    # test uninstall dependencies
    assert lm.install("AsyncMqttClient-esphome @ 0.8.4", silent=True)
    assert len(lm.get_installed()) == 3
    assert lm.uninstall("AsyncMqttClient-esphome",
                        silent=True,
                        skip_dependencies=True)
    assert len(lm.get_installed()) == 2

    lm = LibraryPackageManager(str(storage_dir))
    assert lm.install("AsyncMqttClient-esphome @ 0.8.4", silent=True)
    assert lm.uninstall("AsyncMqttClient-esphome", silent=True)
    assert not lm.get_installed()