Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add python sys.path to vyper path #3763

Merged
merged 8 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions vyper/cli/vyper_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,16 @@ def compile_files(
storage_layout_paths: list[str] = None,
no_bytecode_metadata: bool = False,
) -> dict:
paths = paths or []
# lowest precedence search path is always sys path
search_paths = [Path(p) for p in sys.path]

# 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()

# lowest precedence search path is always `.`
search_paths = [Path(".")]

paths = paths or []

for p in paths:
path = Path(p).resolve(strict=True)
Expand Down
9 changes: 8 additions & 1 deletion vyper/semantics/analysis/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,17 @@


def _parse_and_fold_ast(file: FileInput) -> vy_ast.VyperNode:
module_path = file.resolved_path # for error messages
try:
# try to get a relative path, to simplify the error message
module_path = module_path.relative_to(".")
except ValueError:
Fixed Show fixed Hide fixed
pass

ret = vy_ast.parse_to_ast(
file.source_code,
source_id=file.source_id,
module_path=str(file.path),
module_path=str(module_path),
resolved_path=str(file.resolved_path),
)
return ret
Expand Down
Loading