def install_dependencies(self): def _is_builtin(spec): for lb in self.env.GetLibBuilders(): if lb.name == spec: return True return False not_found_specs = [] for spec in self.dependencies: # check if built-in library if _is_builtin(spec): continue found = False for storage_dir in self.env.GetLibSourceDirs(): lm = LibraryPackageManager(storage_dir) if lm.get_package(spec): found = True break if not found: not_found_specs.append(spec) did_install = False lm = LibraryPackageManager( self.env.subst(os.path.join("$PROJECT_LIBDEPS_DIR", "$PIOENV"))) for spec in not_found_specs: try: lm.install(spec) did_install = True except (UnknownPackageError, InternetIsOffline) as e: click.secho("Warning! %s" % e, fg="yellow") # reset cache if did_install: DefaultEnvironment().Replace(__PIO_LIB_BUILDERS=None)
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)
def lib_install( # pylint: disable=too-many-arguments,unused-argument ctx, libraries, save, silent, interactive, force ): storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY] storage_libdeps = ctx.meta.get(CTX_META_STORAGE_LIBDEPS_KEY, []) installed_pkgs = {} for storage_dir in storage_dirs: if not silent and (libraries or storage_dir in storage_libdeps): print_storage_header(storage_dirs, storage_dir) lm = LibraryPackageManager(storage_dir) if libraries: installed_pkgs = { library: lm.install(library, silent=silent, force=force) for library in libraries } elif storage_dir in storage_libdeps: builtin_lib_storages = None for library in storage_libdeps[storage_dir]: try: lm.install(library, silent=silent, force=force) except UnknownPackageError as e: if builtin_lib_storages is None: builtin_lib_storages = get_builtin_libs() if not silent or not is_builtin_lib(builtin_lib_storages, library): click.secho("Warning! %s" % e, fg="yellow") if save and installed_pkgs: _save_deps(ctx, installed_pkgs)
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
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
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)
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() ]
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()
def lib_install( # pylint: disable=too-many-arguments,unused-argument ctx, libraries, save, silent, interactive, force ): storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY] storage_libdeps = ctx.meta.get(CTX_META_STORAGE_LIBDEPS_KEY, []) installed_pkgs = {} for storage_dir in storage_dirs: if not silent and (libraries or storage_dir in storage_libdeps): print_storage_header(storage_dirs, storage_dir) lm = LibraryPackageManager(storage_dir) if libraries: installed_pkgs = { library: lm.install(library, silent=silent, force=force) for library in libraries } elif storage_dir in storage_libdeps: for library in storage_libdeps[storage_dir]: lm.install(library, silent=silent, force=force) if save and installed_pkgs: _save_deps(ctx, installed_pkgs)