Show owner name for packages

This commit is contained in:
Ivan Kravets
2020-09-02 16:07:16 +03:00
parent 2edd7ae649
commit 5cc21511ad
6 changed files with 51 additions and 14 deletions

View File

@ -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"
% (

View File

@ -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()

View File

@ -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:

View File

@ -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):

View File

@ -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):

View File

@ -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"]