Skip to content

Commit

Permalink
fix: issue where could not compile file and subdir in the same command (
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jul 2, 2024
1 parent 9481f4e commit e43fcc3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/ape/cli/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,22 @@ def lookup(self, path_iter: Iterable, path_set: Optional[set] = None) -> set[Pat
self.project.path / path.name
) == contracts_folder or path.name == contracts_folder.name:
# Was given the path to the contracts folder.
return {p for p in self.project.sources.paths}
path_set = path_set.union({p for p in self.project.sources.paths})

elif (self.project.path / path).is_dir():
# Was given sub-dir in the project folder.
return self.lookup(
(p for p in (self.project.path / path).iterdir()), path_set=path_set
path_set = path_set.union(
self.lookup(
(p for p in (self.project.path / path).iterdir()), path_set=path_set
)
)

elif (contracts_folder / path.name).is_dir():
# Was given sub-dir in the contracts folder.
return self.lookup(
(p for p in (contracts_folder / path.name).iterdir()), path_set=path_set
path_set = path_set.union(
self.lookup(
(p for p in (contracts_folder / path.name).iterdir()), path_set=path_set
)
)

elif resolved_path := self.project.sources.lookup(path):
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,24 @@ def test_contract_file_paths_argument_contract_does_not_exist(
assert expected in result.output


def test_contract_file_paths_argument_given_directory_and_file(
project_with_contract, runner, contracts_paths_cmd
):
"""
Tests against a bug where if given a directory AND a file together,
only the directory resolved and the file was lost.
"""
pm = project_with_contract
src_stem = next(x for x in pm.sources if Path(x).suffix == ".json").split(".")[0]
arguments = ("subdir", src_stem, "--project", f"{pm.path}")
result = runner.invoke(contracts_paths_cmd, arguments)
paths = sorted(pm.sources.paths)

all_paths = ", ".join(x.name for x in paths if x.parent.name == "subdir")
assert f"{all_paths}" in result.output
assert f"{src_stem.split('/')[-1]}" in result.output


def test_existing_alias_option(runner):
@click.command()
@existing_alias_argument()
Expand Down

0 comments on commit e43fcc3

Please sign in to comment.