Skip to content

Commit

Permalink
perf: able to load local project faster (#2359)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 31, 2024
1 parent 115648e commit a84a5ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
9 changes: 7 additions & 2 deletions src/ape/managers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2132,8 +2132,6 @@ def __init__(

super().__init__(manifest, config_override=self._config_override)

self.path = self._base_path / (self.config.base_path or "")

# NOTE: Avoid pointlessly adding info to the __local__ manifest.
# This is mainly for dependencies.
if self.manifest_path.stem != "__local__" and not manifest.sources:
Expand Down Expand Up @@ -2221,6 +2219,13 @@ def __getattr__(self, item: str) -> Any:
# BaseModel internals).
raise AttributeError(message)

@cached_property
def path(self) -> Path:
"""
The path to the project's "base" (where contract source IDs are relative to).
"""
return self._base_path / (self.config.base_path or "")

@property
def _contract_sources(self) -> list[ContractSource]:
sources = []
Expand Down
25 changes: 16 additions & 9 deletions src/ape/pytest/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,22 @@ def pytest_exception_interact(self, report, call):
# Else, it gets way too noisy.
show_locals = not self.config_wrapper.show_internal

report.longrepr = call.excinfo.getrepr(
funcargs=True,
abspath=Path.cwd(),
showlocals=show_locals,
style="short",
tbfilter=False,
truncate_locals=True,
chain=False,
)
try:
here = Path.cwd()

except FileNotFoundError:
pass # In a temp-folder, most likely.

else:
report.longrepr = call.excinfo.getrepr(
funcargs=True,
abspath=here,
showlocals=show_locals,
style="short",
tbfilter=False,
truncate_locals=True,
chain=False,
)

if self.config_wrapper.interactive and report.failed:
traceback = call.excinfo.traceback[-1]
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,10 @@ def test_init_invalid_config(self):

os.chdir(temp_dir)
expected = r"[.\n]*Input should be a valid string\n-->1: name:\n 2: {asdf}[.\n]*"
weird_project = Project(temp_dir)
try:
with pytest.raises(ConfigError, match=expected):
_ = Project(temp_dir)
_ = weird_project.path
finally:
os.chdir(here)

Expand Down

0 comments on commit a84a5ea

Please sign in to comment.