Skip to content

Commit

Permalink
fix: dependency of dependency auto-version detection [APE-1414] (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Nov 1, 2023
1 parent 30f087a commit e8a53df
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ ape compile

The byte-code and ABI for your contracts should now exist in a `__local__.json` file in a `.build/` directory.

### Solidity Versioning

By default, `ape-solidity` tries to use the best versions of Solidity by looking at all the source files' pragma specifications.
However, it is often better to specify a version directly.
If you know the best version to use, set it in your `ape-config.yaml`, like this:

```yaml
solidity:
version: 0.8.14
```
### Dependency Mapping
To configure import remapping, use your project's `ape-config.yaml` file:
Expand Down
37 changes: 25 additions & 12 deletions ape_solidity/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ def _add_dependencies(
cached_source.parent.mkdir(parents=True, exist_ok=True)
if src.content:
cached_source.touch()
cached_source.write_text(
src.content if isinstance(src.content, str) else str(src.content)
)
cached_source.write_text(str(src.content))

# Add dependency remapping that may be needed.
for compiler in manifest.compilers or []:
Expand Down Expand Up @@ -264,21 +262,36 @@ def _add_dependencies(

break

if version is None:
raise CompilerError(f"Unable to discern dependency type '{uri_str}'.")

# Find matching package
for package in packages_dir.iterdir():
if package.name.replace("_", "-").lower() == dependency_name:
dependency_name = str(package.name)
break

dependency_path = (
self.config_manager.packages_folder
/ Path(dependency_name)
/ version
/ f"{dependency_name}.json"
)
dependency_root_path = self.config_manager.packages_folder / Path(dependency_name)

if version is None:
version_dirs = [
d
for d in list(dependency_root_path.iterdir())
if d.is_dir() and not d.name.startswith(".")
]
if len(version_dirs) == 1:
# Use the only existing version.
version = version_dirs[0].name

elif (dependency_root_path / "local").is_dir():
# If not specified, and local exists, use local by default.
version = "local"

else:
options = ", ".join([x.name for x in dependency_root_path.iterdir()])
raise CompilerError(
f"Ambiguous dependency version. "
f"Please specify. Available versions: '{options}'."
)

dependency_path = dependency_root_path / version / f"{dependency_name}.json"
if dependency_path.is_file():
sub_manifest = PackageManifest.parse_file(dependency_path)
dep_id = Path(dependency_name) / version
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"mdformat>=0.7.16", # Auto-formatter for markdown
"mdformat-gfm>=0.3.5", # Needed for formatting GitHub-flavored markdown
"mdformat-frontmatter>=0.4.1", # Needed for frontmatters-style headers in issue templates
"pydantic<2.0", # Needed for successful type check. TODO: Remove after full v2 support.
],
"doc": [
"Sphinx>=3.4.3,<4", # Documentation generator
Expand Down
9 changes: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ def project(data_folder, config):


@pytest.fixture
def compiler():
return ape.compilers.registered_compilers[Extension.SOL.value]
def compiler_manager():
return ape.compilers


@pytest.fixture
def compiler(compiler_manager):
return compiler_manager.registered_compilers[Extension.SOL.value]


@pytest.fixture
Expand Down

0 comments on commit e8a53df

Please sign in to comment.