diff --git a/docs/userguides/dependencies.md b/docs/userguides/dependencies.md index 5359dfd036..9e6a8170b2 100644 --- a/docs/userguides/dependencies.md +++ b/docs/userguides/dependencies.md @@ -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. diff --git a/src/ape_pm/dependency.py b/src/ape_pm/dependency.py index 2623dd99aa..a8bd6485f7 100644 --- a/src/ape_pm/dependency.py +++ b/src/ape_pm/dependency.py @@ -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: diff --git a/tests/functional/test_dependencies.py b/tests/functional/test_dependencies.py index 7685a38b80..fca79885d9 100644 --- a/tests/functional/test_dependencies.py +++ b/tests/functional/test_dependencies.py @@ -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" ) @@ -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. @@ -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")