diff --git a/docs/userguides/installing_plugins.md b/docs/userguides/installing_plugins.md index 892496a6ff..4eb15b1ff1 100644 --- a/docs/userguides/installing_plugins.md +++ b/docs/userguides/installing_plugins.md @@ -67,6 +67,12 @@ Or from the CLI like: ape plugins install "foobar@git+https://github.com//ape-foobar.git@" ``` +Also, you may omit the `foobar@` prefix and allow Ape to deduce the name: + +```shell +ape plugins install "git+https://github.com//ape-foobar.git@" +``` + ## Plugin Versions By default, `ape plugins` commands install plugins within your current Ape version specification. diff --git a/src/ape/plugins/_utils.py b/src/ape/plugins/_utils.py index 43d98eb666..af0b1c1665 100644 --- a/src/ape/plugins/_utils.py +++ b/src/ape/plugins/_utils.py @@ -5,6 +5,7 @@ from functools import cached_property from shutil import which from typing import Any, Optional +from urllib.parse import urlparse import click from packaging.specifiers import SpecifierSet @@ -259,6 +260,15 @@ def validate_name(cls, values): name = values["name"] version = values.get("version") + if name.startswith("git+"): + version = name + name = ( + urlparse(version.replace("git+", "")) + .path.split(".git")[0] + .split("/")[-1] + .replace("ape-", "") + ) + if version and version.startswith("git+"): if f"ape-{name}" not in version: # Just some small validation so you can't put a repo diff --git a/tests/functional/test_plugins.py b/tests/functional/test_plugins.py index 89b9531aa3..409929eda6 100644 --- a/tests/functional/test_plugins.py +++ b/tests/functional/test_plugins.py @@ -152,17 +152,26 @@ def test_install_str_with_complex_constraint_in_name(self): assert actual == f"ape-foo>=0.{ape_version.minor}.0,<0.{ape_version.minor + 1}.0" def test_install_str_when_using_git_remote(self): - url = "git+https://example.com/ape-foo/branch" + url = "git+https://example.com/myorg/ape-foo.git@branch_name" metadata = PluginMetadata(name="foo", version=url) + assert metadata.name == "foo" actual = metadata.install_str assert actual == url def test_install_str_remote_in_name(self): - url = "git+https://example.com/ape-foo/branch" + url = "git+https://example.com/myorg/ape-foo.git@branch_name" metadata = PluginMetadata(name=f"foo@{url}") + assert metadata.name == "foo" actual = metadata.install_str assert actual == url + def test_install_str_only_remote(self): + url = "git+https://example.com/myorg/ape-foo.git@branch_name" + metadata = PluginMetadata(name=url) + actual = metadata.install_str + assert actual == url + assert metadata.name == "foo" + def test_is_available(self): metadata = PluginMetadata(name=list(AVAILABLE_PLUGINS)[0]) assert metadata.is_available