Skip to content

Commit

Permalink
feat: allow installing git+ prefix w/o name@ prefix (#2317)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 14, 2024
1 parent 3f35535 commit bee4889
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/userguides/installing_plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ Or from the CLI like:
ape plugins install "foobar@git+https://github.com/<owner-of-plugin>/ape-foobar.git@<branch/name>"
```

Also, you may omit the `foobar@` prefix and allow Ape to deduce the name:

```shell
ape plugins install "git+https://github.com/<owner-of-plugin>/ape-foobar.git@<branch/name>"
```

## Plugin Versions

By default, `ape plugins` commands install plugins within your current Ape version specification.
Expand Down
10 changes: 10 additions & 0 deletions src/ape/plugins/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions tests/functional/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bee4889

Please sign in to comment.