Skip to content

Commit 1496257

Browse files
committed
etherscan: use POSIX style paths
1 parent a138d3b commit 1496257

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

crytic_compile/platform/etherscan.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import re
99
import urllib.request
1010
from json.decoder import JSONDecodeError
11-
from pathlib import Path
11+
from pathlib import Path, PurePosixPath
1212
from typing import TYPE_CHECKING, Dict, List, Union, Tuple, Optional
1313

1414
from crytic_compile.compilation_unit import CompilationUnit
@@ -147,23 +147,25 @@ def _handle_multiple_files(
147147

148148
filtered_paths: List[str] = []
149149
for filename, source_code in source_codes.items():
150-
path_filename = Path(filename)
150+
path_filename = PurePosixPath(filename)
151151
if "contracts" in path_filename.parts and not filename.startswith("@"):
152-
path_filename = Path(*path_filename.parts[path_filename.parts.index("contracts") :])
152+
path_filename = PurePosixPath(
153+
*path_filename.parts[path_filename.parts.index("contracts") :]
154+
)
153155

154156
# Convert "absolute" paths such as "/interfaces/IFoo.sol" into relative ones.
155157
# This is needed due to the following behavior from pathlib.Path:
156158
# > When several absolute paths are given, the last is taken as an anchor
157159
# We need to make sure this is relative, so that Path(directory, ...) remains anchored to directory
158160
if path_filename.is_absolute():
159-
path_filename = Path(*path_filename.parts[1:])
161+
path_filename = PurePosixPath(*path_filename.parts[1:])
160162

161-
filtered_paths.append(str(path_filename))
162-
path_filename = Path(directory, path_filename)
163+
filtered_paths.append(path_filename.as_posix())
164+
path_filename_disk = Path(directory, path_filename)
163165

164-
if not os.path.exists(path_filename.parent):
165-
os.makedirs(path_filename.parent)
166-
with open(path_filename, "w", encoding="utf8") as file_desc:
166+
if not os.path.exists(path_filename_disk.parent):
167+
os.makedirs(path_filename_disk.parent)
168+
with open(path_filename_disk, "w", encoding="utf8") as file_desc:
167169
file_desc.write(source_code["content"])
168170

169171
return list(filtered_paths), directory

0 commit comments

Comments
 (0)