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: search path resolution for cli #3694

Merged
merged 2 commits into from
Dec 16, 2023
Merged
Changes from 1 commit
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
19 changes: 12 additions & 7 deletions vyper/cli/vyper_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _parse_args(argv):
)
parser.add_argument("--hex-ir", action="store_true")
parser.add_argument(
"-p", help="Set the root path for contract imports", default=".", dest="root_folder"
"--path", "-p", help="Set the root path for contract imports", action="append", dest="paths"
)
parser.add_argument("-o", help="Set the output path", dest="output_path")
parser.add_argument(
Expand Down Expand Up @@ -188,7 +188,7 @@ def _parse_args(argv):
compiled = compile_files(
args.input_files,
output_formats,
args.root_folder,
args.paths,
args.show_gas_estimates,
settings,
args.storage_layout,
Expand Down Expand Up @@ -226,18 +226,23 @@ def exc_handler(contract_path: ContractPath, exception: Exception) -> None:
def compile_files(
input_files: list[str],
output_formats: OutputFormats,
root_folder: str = ".",
paths: list[str] = None,
show_gas_estimates: bool = False,
settings: Optional[Settings] = None,
storage_layout_paths: list[str] = None,
no_bytecode_metadata: bool = False,
experimental_codegen: bool = False,
) -> dict:
root_path = Path(root_folder).resolve()
if not root_path.exists():
raise FileNotFoundError(f"Invalid root path - '{root_path.as_posix()}' does not exist")
paths = paths or []

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

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

input_bundle = FilesystemInputBundle(search_paths)

show_version = False
if "combined_json" in output_formats:
Expand Down
Loading