-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
compile.py
29 lines (23 loc) · 920 Bytes
/
compile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import sys, subprocess, json
# Check if `experimental_codegen` is enabled in the
# Foundry profile.
def is_experimental_codegen():
try:
result = subprocess.run(
["forge", "config", "--json"], capture_output=True, text=True, check=True
)
config = json.loads(result.stdout)
return config.get("vyper", {}).get("experimental_codegen", False) == True
except (subprocess.CalledProcessError, json.JSONDecodeError, KeyError):
return False
# Build the Vyper command.
command = (
["vyper", "--experimental-codegen"] if is_experimental_codegen() else ["vyper"]
)
command += sys.argv[1:]
result = subprocess.run(command, capture_output=True, text=True)
if result.returncode != 0:
raise Exception(f"Error compiling: {sys.argv[1]}")
# Remove any leading and trailing whitespace characters
# from the compilation result.
sys.stdout.write(result.stdout.strip())