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: allow multiple paths to .compile_files() #35

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions tests/test_compile_source.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import tempfile
from pathlib import Path

import pytest
from packaging.version import Version

Expand All @@ -19,6 +22,16 @@ def test_compile_files(foo_path, vyper_version):
assert foo_path.as_posix() in output


def test_compile_files_search_paths(foo_path, vyper_version):
if Version("0.4.0b1") <= vyper_version <= Version("0.4.0b5"):
pytest.skip("vyper 0.4.0b1 to 0.4.0b5 have a bug with combined_json")

with tempfile.TemporaryDirectory() as tmpdir:
output = vvm.compile_files([foo_path], search_paths=[Path.cwd(), tmpdir])

assert foo_path.as_posix() in output


def test_compile_standard(input_json, foo_source):
input_json["sources"] = {"contracts/Foo.vy": {"content": foo_source}}
result = vvm.compile_standard(input_json)
Expand Down
14 changes: 12 additions & 2 deletions vvm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ def compile_source(

def compile_files(
source_files: Union[List, Path, str],
base_path: Union[Path, str] = None,
base_path: Optional[Union[Path, str]] = None,
evm_version: str = None,
vyper_binary: Union[str, Path] = None,
vyper_version: Union[str, Version, None] = None,
output_format: str = None,
search_paths: Optional[List[Union[Path, str]]] = None,
) -> Any:
"""
Compile one or more Vyper source files.
Expand All @@ -115,6 +116,9 @@ def compile_files(
Ignored if `vyper_binary` is also given.
output_format: str, optional
Output format of the compiler. See `vyper --help` for more information.
search_paths: List[str | Path], optional
Additional search paths. Only applicable for Vyper 0.4. Cannot use with
`base_path` argument.

Returns
-------
Expand All @@ -129,6 +133,7 @@ def compile_files(
base_path=base_path,
evm_version=evm_version,
output_format=output_format,
search_paths=search_paths,
)


Expand All @@ -137,15 +142,20 @@ def _compile(
vyper_binary: Union[str, Path, None],
vyper_version: Union[str, Version, None],
output_format: Optional[str],
search_paths: Optional[List[Union[Path, str]]] = None,
**kwargs: Any,
) -> Any:
if vyper_binary is None:
vyper_binary = get_executable(vyper_version)
if output_format is None:
output_format = "combined_json"

if base_path is not None and search_paths is not None:
raise ValueError("Cannot specify both 'base_path' and 'search_paths'.")

paths = search_paths if base_path is None else [base_path]
stdoutdata, stderrdata, command, proc = wrapper.vyper_wrapper(
vyper_binary=vyper_binary, f=output_format, p=base_path, **kwargs
vyper_binary=vyper_binary, f=output_format, paths=paths, **kwargs
)

if output_format in ("combined_json", "standard_json", "metadata"):
Expand Down
7 changes: 6 additions & 1 deletion vvm/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import subprocess
from pathlib import Path
from typing import Any, Dict, List, Tuple, Union
from typing import Any, Dict, List, Optional, Tuple, Union

from packaging.version import Version

Expand Down Expand Up @@ -40,6 +40,7 @@ def vyper_wrapper(
stdin: str = None,
source_files: Union[List, Path, str] = None,
success_return_code: int = 0,
paths: Optional[List[Union[Path, str]]] = None,
**kwargs: Any,
) -> Tuple[str, str, List, subprocess.Popen]:
"""
Expand Down Expand Up @@ -95,6 +96,10 @@ def vyper_wrapper(
else:
command.extend([_to_string("source_files", i) for i in source_files])

if paths is not None:
for path in paths:
command.extend(("-p", f"{path}"))

for key, value in kwargs.items():
if value is None or value is False:
continue
Expand Down
Loading