Skip to content

Commit

Permalink
fix: issue where could not have dependencies with contracts_folder
Browse files Browse the repository at this point in the history
…pointed at the root project path (#2048)
  • Loading branch information
antazoey authored May 3, 2024
1 parent aec6abb commit df95b4e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
2 changes: 0 additions & 2 deletions src/ape/api/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,9 @@ def _extract_local_manifest(
if project_path.is_file() and project_path.suffix == ".json":
try:
manifest = PackageManifest.model_validate_json(project_path.read_text())

except ValueError as err:
if project_path.parent.is_dir():
project_path = project_path.parent

else:
raise ProjectError(f"Invalid manifest file: '{project_path}'.") from err

Expand Down
19 changes: 14 additions & 5 deletions src/ape/managers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ def _plugin_configs(self) -> Dict[str, PluginConfig]:
)

self.contracts_folder = configs["contracts_folder"] = contracts_folder

deployments = user_config.pop("deployments", {})
valid_ecosystems = dict(self.plugin_manager.ecosystems)
valid_network_names = [n[1] for n in [e[1] for e in self.plugin_manager.networks]]
Expand Down Expand Up @@ -335,9 +334,15 @@ def using_project(
return

self.PROJECT_FOLDER = project_folder
self.contracts_folder = (
contracts_folder if contracts_folder else project_folder / "contracts"
)

if isinstance(contracts_folder, str):
contracts_folder = (project_folder / contracts_folder).expanduser().resolve()
elif isinstance(contracts_folder, Path):
contracts_folder = contracts_folder
else:
contracts_folder = project_folder / "contracts"

self.contracts_folder = contracts_folder
self.project_manager.path = project_folder
os.chdir(project_folder)
clean_config = False
Expand All @@ -347,7 +352,11 @@ def using_project(
project = self.project_manager.get_project(
project_folder, contracts_folder=contracts_folder
)
clean_config = project.process_config_file(contracts_folder=contracts_folder, **config)
# Ensure this ends up in the project's config.
if "contracts_folder" not in config:
config["contracts_folder"] = contracts_folder

clean_config = project.process_config_file(**config)
self.load(force_reload=True)
yield self.project_manager

Expand Down
14 changes: 11 additions & 3 deletions src/ape/managers/project/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,17 @@ def process_config_file(self, **kwargs) -> bool:
config_data["version"] = self.version

contracts_folder = kwargs.get("contracts_folder") or self.contracts_folder
contracts_folder_config_item = (
str(contracts_folder).replace(str(self.path), "").strip(os.path.sep)
)

if contracts_folder == self.path:
# Handle projects pointed at root path.
contracts_folder_config_item = "."
elif isinstance(contracts_folder, Path):
# Strip of path prefix.
contracts_folder_config_item = os.path.relpath(contracts_folder, self.path)
else:
# Was given a str.
contracts_folder_config_item = contracts_folder

config_data["contracts_folder"] = contracts_folder_config_item
self.config_file.parent.mkdir(parents=True, exist_ok=True)
self.config_file.touch()
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/cli/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,15 @@ def clean_cache(project):
if cache_file.is_file():
cache_file.unlink()

project.local_project._cached_manifest = None

yield

if cache_file.is_file():
cache_file.unlink()

project.local_project._cached_manifest = None


@pytest.fixture
def switch_config(config):
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/cli/projects/with-contracts/ape-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ dependencies:
- name: foodep
local: ./dep

# Showing we can have dependencies with contracts_folder
# equal to the path. (used in `tests/integration/cli/test_pm.py -k test_install`)
- name: depcontractsfolderroot
local: ./dep_contracts_folder_root
config_override:
contracts_folder: .

test:
# `false` because running pytest within pytest.
disconnect_providers_after: false
Expand Down

Large diffs are not rendered by default.

0 comments on commit df95b4e

Please sign in to comment.