def lib_install( # pylint: disable=too-many-arguments 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_manifests = {} 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 = LibraryManager(storage_dir) if libraries: for library in libraries: pkg_dir = lm.install(library, silent=silent, interactive=interactive, force=force) installed_manifests[library] = lm.load_manifest(pkg_dir) elif storage_dir in storage_libdeps: builtin_lib_storages = None for library in storage_libdeps[storage_dir]: try: pkg_dir = lm.install(library, silent=silent, interactive=interactive, force=force) installed_manifests[library] = lm.load_manifest(pkg_dir) except exception.LibNotFound 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 not save or not libraries: return input_dirs = ctx.meta.get(CTX_META_INPUT_DIRS_KEY, []) project_environments = ctx.meta[CTX_META_PROJECT_ENVIRONMENTS_KEY] for input_dir in input_dirs: config = ProjectConfig.get_instance( os.path.join(input_dir, "platformio.ini")) config.validate(project_environments) for env in config.envs(): if project_environments and env not in project_environments: continue config.expand_interpolations = False lib_deps = config.get("env:" + env, "lib_deps", []) for library in libraries: if library in lib_deps: continue manifest = installed_manifests[library] try: assert library.lower() == manifest["name"].lower() assert semantic_version.Version(manifest["version"]) lib_deps.append("{name}@^{version}".format(**manifest)) except (AssertionError, ValueError): lib_deps.append(library) config.set("env:" + env, "lib_deps", lib_deps) config.save()
def _autoinstall_libdeps(ctx, libraries, verbose=False): if not libraries: return storage_dir = util.get_projectlibdeps_dir() ctx.obj = LibraryManager(storage_dir) if verbose: click.echo("Library Storage: " + storage_dir) for lib in libraries: try: ctx.invoke(cmd_lib_install, libraries=[lib], silent=not verbose) except exception.LibNotFound as e: if verbose or not is_builtin_lib(lib): click.secho("Warning! %s" % e, fg="yellow") except exception.InternetIsOffline as e: click.secho(str(e), fg="yellow")
def _autoinstall_libdeps(ctx, libraries, verbose=False): if not libraries: return storage_dir = util.get_projectlibdeps_dir() ctx.obj = LibraryManager(storage_dir) if verbose: click.echo("Library Storage: " + storage_dir) for lib in libraries: try: ctx.invoke(cmd_lib_install, libraries=[lib], silent=not verbose) except exception.LibNotFound as e: if verbose or not is_builtin_lib(lib): click.secho("Warning! %s" % e, fg="yellow") except exception.InternetIsOffline as e: click.secho(str(e), fg="yellow")