Skip to content

Commit 6cde05a

Browse files
refactor: cleaner path combination logic
1 parent 2af4f95 commit 6cde05a

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

natrix/ast_tools.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,26 @@ def _obtain_default_paths():
6565
"lib/pypi", # Default dependency folder for moccasin
6666
# Add more paths here in the future
6767
]
68-
68+
6969
# Return only existing paths
7070
existing_paths = []
7171
for path in default_paths:
7272
if os.path.exists(path) and os.path.isdir(path):
7373
existing_paths.append(path)
74-
74+
7575
return existing_paths
7676

7777

78-
def vyper_compile(filename, formatting, extra_paths=None):
78+
def vyper_compile(filename, formatting, extra_paths=[]):
7979
_check_vyper_version()
8080

81-
# For each path add a '-p /the/path' flag to the compiler
82-
paths = [item for p in _obtain_sys_path() for item in ["-p", p]]
83-
84-
# Add default paths (like lib/pypi for moccasin)
85-
for path in _obtain_default_paths():
86-
paths.extend(["-p", path])
81+
# Combine all paths
82+
all_paths = _obtain_sys_path() + _obtain_default_paths() + extra_paths
8783

88-
# Add extra paths if provided
89-
if extra_paths:
90-
for path in extra_paths:
91-
paths.extend(["-p", path])
84+
# Convert to compiler flags
85+
path_flags = [item for p in all_paths for item in ["-p", p]]
9286

93-
command = ["vyper", "-f", formatting, filename] + paths
87+
command = ["vyper", "-f", formatting, filename] + path_flags
9488

9589
process = subprocess.Popen(
9690
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
@@ -106,7 +100,7 @@ def vyper_compile(filename, formatting, extra_paths=None):
106100
)
107101

108102

109-
def parse_file(file_path, extra_paths=None):
103+
def parse_file(file_path, extra_paths=[]):
110104
ast = vyper_compile(file_path, "annotated_ast", extra_paths=extra_paths)
111105
metadata = vyper_compile(file_path, "metadata", extra_paths=extra_paths)
112106

0 commit comments

Comments
 (0)