forked from platformio/platformio-core
Fix updating project libraries // Resolve #745
This commit is contained in:
@ -47,8 +47,11 @@ def cli(ctx, **options):
|
|||||||
(len(ctx.args) == 2 and ctx.args[1] in ("-h", "--help")):
|
(len(ctx.args) == 2 and ctx.args[1] in ("-h", "--help")):
|
||||||
return
|
return
|
||||||
storage_dir = options['storage_dir']
|
storage_dir = options['storage_dir']
|
||||||
if not storage_dir and options['global']:
|
if not storage_dir:
|
||||||
storage_dir = join(util.get_home_dir(), "lib")
|
if options['global']:
|
||||||
|
storage_dir = join(util.get_home_dir(), "lib")
|
||||||
|
elif util.is_platformio_project():
|
||||||
|
storage_dir = util.get_projectlibdeps_dir()
|
||||||
|
|
||||||
if not storage_dir and not util.is_platformio_project():
|
if not storage_dir and not util.is_platformio_project():
|
||||||
raise exception.PlatformioException(
|
raise exception.PlatformioException(
|
||||||
@ -59,7 +62,8 @@ def cli(ctx, **options):
|
|||||||
ctx.invoked_subcommand))
|
ctx.invoked_subcommand))
|
||||||
|
|
||||||
ctx.obj = LibraryManager(storage_dir)
|
ctx.obj = LibraryManager(storage_dir)
|
||||||
click.echo("Library Storage: " + storage_dir)
|
if "--json-output" not in ctx.args:
|
||||||
|
click.echo("Library Storage: " + storage_dir)
|
||||||
|
|
||||||
|
|
||||||
@cli.command("install", short_help="Install library")
|
@cli.command("install", short_help="Install library")
|
||||||
|
@ -357,7 +357,10 @@ class BasePkgManager(PkgRepoMixin, PkgInstallerMixin):
|
|||||||
return BasePkgManager._INSTALLED_CACHE[self.package_dir]
|
return BasePkgManager._INSTALLED_CACHE[self.package_dir]
|
||||||
items = []
|
items = []
|
||||||
for p in sorted(os.listdir(self.package_dir)):
|
for p in sorted(os.listdir(self.package_dir)):
|
||||||
manifest = self.load_manifest(join(self.package_dir, p))
|
pkg_dir = join(self.package_dir, p)
|
||||||
|
if not isdir(pkg_dir):
|
||||||
|
continue
|
||||||
|
manifest = self.load_manifest(pkg_dir)
|
||||||
if not manifest:
|
if not manifest:
|
||||||
continue
|
continue
|
||||||
assert set(["name", "version"]) <= set(manifest.keys())
|
assert set(["name", "version"]) <= set(manifest.keys())
|
||||||
|
@ -12,18 +12,23 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
import re
|
import re
|
||||||
|
from os.path import basename
|
||||||
|
|
||||||
from platformio.commands.lib import cli
|
from platformio import util
|
||||||
|
from platformio.commands.init import cli as cmd_init
|
||||||
|
from platformio.commands.lib import cli as cmd_lib
|
||||||
|
|
||||||
|
|
||||||
def test_search(clirunner, validate_cliresult):
|
def test_search(clirunner, validate_cliresult):
|
||||||
result = clirunner.invoke(cli, ["search", "DHT22"])
|
result = clirunner.invoke(cmd_lib, ["search", "DHT22"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
match = re.search(r"Found\s+(\d+)\slibraries:", result.output)
|
match = re.search(r"Found\s+(\d+)\slibraries:", result.output)
|
||||||
assert int(match.group(1)) > 2
|
assert int(match.group(1)) > 2
|
||||||
|
|
||||||
result = clirunner.invoke(cli, ["search", "DHT22", "--platform=timsp430"])
|
result = clirunner.invoke(cmd_lib,
|
||||||
|
["search", "DHT22", "--platform=timsp430"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
match = re.search(r"Found\s+(\d+)\slibraries:", result.output)
|
match = re.search(r"Found\s+(\d+)\slibraries:", result.output)
|
||||||
assert int(match.group(1)) == 1
|
assert int(match.group(1)) == 1
|
||||||
@ -32,7 +37,7 @@ def test_search(clirunner, validate_cliresult):
|
|||||||
def test_global_install_registry(clirunner, validate_cliresult,
|
def test_global_install_registry(clirunner, validate_cliresult,
|
||||||
isolated_pio_home):
|
isolated_pio_home):
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cli, ["-g", "install", "58", "OneWire", "Json@5.4.0", "Json@>5.4"])
|
cmd_lib, ["-g", "install", "58", "OneWire", "Json@5.4.0", "Json@>5.4"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
items1 = [d.basename for d in isolated_pio_home.join("lib").listdir()]
|
items1 = [d.basename for d in isolated_pio_home.join("lib").listdir()]
|
||||||
items2 = ["DHT22_ID58", "Json_ID64", "Json_ID64@5.4.0", "OneWire_ID1"]
|
items2 = ["DHT22_ID58", "Json_ID64", "Json_ID64@5.4.0", "OneWire_ID1"]
|
||||||
@ -42,10 +47,10 @@ def test_global_install_registry(clirunner, validate_cliresult,
|
|||||||
def test_global_install_repository(clirunner, validate_cliresult,
|
def test_global_install_repository(clirunner, validate_cliresult,
|
||||||
isolated_pio_home):
|
isolated_pio_home):
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cli, ["-g", "install", "https://github.com/gioblu/PJON.git#3.0",
|
cmd_lib, ["-g", "install", "https://github.com/gioblu/PJON.git#3.0",
|
||||||
"https://developer.mbed.org/users/simon/code/TextLCD/",
|
"https://developer.mbed.org/users/simon/code/TextLCD/",
|
||||||
"http://dl.platformio.org/libraries/archives/3/3756.tar.gz",
|
"http://dl.platformio.org/libraries/archives/3/3756.tar.gz",
|
||||||
"knolleary/pubsubclient"])
|
"knolleary/pubsubclient"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
items1 = [d.basename for d in isolated_pio_home.join("lib").listdir()]
|
items1 = [d.basename for d in isolated_pio_home.join("lib").listdir()]
|
||||||
items2 = ["PJON", "TextLCD", "ESPAsyncTCP", "PubSubClient"]
|
items2 = ["PJON", "TextLCD", "ESPAsyncTCP", "PubSubClient"]
|
||||||
@ -53,36 +58,39 @@ def test_global_install_repository(clirunner, validate_cliresult,
|
|||||||
|
|
||||||
|
|
||||||
def test_global_lib_list(clirunner, validate_cliresult, isolated_pio_home):
|
def test_global_lib_list(clirunner, validate_cliresult, isolated_pio_home):
|
||||||
result = clirunner.invoke(cli, ["-g", "list"])
|
result = clirunner.invoke(cmd_lib, ["-g", "list"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert all([n in result.output for n in ("OneWire", "DHT22", "64")])
|
assert all([n in result.output for n in ("OneWire", "DHT22", "64")])
|
||||||
|
|
||||||
result = clirunner.invoke(cli, ["-g", "list", "--json-output"])
|
result = clirunner.invoke(cmd_lib, ["-g", "list", "--json-output"])
|
||||||
validate_cliresult(result)
|
|
||||||
assert all(
|
assert all(
|
||||||
[n in result.output
|
[n in result.output
|
||||||
for n in ("PJON",
|
for n in ("PJON",
|
||||||
"https://developer.mbed.org/users/simon/code/TextLCD/")])
|
"https://developer.mbed.org/users/simon/code/TextLCD/")])
|
||||||
|
items1 = [i['name'] for i in json.loads(result.output)]
|
||||||
|
items2 = ["OneWire", "DHT22", "PJON", "ESPAsyncTCP", "Json", "TextLCD",
|
||||||
|
"pubsubclient"]
|
||||||
|
assert set(items1) == set(items2)
|
||||||
|
|
||||||
|
|
||||||
def test_global_lib_show(clirunner, validate_cliresult, isolated_pio_home):
|
def test_global_lib_show(clirunner, validate_cliresult, isolated_pio_home):
|
||||||
result = clirunner.invoke(cli, ["-g", "show", "64@5.4.0"])
|
result = clirunner.invoke(cmd_lib, ["-g", "show", "64@5.4.0"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert all(
|
assert all(
|
||||||
[s in result.output for s in ("Json", "arduino", "atmelavr", "5.4.0")])
|
[s in result.output for s in ("Json", "arduino", "atmelavr", "5.4.0")])
|
||||||
|
|
||||||
result = clirunner.invoke(cli, ["-g", "show", "Json@>5.4.0"])
|
result = clirunner.invoke(cmd_lib, ["-g", "show", "Json@>5.4.0"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert all([s in result.output for s in ("Json", "arduino", "atmelavr")])
|
assert all([s in result.output for s in ("Json", "arduino", "atmelavr")])
|
||||||
assert "5.4.0" not in result.output
|
assert "5.4.0" not in result.output
|
||||||
|
|
||||||
result = clirunner.invoke(cli, ["-g", "show", "1"])
|
result = clirunner.invoke(cmd_lib, ["-g", "show", "1"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert "OneWire" in result.output
|
assert "OneWire" in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_global_lib_update(clirunner, validate_cliresult, isolated_pio_home):
|
def test_global_lib_update(clirunner, validate_cliresult, isolated_pio_home):
|
||||||
result = clirunner.invoke(cli, ["-g", "update"])
|
result = clirunner.invoke(cmd_lib, ["-g", "update"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert all([s in result.output for s in ("[Up-to-date]", "[VCS]")])
|
assert all([s in result.output for s in ("[Up-to-date]", "[VCS]")])
|
||||||
|
|
||||||
@ -90,9 +98,37 @@ def test_global_lib_update(clirunner, validate_cliresult, isolated_pio_home):
|
|||||||
def test_global_lib_uninstall(clirunner, validate_cliresult,
|
def test_global_lib_uninstall(clirunner, validate_cliresult,
|
||||||
isolated_pio_home):
|
isolated_pio_home):
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cli, ["-g", "uninstall", "1", "Json@!=5.4.0", "TextLCD"])
|
cmd_lib, ["-g", "uninstall", "1", "Json@!=5.4.0", "TextLCD"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
items1 = [d.basename for d in isolated_pio_home.join("lib").listdir()]
|
items1 = [d.basename for d in isolated_pio_home.join("lib").listdir()]
|
||||||
items2 = ["DHT22_ID58", "Json_ID64@5.4.0", "ESPAsyncTCP_ID305",
|
items2 = ["DHT22_ID58", "Json_ID64@5.4.0", "ESPAsyncTCP_ID305",
|
||||||
"pubsubclient", "PJON"]
|
"pubsubclient", "PJON"]
|
||||||
assert set(items1) == set(items2)
|
assert set(items1) == set(items2)
|
||||||
|
|
||||||
|
|
||||||
|
def test_project_lib_complex(clirunner, validate_cliresult, tmpdir):
|
||||||
|
with util.cd(str(tmpdir)):
|
||||||
|
# init
|
||||||
|
result = clirunner.invoke(cmd_init)
|
||||||
|
validate_cliresult(result)
|
||||||
|
|
||||||
|
# isntall
|
||||||
|
result = clirunner.invoke(cmd_lib, ["install", "54", "Json"])
|
||||||
|
validate_cliresult(result)
|
||||||
|
items1 = [d.basename
|
||||||
|
for d in tmpdir.join(basename(util.get_projectlibdeps_dir(
|
||||||
|
))).listdir()]
|
||||||
|
items2 = ["DallasTemperature_ID54", "OneWire_ID1", "Json_ID64"]
|
||||||
|
assert set(items1) == set(items2)
|
||||||
|
|
||||||
|
# list
|
||||||
|
result = clirunner.invoke(cmd_lib, ["list", "--json-output"])
|
||||||
|
validate_cliresult(result)
|
||||||
|
items1 = [i['name'] for i in json.loads(result.output)]
|
||||||
|
items2 = ["DallasTemperature", "OneWire", "Json"]
|
||||||
|
assert set(items1) == set(items2)
|
||||||
|
|
||||||
|
# update
|
||||||
|
result = clirunner.invoke(cmd_lib, ["update"])
|
||||||
|
validate_cliresult(result)
|
||||||
|
assert "[Up-to-date]" in result.output
|
||||||
|
Reference in New Issue
Block a user