Skip to content

Commit cf3bfd0

Browse files
committed
auto-clean: fix typing errors and lint warnings
1 parent 9e786ac commit cf3bfd0

File tree

9 files changed

+39
-29
lines changed

9 files changed

+39
-29
lines changed

crytic_compile/platform/embark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def clean(self, **_kwargs: str) -> None:
172172
"""Clean compilation artifacts
173173
174174
Args:
175-
**kwargs: unused.
175+
**_kwargs: unused.
176176
"""
177177
return
178178

crytic_compile/platform/foundry.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from crytic_compile.platform.types import Type
1717
from crytic_compile.utils.naming import convert_filename
1818
from crytic_compile.utils.natspec import Natspec
19+
from crytic_compile.utils.subprocess import run
1920

2021
# Handle cycle
2122
if TYPE_CHECKING:
@@ -157,13 +158,21 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
157158
compiler=compiler, version=version, optimized=optimized, optimize_runs=runs
158159
)
159160

160-
def clean(self, **_kwargs: str) -> None:
161+
def clean(self, **kwargs: str) -> None:
161162
"""Clean compilation artifacts
162163
163164
Args:
164-
**kwargs: unused.
165+
**kwargs: optional arguments.
165166
"""
166-
return
167+
168+
ignore_compile = kwargs.get("foundry_ignore_compile", False) or kwargs.get(
169+
"ignore_compile", False
170+
)
171+
172+
if ignore_compile:
173+
return
174+
175+
run(["forge", "clean"], cwd=self._target)
167176

168177
@staticmethod
169178
def is_supported(target: str, **kwargs: str) -> bool:

crytic_compile/platform/hardhat.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import shutil
88
import subprocess
99
from pathlib import Path
10-
from typing import TYPE_CHECKING, Dict, List, Optional, Union
10+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union
1111

1212
from crytic_compile.compiler.compiler import CompilerVersion
1313
from crytic_compile.platform.exceptions import InvalidCompilation
@@ -36,17 +36,6 @@ class Hardhat(AbstractPlatform):
3636
PROJECT_URL = "https://github.com/nomiclabs/hardhat"
3737
TYPE = Type.HARDHAT
3838

39-
def _settings(self, args):
40-
hardhat_ignore_compile = args.get("hardhat_ignore_compile", False) or args.get(
41-
"ignore_compile", False
42-
)
43-
44-
base_cmd = ["hardhat"]
45-
if not args.get("npx_disable", False):
46-
base_cmd = ["npx"] + base_cmd
47-
48-
return hardhat_ignore_compile, base_cmd
49-
5039
# pylint: disable=too-many-locals,too-many-statements
5140
def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
5241
"""Run the compilation
@@ -242,6 +231,18 @@ def _guessed_tests(self) -> List[str]:
242231
"""
243232
return ["hardhat test"]
244233

234+
@staticmethod
235+
def _settings(args: Dict[str, Any]) -> Tuple[bool, List[str]]:
236+
hardhat_ignore_compile = args.get("hardhat_ignore_compile", False) or args.get(
237+
"ignore_compile", False
238+
)
239+
240+
base_cmd = ["hardhat"]
241+
if not args.get("npx_disable", False):
242+
base_cmd = ["npx"] + base_cmd
243+
244+
return hardhat_ignore_compile, base_cmd
245+
245246
def _get_hardhat_paths(
246247
self, base_cmd: List[str], args: Dict[str, str]
247248
) -> Dict[str, Union[Path, str]]:

crytic_compile/platform/solc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def clean(self, **_kwargs: str) -> None:
186186
"""Clean compilation artifacts
187187
188188
Args:
189-
**kwargs: unused.
189+
**_kwargs: unused.
190190
"""
191191
return
192192

crytic_compile/platform/standard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def clean(self, **_kwargs: str) -> None:
9797
"""Clean compilation artifacts
9898
9999
Args:
100-
**kwargs: unused.
100+
**_kwargs: unused.
101101
"""
102102
return
103103

crytic_compile/platform/truffle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def clean(self, **_kwargs: str) -> None:
282282
"""Clean compilation artifacts
283283
284284
Args:
285-
**kwargs: unused.
285+
**_kwargs: unused.
286286
"""
287287
return
288288

crytic_compile/platform/vyper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def clean(self, **_kwargs: str) -> None:
9191
"""Clean compilation artifacts
9292
9393
Args:
94-
**kwargs: unused.
94+
**_kwargs: unused.
9595
"""
9696
return
9797

crytic_compile/platform/waffle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def clean(self, **_kwargs: str) -> None:
223223
"""Clean compilation artifacts
224224
225225
Args:
226-
**kwargs: unused.
226+
**_kwargs: unused.
227227
"""
228228
return
229229

crytic_compile/utils/subprocess.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
from pathlib import Path
44
import shutil
55
import subprocess
6-
from typing import Dict, List
6+
from typing import Any, Dict, List, Optional, Union
77

88
LOGGER = logging.getLogger("CryticCompile")
99

1010

1111
def run(
1212
cmd: List[str],
13-
cwd: os.PathLike | None = None,
14-
extra_env: Dict[str, str] | None = None,
15-
**kwargs,
16-
) -> subprocess.CompletedProcess | None:
13+
cwd: Optional[Union[str, os.PathLike]] = None,
14+
extra_env: Optional[Dict[str, str]] = None,
15+
**kwargs: Any,
16+
) -> Optional[subprocess.CompletedProcess]:
1717
"""
1818
Execute a command in a cross-platform compatible way.
1919
@@ -28,7 +28,7 @@ def run(
2828
None: if there was a problem executing
2929
"""
3030
subprocess_cwd = Path(os.getcwd() if cwd is None else cwd).resolve()
31-
subprocess_env = None if extra_env is None else dict(os.environ, extra_env)
31+
subprocess_env = None if extra_env is None else dict(os.environ, **extra_env)
3232
subprocess_exe = shutil.which(cmd[0])
3333

3434
if subprocess_exe is None:
@@ -43,11 +43,11 @@ def run(
4343

4444
try:
4545
return subprocess.run(
46-
cmd, cwd=subprocess_cwd, executable=subprocess_exe, env=subprocess_env, **kwargs
46+
cmd, executable=subprocess_exe, cwd=subprocess_cwd, env=subprocess_env, **kwargs
4747
)
4848
except FileNotFoundError:
4949
LOGGER.error("Could not execute `%s`, is it installed and in PATH?", cmd[0])
5050
except OSError:
51-
LOGGER.error("OS error executing:", exc_info=1)
51+
LOGGER.error("OS error executing:", exc_info=True)
5252

5353
return None

0 commit comments

Comments
 (0)