Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle when local dependency is already a manifest [APE-1397] #1666

Merged
merged 9 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/userguides/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ This is helpful when:
- When there is not a suitable `DependencyAPI` implementation available for downloading your dependency.
- Testing the framework.

You can also reference local project manifests and use those as dependencies.
To do this, use a local value pointing to the manifest file, like this:

```yaml
dependencies:
- name: MyDependency
local: ./my-dependency.json
version: 1.0.0
```

### NPM

You can use dependencies from NPM.
Expand Down
27 changes: 26 additions & 1 deletion src/ape/api/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from packaging.version import InvalidVersion, Version
from pydantic import ValidationError

from ape.exceptions import ApeAttributeError
from ape.exceptions import ApeAttributeError, ProjectError
from ape.logging import logger
from ape.utils import (
BaseInterfaceModel,
Expand Down Expand Up @@ -410,6 +410,31 @@ def _extract_local_manifest(
if cached_manifest:
return cached_manifest

if project_path.is_file() and project_path.suffix == ".json":
try:
manifest = PackageManifest.parse_file(project_path)

except ValueError as err:
if project_path.parent.is_dir():
project_path = project_path.parent

else:
raise ProjectError(f"Invalid manifest file: '{project_path}'.") from err

else:
# Was given a path to a manifest JSON.
self._write_manifest_to_cache(manifest)
return manifest

elif (project_path.parent / project_path.name.replace("-", "_")).is_dir():
project_path = project_path.parent / project_path.name.replace("-", "_")

elif (project_path.parent / project_path.name.replace("_", "-")).is_dir():
project_path = project_path.parent / project_path.name.replace("_", "-")

elif project_path.parent.is_dir():
project_path = project_path.parent

# NOTE: Dependencies are not compiled here. Instead, the sources are packaged
# for later usage via imports. For legacy reasons, many dependency-esque projects
# are not meant to compile on their own.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ dependencies:

- name: renamed-contracts-folder-specified-in-config
local: ./renamed_contracts_folder_specified_in_config

- name: manifest-dependency
local: ./manifest_dependency.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"contractTypes":{"manifest-dependency":{"abi":[{"stateMutability":"nonpayable","type":"fallback"}],"contractName":"manifest-dependency","sourceId":"manifest-dependency.json"}},"manifest":"ethpm/3","sources":{"manifest-dependency.json":{"checksum":{"algorithm":"md5","hash":"0xaaf11362c066814f73d7db766ade0a0c"},"content":"[\n {\"name\":\"foo\",\"type\":\"fallback\", \"stateMutability\":\"nonpayable\"}\n]\n","imports":[],"references":[],"urls":[]}}}
1 change: 1 addition & 0 deletions tests/integration/cli/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def test_compile_with_dependency(ape_cli, runner, project, contract_path):
"containing-sub-dependencies",
"renamed-complex-contracts-folder",
"renamed-contracts-folder-specified-in-config",
"manifest-dependency",
):
assert name in list(project.dependencies.keys())
dependency = project.dependencies[name]["local"]
Expand Down