Skip to content

Commit

Permalink
fix: don't compile contracts/.build [APE-1358] (ApeWorX#1645)
Browse files Browse the repository at this point in the history
* fix: ignor build dir

* test: add tst

* test: clean
  • Loading branch information
antazoey authored Sep 1, 2023
1 parent f8eeae4 commit b5f46f7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/ape/api/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class DependencyAPI(BaseInterfaceModel):
**NOTE**: This must be the name of a directory in the project.
"""

exclude: List[str] = ["package.json", "package-lock.json"]
exclude: List[str] = ["package.json", "package-lock.json", "**/.build/**/*.json"]
"""
A list of glob-patterns for excluding files in dependency projects.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/ape/managers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def compile(self, contract_filepaths: List[Path]) -> Dict[str, ContractType]:
and path not in paths_to_ignore
and path not in built_paths
and path.suffix == extension
and ".cache" not in [p.name for p in path.parents]
and not any(x in [p.name for p in path.parents] for x in (".cache", ".build"))
]

for path in paths_to_compile:
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def test_contracts_get_multiple(vyper_contract_instance, solidity_contract_insta
def test_contracts_get_multiple_no_addresses(chain, caplog):
contract_map = chain.contracts.get_multiple([])
assert not contract_map
assert caplog.records[-1].levelname == "WARNING"
assert "WARNING" in caplog.records[-1].levelname
assert "No addresses provided." in caplog.records[-1].message


Expand Down
30 changes: 23 additions & 7 deletions tests/integration/cli/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,45 @@ def test_compile(ape_cli, runner, project, clean_cache):
# Don't expect directories that may happen to have `.json` in name
# as well as hidden files, such as `.gitkeep`. Both examples are present
# in the test project!
excluded = ("Exclude.json", "UnwantedContract.json")
excluded = (
"Exclude.json",
"UnwantedContract.json",
"tsconfig.json",
"package.json",
"package-lock.json",
)
expected_files = [
f
for f in all_files
if f.name.count(".") == 1
and f.is_file()
and not f.name.startswith(".")
and f.name not in excluded
and f.suffix == ".json"
]
unexpected_files = [f for f in all_files if f not in expected_files]

manifest = project.extract_manifest()
for file in expected_files:
assert file.name in manifest.sources

assert all(f.stem in result.output for f in expected_files)
missing = [f.name for f in expected_files if f.stem not in result.output]
assert not missing, f"Missing: {', '.join(missing)}"
assert not any(f.stem in result.output for f in unexpected_files)

result = runner.invoke(ape_cli, ["compile"], catch_exceptions=False)
assert result.exit_code == 0, result.output
# First time it compiles, it caches
for file in project.path.glob("contracts/**/*"):
assert file.stem not in result.output
# Copy in .build to show that those file won't compile.
# (Anything in a .build is ignored, even if in a contracts folder to prevent accidents).
shutil.copytree(project.path / ".build", project.contracts_folder / ".build")

try:
result = runner.invoke(ape_cli, ["compile"], catch_exceptions=False)
assert result.exit_code == 0, result.output
# First time it compiles, it caches
for file in project.path.glob("contracts/**/*"):
assert file.stem not in result.output

finally:
shutil.rmtree(project.contracts_folder / ".build", ignore_errors=True)


@skip_projects_except("multiple-interfaces")
Expand Down

0 comments on commit b5f46f7

Please sign in to comment.