From a84a5ea339e5b19114f9ed353b54c6df24fdd229 Mon Sep 17 00:00:00 2001 From: antazoey Date: Thu, 31 Oct 2024 12:17:04 -0500 Subject: [PATCH] perf: able to load local project faster (#2359) --- src/ape/managers/project.py | 9 +++++++-- src/ape/pytest/runners.py | 25 ++++++++++++++++--------- tests/functional/test_project.py | 3 ++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/ape/managers/project.py b/src/ape/managers/project.py index c900e8fdb6..2f6f658945 100644 --- a/src/ape/managers/project.py +++ b/src/ape/managers/project.py @@ -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: @@ -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 = [] diff --git a/src/ape/pytest/runners.py b/src/ape/pytest/runners.py index e41f724027..6ddac468d8 100644 --- a/src/ape/pytest/runners.py +++ b/src/ape/pytest/runners.py @@ -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] diff --git a/tests/functional/test_project.py b/tests/functional/test_project.py index e36855cc3f..bb0ee3de41 100644 --- a/tests/functional/test_project.py +++ b/tests/functional/test_project.py @@ -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)