Skip to content

Commit

Permalink
fix: issue where using version: key for a GH ref-based releases cau…
Browse files Browse the repository at this point in the history
…sed invalid directory structure (#2286)
  • Loading branch information
antazoey committed Sep 16, 2024
1 parent 20faa7c commit 073434c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/userguides/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Often times, the `v` prefix is required when using tags.
However, if cloning the tag fails, `ape` will retry with a `v` prefix.
Bypass the original failing attempt by including a `v` in your dependency config.

**By knowing if the release is from the version API or only available via tag, and whether the version is v-prefixed or not, you save Ape some time and complexity when installing dependencies.**

### Python

You can use dependencies to PyPI by using the `python:` keyed dependency type.
Expand Down
5 changes: 5 additions & 0 deletions src/ape_pm/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ def fetch(self, destination: Path):
"Use `ref:` instead of `version:` for release tags. "
"Checking for matching tags..."
)

# NOTE: When using ref-from-a-version, ensure
# it didn't create the destination along the way;
# else, the ref is cloned in the wrong spot.
shutil.rmtree(destination, ignore_errors=True)
try:
self._fetch_ref(version, destination)
except Exception:
Expand Down
10 changes: 7 additions & 3 deletions tests/functional/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def test_ref_or_version_is_required(self):
with pytest.raises(ValidationError, match=expected):
_ = GithubDependency(name="foo", github="asdf")

def test_fetch(self, mock_client):
def test_fetch_given_version(self, mock_client):
dependency = GithubDependency(
github="ApeWorX/ApeNotAThing", version="3.0.0", name="apetestdep"
)
Expand Down Expand Up @@ -533,7 +533,7 @@ def only_want_non_v(n0, n1, vers, pth):
# The second call does not have the v!
assert calls[1][0] == ("ApeWorX", "ApeNotAThing", "3.0.0", path)

def test_fetch_given_version_but_expects_reference(self, mock_client):
def test_fetch_given_version_when_expects_reference(self, mock_client):
"""
Show that if a user configures `version:`, but version fails, it
tries `ref:` instead as a backup.
Expand All @@ -546,7 +546,11 @@ def test_fetch_given_version_but_expects_reference(self, mock_client):
mock_client.download_package.side_effect = ValueError("nope")

# Simulate only the non-v prefix ref working (for a fuller flow)
def needs_non_v_prefix_ref(n0, n1, path, branch):
def needs_non_v_prefix_ref(n0, n1, dst_path, branch):
# NOTE: This assertion is very important!
# We must only give it non-existing directories.
assert not dst_path.is_dir()

if branch.startswith("v"):
raise ValueError("nope")

Expand Down

0 comments on commit 073434c

Please sign in to comment.