From 5cc21511ad2a9a8de560f0bb8e32bf45b3f2fd8c Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 2 Sep 2020 16:07:16 +0300 Subject: [PATCH] Show owner name for packages --- platformio/commands/lib/command.py | 7 ++--- platformio/commands/lib/helpers.py | 5 +++- platformio/commands/platform.py | 8 +++--- platformio/package/manager/_legacy.py | 2 ++ platformio/project/config.py | 6 +++++ tests/commands/test_lib.py | 37 ++++++++++++++++++++++----- 6 files changed, 51 insertions(+), 14 deletions(-) diff --git a/platformio/commands/lib/command.py b/platformio/commands/lib/command.py index d871c917..23a5b46e 100644 --- a/platformio/commands/lib/command.py +++ b/platformio/commands/lib/command.py @@ -450,12 +450,13 @@ def lib_show(library, json_output): if json_output: return click.echo(dump_json_to_unicode(lib)) - click.secho(lib["name"], fg="cyan") - click.echo("=" * len(lib["name"])) - click.secho("#ID: %d" % lib["id"], bold=True) + title = "{ownername}/{name}".format(**lib) + click.secho(title, fg="cyan") + click.echo("=" * len(title)) click.echo(lib["description"]) click.echo() + click.secho("ID: %d" % lib["id"]) click.echo( "Version: %s, released %s" % ( diff --git a/platformio/commands/lib/helpers.py b/platformio/commands/lib/helpers.py index a5b0e260..7a156e0f 100644 --- a/platformio/commands/lib/helpers.py +++ b/platformio/commands/lib/helpers.py @@ -87,5 +87,8 @@ def save_project_libdeps(project_dir, specs, environments=None, action="add"): pass if action == "add": lib_deps.extend(spec.as_dependency() for spec in specs) - config.set("env:" + env, "lib_deps", lib_deps) + if lib_deps: + config.set("env:" + env, "lib_deps", lib_deps) + elif config.has_option("env:" + env, "lib_deps"): + config.remove_option("env:" + env, "lib_deps") config.save() diff --git a/platformio/commands/platform.py b/platformio/commands/platform.py index 588e7ccc..054a7a12 100644 --- a/platformio/commands/platform.py +++ b/platformio/commands/platform.py @@ -140,6 +140,7 @@ def _get_registry_platform_data( # pylint: disable=unused-argument return None data = dict( + ownername=_data.get("ownername"), name=_data["name"], title=_data["title"], description=_data["description"], @@ -242,12 +243,11 @@ def platform_show(platform, json_output): # pylint: disable=too-many-branches if json_output: return click.echo(dump_json_to_unicode(data)) + dep = "{ownername}/{name}".format(**data) if "ownername" in data else data["name"] click.echo( - "{name} ~ {title}".format( - name=click.style(data["name"], fg="cyan"), title=data["title"] - ) + "{dep} ~ {title}".format(dep=click.style(dep, fg="cyan"), title=data["title"]) ) - click.echo("=" * (3 + len(data["name"] + data["title"]))) + click.echo("=" * (3 + len(dep + data["title"]))) click.echo(data["description"]) click.echo() if "version" in data: diff --git a/platformio/package/manager/_legacy.py b/platformio/package/manager/_legacy.py index 95f628d0..5c35ebeb 100644 --- a/platformio/package/manager/_legacy.py +++ b/platformio/package/manager/_legacy.py @@ -53,6 +53,8 @@ class PackageManagerLegacyMixin(object): 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) + if pkg.metadata and pkg.metadata.spec.owner: + manifest["ownername"] = pkg.metadata.spec.owner return manifest def legacy_get_installed(self): diff --git a/platformio/project/config.py b/platformio/project/config.py index 786f080a..2d841b39 100644 --- a/platformio/project/config.py +++ b/platformio/project/config.py @@ -358,6 +358,12 @@ class ProjectConfigBase(object): click.secho("Warning! %s" % warning, fg="yellow") return True + def remove_option(self, section, option): + return self._parser.remove_option(section, option) + + def remove_section(self, section): + return self._parser.remove_section(section) + class ProjectConfigDirsMixin(object): def _get_core_dir(self, exists=False): diff --git a/tests/commands/test_lib.py b/tests/commands/test_lib.py index 332161e1..b077f63b 100644 --- a/tests/commands/test_lib.py +++ b/tests/commands/test_lib.py @@ -44,16 +44,21 @@ lib_deps = ArduinoJson @ 5.10.1 """ ) - result = clirunner.invoke(cmd_lib, ["-d", str(project_dir), "install", "64"]) + result = clirunner.invoke( + cmd_lib, + ["-d", str(project_dir), "install", "64", "knolleary/PubSubClient@~2.7"], + ) validate_cliresult(result) aj_pkg_data = regclient.get_package(PackageType.LIBRARY, "bblanchon", "ArduinoJson") config = ProjectConfig(os.path.join(str(project_dir), "platformio.ini")) assert config.get("env:one", "lib_deps") == [ - "bblanchon/ArduinoJson@^%s" % aj_pkg_data["version"]["name"] + "bblanchon/ArduinoJson@^%s" % aj_pkg_data["version"]["name"], + "knolleary/PubSubClient@~2.7", ] assert config.get("env:two", "lib_deps") == [ "CustomLib", "bblanchon/ArduinoJson@^%s" % aj_pkg_data["version"]["name"], + "knolleary/PubSubClient@~2.7", ] # ensure "build" version without NPM spec @@ -68,6 +73,7 @@ lib_deps = config = ProjectConfig(os.path.join(str(project_dir), "platformio.ini")) assert config.get("env:one", "lib_deps") == [ "bblanchon/ArduinoJson@^%s" % aj_pkg_data["version"]["name"], + "knolleary/PubSubClient@~2.7", "mbed-sam-grove/LinkedList@%s" % ll_pkg_data["version"]["name"], ] @@ -85,23 +91,41 @@ lib_deps = ) validate_cliresult(result) config = ProjectConfig(os.path.join(str(project_dir), "platformio.ini")) - assert len(config.get("env:one", "lib_deps")) == 3 - assert config.get("env:one", "lib_deps")[2] == ( + assert len(config.get("env:one", "lib_deps")) == 4 + assert config.get("env:one", "lib_deps")[3] == ( "https://github.com/OttoWinter/async-mqtt-client.git#v0.8.3 @ 0.8.3" ) # test uninstalling + # from all envs result = clirunner.invoke( cmd_lib, ["-d", str(project_dir), "uninstall", "ArduinoJson"] ) validate_cliresult(result) + # from "one" env + result = clirunner.invoke( + cmd_lib, + [ + "-d", + str(project_dir), + "-e", + "one", + "uninstall", + "knolleary/PubSubClient@~2.7", + ], + ) + validate_cliresult(result) config = ProjectConfig(os.path.join(str(project_dir), "platformio.ini")) assert len(config.get("env:one", "lib_deps")) == 2 - assert len(config.get("env:two", "lib_deps")) == 1 + assert len(config.get("env:two", "lib_deps")) == 2 assert config.get("env:one", "lib_deps") == [ "mbed-sam-grove/LinkedList@%s" % ll_pkg_data["version"]["name"], "https://github.com/OttoWinter/async-mqtt-client.git#v0.8.3 @ 0.8.3", ] + assert config.get("env:two", "lib_deps") == [ + "CustomLib", + "knolleary/PubSubClient@~2.7", + ] # test list result = clirunner.invoke(cmd_lib, ["-d", str(project_dir), "list"]) @@ -122,7 +146,8 @@ lib_deps = item for item in data["one"] if item["name"] == "AsyncMqttClient-esphome" ) ame_vcs = VCSClientFactory.new(ame_lib["__pkg_dir"], ame_lib["__src_url"]) - assert data["two"] == [] + assert len(data["two"]) == 1 + assert data["two"][0]["name"] == "PubSubClient" assert "__pkg_dir" in data["one"][0] assert ( ame_lib["__src_url"]