diff --git a/brownie/project/compiler/solidity.py b/brownie/project/compiler/solidity.py index ebf9d6a3d..2146da81c 100644 --- a/brownie/project/compiler/solidity.py +++ b/brownie/project/compiler/solidity.py @@ -90,11 +90,13 @@ def install_solc(*versions: str) -> None: solcx.install_solc(str(version), show_progress=True) -def get_abi(contract_source: str) -> Dict: +def get_abi(contract_source: str, allow_paths: Optional[str] = None) -> Dict: """Given a contract source, returns a dict of {name: abi}""" version = find_best_solc_version({"": contract_source}) set_solc_version(version) - compiled = solcx.compile_source(contract_source, allow_empty=True, output_values=["abi"]) + compiled = solcx.compile_source( + contract_source, allow_empty=True, allow_paths=allow_paths, output_values=["abi"] + ) return {k.rsplit(":")[-1]: v["abi"] for k, v in compiled.items()} diff --git a/brownie/project/main.py b/brownie/project/main.py index 794a06ddd..f521370c6 100644 --- a/brownie/project/main.py +++ b/brownie/project/main.py @@ -272,29 +272,38 @@ def _compile_interfaces(self, compiled_hashes: Dict) -> None: return print("Generating interface ABIs...") - for name in changed: - print(f" - {name}...") - path_str = self._sources.get_source_path(name) - source = self._sources.get(path_str) - path = Path(path_str) - - if path.suffix == ".json": - abi = json.loads(source) - elif path.suffix == ".vy": - try: - abi = compiler.vyper.get_abi(source, name)[name] - except Exception: - # vyper interfaces do not convert to ABIs - # https://github.com/vyperlang/vyper/issues/1944 - continue - else: - abi = compiler.solidity.get_abi(source)[name] - data = {"abi": abi, "contractName": name, "type": "interface", "sha1": new_hashes[name]} + cwd = os.getcwd() + try: + os.chdir(self._path.joinpath("interfaces")) + for name in changed: + print(f" - {name}...") + path_str = self._sources.get_source_path(name) + source = self._sources.get(path_str) + path = Path(path_str) + + if path.suffix == ".json": + abi = json.loads(source) + elif path.suffix == ".vy": + try: + abi = compiler.vyper.get_abi(source, name)[name] + except Exception: + # vyper interfaces do not convert to ABIs + # https://github.com/vyperlang/vyper/issues/1944 + continue + else: + abi = compiler.solidity.get_abi(source, allow_paths=self._path.as_posix())[name] + data = { + "abi": abi, + "contractName": name, + "type": "interface", + "sha1": new_hashes[name], + } - if self._path is not None: with self._path.joinpath(f"build/interfaces/{name}.json").open("w") as fp: json.dump(data, fp, sort_keys=True, indent=2, default=sorted) - self._build._add(data) + self._build._add(data) + finally: + os.chdir(cwd) def _load_deployments(self) -> None: if CONFIG.network_type != "live":