Skip to content

Commit

Permalink
Merge branch 'main' into perf/api-module-fast
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 31, 2024
2 parents 679c20b + a84a5ea commit 97cdca5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
15 changes: 11 additions & 4 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 @@ -2216,8 +2214,17 @@ def __getattr__(self, item: str) -> Any:
"missing compilers for extensions: " + f'{", ".join(sorted(missing_exts))}?'
)

err.args = (message,)
raise # The same exception (keep the stack the same height).
# NOTE: Purposely discard the stack-trace and raise a new exception.
# This shows a better stack-trace to the user (rather than weird
# 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]:
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
12 changes: 10 additions & 2 deletions tests/functional/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,16 @@ def test_getattr(tmp_project):


def test_getattr_not_exists(tmp_project):
with pytest.raises(AttributeError):
expected = (
r"'LocalProject' object has no attribute 'nope'\. Also checked extra\(s\) 'contracts'\."
)
with pytest.raises(AttributeError, match=expected) as err:
_ = tmp_project.nope

# Was the case where the last entry was from Ape's basemodel stuff.
# Now, it points at the project manager last.
assert "ape/managers/project.py:" in repr(err.traceback[-1])


def test_getattr_detects_changes(tmp_project):
source_id = tmp_project.Other.contract_type.source_id
Expand Down Expand Up @@ -680,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 97cdca5

Please sign in to comment.