Skip to content

Commit

Permalink
clean up _resolve_import
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Oct 29, 2023
1 parent e78e81a commit a2b21b7
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions vyper/semantics/analysis/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,29 +329,24 @@ def _add_import(
)

with self.input_bundle.search_path(builtins_path):
file = self._resolve_import(level, qualified_module_name)

if isinstance(file, VyFile):
interface_ast = vy_ast.parse_to_ast(file.source_code, contract_name=file.path)
type_ = InterfaceT.from_ast(interface_ast)
elif isinstance(file, ABIInput):
type_ = InterfaceT.from_json_abi(file.path, file.abi)
else: # pragma: nocover
raise CompilerPanic(f"Unknown interface format: {type(file)}")
type_ = self._load_import(level, qualified_module_name)

try:
self.namespace[alias] = type_
except VyperException as exc:
raise exc.with_annotation(node) from None

def _resolve_import(self, level: int, module: str) -> CompilerInput:
# load an InterfaceT from an import
def _load_import(self, level: int, module: str) -> InterfaceT:
path = _import_to_path(level, module)
try:
return self.input_bundle.load_file(path.with_suffix(".vy"))
file = self.input_bundle.load_file(path.with_suffix(".vy"))
ast = vy_ast.parse_to_ast(file.source_code, contract_name=file.path)
InterfaceT.from_ast(interface_ast)
except FileNotFoundError:
file = self.input_bundle.load_file(path.with_suffix(".json"))
abi = json.loads(file.source_code)
return ABIInput(file.path, abi)
return InterfaceT.from_json_abi(file.path, abi)


# convert an import to a path (without suffix)
Expand Down

0 comments on commit a2b21b7

Please sign in to comment.