Skip to content

Commit

Permalink
refactor: get_search_paths() for vyper cli (#3778)
Browse files Browse the repository at this point in the history
this is for external consumers of the compiler library, which may want
to be able to replicate how vyper computes the search path
  • Loading branch information
charles-cooper authored Feb 13, 2024
1 parent 199f2b6 commit d372378
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions vyper/cli/vyper_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,32 +229,37 @@ def exc_handler(contract_path: ContractPath, exception: Exception) -> None:
raise exception


def compile_files(
input_files: list[str],
output_formats: OutputFormats,
paths: list[str] = None,
show_gas_estimates: bool = False,
settings: Optional[Settings] = None,
storage_layout_paths: list[str] = None,
no_bytecode_metadata: bool = False,
) -> dict:
# lowest precedence search path is always sys path
search_paths = [Path(p) for p in sys.path]
def get_search_paths(paths: list[str] = None) -> list[Path]:
# given `paths` input, get the full search path, including
# the system search path.
paths = paths or []

# python sys path uses opposite resolution order from us
# lowest precedence search path is always sys path
# note python sys path uses opposite resolution order from us
# (first in list is highest precedence; we give highest precedence
# to the last in the list)
search_paths.reverse()
search_paths = [Path(p) for p in reversed(sys.path)]

if Path(".") not in search_paths:
search_paths.append(Path("."))

paths = paths or []

for p in paths:
path = Path(p).resolve(strict=True)
search_paths.append(path)

return search_paths


def compile_files(
input_files: list[str],
output_formats: OutputFormats,
paths: list[str] = None,
show_gas_estimates: bool = False,
settings: Optional[Settings] = None,
storage_layout_paths: list[str] = None,
no_bytecode_metadata: bool = False,
) -> dict:
search_paths = get_search_paths(paths)
input_bundle = FilesystemInputBundle(search_paths)

show_version = False
Expand Down

0 comments on commit d372378

Please sign in to comment.