diff --git a/vyper/cli/utils.py b/vyper/cli/utils.py index 8fc64b1cdfb..1ff44a56837 100644 --- a/vyper/cli/utils.py +++ b/vyper/cli/utils.py @@ -1,8 +1,21 @@ +from pathlib import Path +from typing import Sequence + from vyper import ast as vy_ast from vyper.exceptions import StructureException from vyper.typing import InterfaceImports, SourceCode +def get_interface_file_path(base_paths: Sequence, import_path: str) -> Path: + relative_path = Path(import_path) + for path in base_paths: + file_path = path.joinpath(relative_path) + suffix = next((i for i in (".vy", ".json") if file_path.with_suffix(i).exists()), None) + if suffix: + return file_path.with_suffix(suffix) + raise FileNotFoundError(f" Cannot locate interface '{import_path}{{.vy,.json}}'") + + def extract_file_interface_imports(code: SourceCode) -> InterfaceImports: ast_tree = vy_ast.parse_to_ast(code) diff --git a/vyper/cli/vyper_compile.py b/vyper/cli/vyper_compile.py index 5138c4f75a7..10b3d189bbe 100755 --- a/vyper/cli/vyper_compile.py +++ b/vyper/cli/vyper_compile.py @@ -5,11 +5,14 @@ import warnings from collections import OrderedDict from pathlib import Path -from typing import Dict, Iterable, Iterator, Sequence, Set, TypeVar +from typing import Dict, Iterable, Iterator, Set, TypeVar import vyper from vyper.cli import vyper_json -from vyper.cli.utils import extract_file_interface_imports +from vyper.cli.utils import ( + extract_file_interface_imports, + get_interface_file_path, +) from vyper.opcodes import DEFAULT_EVM_VERSION, EVM_VERSIONS from vyper.parser import parser_utils from vyper.settings import VYPER_TRACEBACK_LIMIT @@ -183,16 +186,6 @@ def get_interface_codes(root_path: Path, contract_sources: ContractCodes) -> Dic return interfaces -def get_interface_file_path(base_paths: Sequence, import_path: str) -> Path: - relative_path = Path(import_path) - for path in base_paths: - file_path = path.joinpath(relative_path) - suffix = next((i for i in (".vy", ".json") if file_path.with_suffix(i).exists()), None) - if suffix: - return file_path.with_suffix(suffix) - raise FileNotFoundError(f" Cannot locate interface '{import_path}{{.vy,.json}}'") - - def compile_files( input_files: Iterable[str], output_formats: OutputFormats, diff --git a/vyper/cli/vyper_json.py b/vyper/cli/vyper_json.py index 7f172c18e48..39cb7e5c08b 100755 --- a/vyper/cli/vyper_json.py +++ b/vyper/cli/vyper_json.py @@ -8,8 +8,10 @@ from typing import Callable, Dict, Tuple, Union import vyper -from vyper.cli.utils import extract_file_interface_imports -from vyper.cli.vyper_compile import get_interface_file_path +from vyper.cli.utils import ( + extract_file_interface_imports, + get_interface_file_path, +) from vyper.exceptions import JSONError from vyper.opcodes import DEFAULT_EVM_VERSION, EVM_VERSIONS from vyper.typing import ContractCodes, ContractPath