From e2d229586694da4f4ac0a3463151493e0a820980 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 3 Sep 2016 01:27:34 +0300 Subject: [PATCH] Handle url with ".git" extension as Git package/library --- platformio/__init__.py | 2 +- platformio/managers/package.py | 16 ++++++++++++---- tests/commands/test_lib.py | 5 +++-- tests/test_managers.py | 2 ++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/platformio/__init__.py b/platformio/__init__.py index 7852e081..0ba9b049 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -14,7 +14,7 @@ import sys -VERSION = (3, 0, "0b9") +VERSION = (3, 0, "0b10") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/managers/package.py b/platformio/managers/package.py index 39626f76..14e9644f 100644 --- a/platformio/managers/package.py +++ b/platformio/managers/package.py @@ -324,13 +324,19 @@ class BasePkgManager(PkgRepoMixin, PkgInstallerMixin): if "=" in text and not text.startswith("id="): name, url = text.split("=", 1) - # Handle GitHub URL (https://github.com/user/package) - if url.startswith("https://github.com/") and \ - not url.endswith((".zip", ".tar.gz")): + git_conditions = [ + # Handle GitHub URL (https://github.com/user/package) + url.startswith("https://github.com/") and not url.endswith( + (".zip", ".tar.gz")), + url.startswith("http") and + (url.split("#", 1)[0] if "#" in url else url).endswith(".git") + ] + + if any(git_conditions): url = "git+" + url # Handle Developer Mbed URL # (https://developer.mbed.org/users/user/code/package/) - if url.startswith("https://developer.mbed.org"): + elif url.startswith("https://developer.mbed.org"): url = "hg+" + url # git@github.com:user/package.git @@ -342,6 +348,8 @@ class BasePkgManager(PkgRepoMixin, PkgInstallerMixin): url = "file://" + url elif url.count("/") == 1 and not url.startswith("git@"): url = "git+https://github.com/" + url + + # determine name if url_marker in url and not name: _url = url.split("#", 1)[0] if "#" in url else url if _url.endswith(("\\", "/")): diff --git a/tests/commands/test_lib.py b/tests/commands/test_lib.py index af9d60da..0daae542 100644 --- a/tests/commands/test_lib.py +++ b/tests/commands/test_lib.py @@ -52,6 +52,7 @@ def test_global_install_repository(clirunner, validate_cliresult, ["-g", "install", "https://github.com/gioblu/PJON.git#3.0", + "https://gitlab.com/ivankravets/rs485-nodeproto.git", # "https://developer.mbed.org/users/simon/code/TextLCD/", "http://dl.platformio.org/libraries/archives/3/3756.tar.gz", "knolleary/pubsubclient"]) @@ -72,7 +73,7 @@ def test_global_lib_list(clirunner, validate_cliresult, isolated_pio_home): for n in ("PJON", "git+https://github.com/knolleary/pubsubclient")]) items1 = [i['name'] for i in json.loads(result.output)] items2 = ["OneWire", "DHT22", "PJON", "ESPAsyncTCP", "Json", "ArduinoJson", - "pubsubclient"] + "pubsubclient", "rs485-nodeproto"] assert set(items1) == set(items2) @@ -106,7 +107,7 @@ def test_global_lib_uninstall(clirunner, validate_cliresult, validate_cliresult(result) items1 = [d.basename for d in isolated_pio_home.join("lib").listdir()] items2 = ["DHT22_ID58", "Json_ID64", "ESPAsyncTCP_ID305", "pubsubclient", - "PJON"] + "PJON", "rs485-nodeproto"] assert set(items1) == set(items2) diff --git a/tests/test_managers.py b/tests/test_managers.py index f41c31a1..f99038e6 100644 --- a/tests/test_managers.py +++ b/tests/test_managers.py @@ -30,6 +30,8 @@ def test_pkg_name_parser(): ("LocalName", None, "file://" + util.get_home_dir())], ["https://github.com/user/package.git", ("package", None, "git+https://github.com/user/package.git")], + ["https://gitlab.com/user/package.git", + ("package", None, "git+https://gitlab.com/user/package.git")], ["https://github.com/user/package/archive/branch.zip", ("branch", None, "https://github.com/user/package/archive/branch.zip")],