Skip to content

Commit

Permalink
fix: changed sources bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 8, 2023
1 parent 1512741 commit 3936d6b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/ape/managers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def compile(
Dict[str, ``ContractType``]: A mapping of contract names to their type.
"""
contract_file_paths = [Path(p) if isinstance(p, str) else p for p in contract_filepaths]

extensions = self._get_contract_extensions(contract_file_paths)
contracts_folder = self.config_manager.contracts_folder
contract_types_dict: Dict[str, ContractType] = {}
Expand Down
23 changes: 19 additions & 4 deletions src/ape/managers/project/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ class _ProjectSources:
# running `ape compile`.

def __init__(
self, cached_manifest: PackageManifest, active_sources: List[Path], contracts_folder: Path
self,
cached_manifest: PackageManifest,
active_sources: List[Path],
contracts_folder: Path,
cache_folder: Path,
):
self.cached_manifest = cached_manifest
self.active_sources = active_sources
self.contracts_folder = contracts_folder
self.cache_folder = cache_folder

@cached_property
def cached_sources(self) -> Dict[str, Source]:
Expand Down Expand Up @@ -59,6 +64,7 @@ def sources_needing_compilation(self) -> List[Path]:
needs_compile.update(reference_paths)

needs_compile.update(all_referenced_paths)

return list(needs_compile)

@cached_property
Expand All @@ -83,10 +89,17 @@ def _check_needs_compiling(self, source_path: Path) -> bool:
# We need to do the same here for to prevent the endless recompiling bug.
content = f"{source_file.read_text('utf8').rstrip()}\n"
checksum = compute_checksum(content.encode("utf8"), algorithm=cached_checksum.algorithm)
breakpoint()

# NOTE: Filter by checksum to only update what's needed
return checksum != cached_checksum.hash # Contents changed
content_changed = checksum != cached_checksum.hash # Contents changed

if content_changed:
# If content has changed, removed previous build artifact.
json_name = source_id.split(os.path.sep)[-1]
cached_file = self.cache_folder / json_name
cached_file.unlink(missing_ok=True)

return content_changed

def get_source_reference_paths(self, source_id: str) -> List[Path]:
return [s for s in self._source_reference_paths.get(source_id, []) if s.is_file()]
Expand Down Expand Up @@ -175,7 +188,9 @@ def create_manifest(
]
)
)
project_sources = _ProjectSources(manifest, source_paths, self.contracts_folder)
project_sources = _ProjectSources(
manifest, source_paths, self.contracts_folder, self._cache_folder
)
contract_types = project_sources.remaining_cached_contract_types
compiled_contract_types = self._compile(project_sources)
contract_types.update(compiled_contract_types)
Expand Down

0 comments on commit 3936d6b

Please sign in to comment.