Skip to content

Commit c78aff9

Browse files
authored
Merge branch 'main' into fix/local-default-provider-config
2 parents 1f381d7 + f6c3930 commit c78aff9

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/ape/managers/project.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,9 @@ def get(
450450
if check_for_changes and self._detect_change(source_id):
451451
compiled = {
452452
ct.name: ct
453-
for ct in self.compiler_manager.compile(source_id, project=self.project)
453+
for ct in self.compiler_manager.compile(
454+
self.project.path / source_id, project=self.project
455+
)
454456
if ct.name
455457
}
456458
if compiled:

src/ape_console/_cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ def _load_extras_file(self, extras_file: Path) -> dict:
157157
if ape_init_extras is not None:
158158
func_spec = inspect.getfullargspec(ape_init_extras)
159159
init_kwargs: dict[str, Any] = {k: self._get_from_ape(k) for k in func_spec.args}
160+
160161
extras = ape_init_extras(**init_kwargs)
162+
if inspect.iscoroutine(extras):
163+
from IPython.core.async_helpers import get_asyncio_loop
164+
165+
extras = get_asyncio_loop().run_until_complete(extras)
161166

162167
if isinstance(extras, dict):
163168
all_extras.update(extras)

tests/functional/test_console.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ def test_extras_load_using_ape_namespace(self, scope):
8585
extras_content = """
8686
def ape_init_extras(project):
8787
return {"foo": type(project)}
88+
"""
89+
with create_tempdir() as temp:
90+
extras_file = temp / CONSOLE_EXTRAS_FILENAME
91+
extras_file.write_text(extras_content)
92+
extras.__dict__[f"_{scope}_path"] = extras_file
93+
extras.__dict__.pop(f"_{scope}_extras", None)
94+
assert extras["foo"] is LocalProject
95+
96+
@pytest.mark.parametrize("scope", ("local", "global"))
97+
def test_extras_async_ape_init_extras(self, scope):
98+
"""
99+
``ape_init_extras`` is allowed to be defined as an ``async`` function;
100+
it gets awaited before its result is merged into the namespace.
101+
"""
102+
extras = ApeConsoleNamespace()
103+
_ = getattr(extras, f"_{scope}_path")
104+
extras_content = """
105+
async def ape_init_extras(project):
106+
return {"foo": type(project)}
88107
"""
89108
with create_tempdir() as temp:
90109
extras_file = temp / CONSOLE_EXTRAS_FILENAME

tests/functional/test_project.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,24 @@ def test_values(self, small_temp_project):
11081108
new_count = len(small_temp_project.contracts)
11091109
assert new_count == count - 1
11101110

1111+
def test_get_after_change_from_other_cwd(self, small_temp_project):
1112+
# Regression: getting a contract whose source has changed must not
1113+
# depend on cwd happening to equal the project root.
1114+
small_temp_project.load_contracts(use_cache=False)
1115+
source_path = small_temp_project.contracts_folder / "Other.json"
1116+
source_path.write_text(source_path.read_text(encoding="utf8") + "\n", encoding="utf8")
1117+
1118+
original_cwd = Path.cwd()
1119+
with create_tempdir() as elsewhere:
1120+
os.chdir(elsewhere)
1121+
try:
1122+
actual = small_temp_project.contracts.get("Other")
1123+
finally:
1124+
os.chdir(original_cwd)
1125+
1126+
assert isinstance(actual, ContractContainer)
1127+
assert actual.contract_type.name == "Other"
1128+
11111129

11121130
class TestDeploymentManager:
11131131
def test_track(self, project, owner):

0 commit comments

Comments
 (0)