Skip to content

Commit

Permalink
fix: add compiler data to manifest output [APE-1573] (#1746)
Browse files Browse the repository at this point in the history
* fix: add compiler data to manifest output

* fix: prevent infinite loop

* fix: make proper external fn

we now have multiple callers so its worth properly exposing

* fix: we don't have compiler data for json
  • Loading branch information
z80dev authored Nov 27, 2023
1 parent caab108 commit 0845558
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ape/api/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Union

from ethpm_types import Checksum, ContractType, PackageManifest, Source
from ethpm_types import Checksum, Compiler, ContractType, PackageManifest, Source
from ethpm_types.manifest import PackageName
from ethpm_types.source import Content
from ethpm_types.utils import Algorithm, AnyUrl, compute_checksum
Expand Down Expand Up @@ -180,12 +180,14 @@ def _create_manifest(
name: Optional[str] = None,
version: Optional[str] = None,
initial_manifest: Optional[PackageManifest] = None,
compiler_data: Optional[List[Compiler]] = None,
) -> PackageManifest:
manifest = initial_manifest or PackageManifest()
manifest.name = PackageName(__root__=name.lower()) if name is not None else manifest.name
manifest.version = version or manifest.version
manifest.sources = cls._create_source_dict(source_paths, contracts_path)
manifest.contract_types = contract_types
manifest.compilers = compiler_data or []
return manifest

@classmethod
Expand Down Expand Up @@ -445,7 +447,7 @@ def _extract_local_manifest(
project_manifest = project._create_manifest(
sources, project.contracts_folder, {}, name=project.name, version=project.version
)
compiler_data = self.project_manager._get_compiler_data(compile_if_needed=False)
compiler_data = self.project_manager.get_compiler_data(compile_if_needed=False)

if dependencies:
project_manifest.dependencies = dependencies
Expand Down
13 changes: 13 additions & 0 deletions src/ape/managers/project/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ def compiler_data(self) -> List[Compiler]:
"""
return self._get_compiler_data()

def get_compiler_data(self, compile_if_needed: bool = True) -> List[Compiler]:
"""
A list of ``Compiler`` objects representing the raw-data specifics of a compiler.
Args:
compile_if_needed (bool): Set to ``False`` to only return cached compiler data.
Defaults to ``True``.
Returns:
List[Compiler]
"""
return self._get_compiler_data(compile_if_needed=compile_if_needed)

def _get_compiler_data(self, compile_if_needed: bool = True):
contract_types: Iterable[ContractType] = (
self.contracts.values()
Expand Down
4 changes: 4 additions & 0 deletions src/ape/managers/project/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,17 @@ def create_manifest(
contract_types = project_sources.remaining_cached_contract_types
compiled_contract_types = self._compile(project_sources)
contract_types.update(compiled_contract_types)
# NOTE: We need to prevent compilation or else we get an endless loop, because
# compilation results in creating a manifest, which triggers compilation, etc.
compiler_data = self.project_manager.get_compiler_data(compile_if_needed=False)
manifest = self._create_manifest(
source_paths,
self.contracts_folder,
contract_types,
initial_manifest=manifest,
name=self.name,
version=self.version,
compiler_data=compiler_data,
)
# Cache the updated manifest so `self.cached_manifest` reads it next time
self.manifest_cachefile.write_text(manifest.json())
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/cli/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def test_compile(ape_cli, runner, project, clean_cache):
unexpected_files = [f for f in all_files if f not in expected_files]

manifest = project.extract_manifest()
non_json = [f for f in expected_files if f.suffix != ".json"]
if len(non_json) > 0:
assert manifest.compilers
for file in expected_files:
assert file.name in manifest.sources

Expand Down

0 comments on commit 0845558

Please sign in to comment.