Skip to content

Commit 8b9c060

Browse files
committed
fix new linting errors
1 parent 0fc24dd commit 8b9c060

File tree

5 files changed

+174
-133
lines changed

5 files changed

+174
-133
lines changed

buildbot_effects/__init__.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
from .options import EffectsOptions
1414

1515

16+
class BuildbotEffectsError(Exception):
17+
pass
18+
19+
1620
def run(
1721
cmd: list[str],
1822
stdin: int | IO[str] | None = None,
@@ -151,8 +155,12 @@ def pipe() -> Iterator[tuple[IO[str], IO[str]]]:
151155

152156

153157
def run_effects(
154-
drv_path: str, drv: dict[str, Any], secrets: dict[str, Any] = {}
158+
drv_path: str,
159+
drv: dict[str, Any],
160+
secrets: dict[str, Any] | None = None,
155161
) -> None:
162+
if secrets is None:
163+
secrets = {}
156164
builder = drv["builder"]
157165
args = drv["args"]
158166
sandboxed_cmd = [
@@ -165,7 +173,8 @@ def run_effects(
165173
env["NIX_BUILD_TOP"] = "/build"
166174
bwrap = shutil.which("bwrap")
167175
if bwrap is None:
168-
raise Exception("bwrap not found")
176+
msg = "bwrap' executable not found"
177+
raise BuildbotEffectsError(msg)
169178

170179
bubblewrap_cmd = [
171180
"nix",
@@ -183,7 +192,7 @@ def run_effects(
183192
"--chdir",
184193
"/build",
185194
"--tmpfs",
186-
"/tmp",
195+
"/tmp", # noqa: S108
187196
"--tmpfs",
188197
"/build",
189198
"--proc",
@@ -210,7 +219,7 @@ def run_effects(
210219
"--ro-bind",
211220
tmp.name,
212221
"/run/secrets.json",
213-
]
222+
],
214223
)
215224
bubblewrap_cmd.extend(env_args(env))
216225
bubblewrap_cmd.append("--")
@@ -230,4 +239,5 @@ def run_effects(
230239
print(line, end="")
231240
proc.wait()
232241
if proc.returncode != 0:
233-
raise Exception(f"command failed with exit code {proc.returncode}")
242+
msg = f"command failed with exit code {proc.returncode}"
243+
raise BuildbotEffectsError(msg)

buildbot_effects/cli.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import argparse
2+
import json
23
from collections.abc import Callable
34
from pathlib import Path
4-
import json
55

6+
from . import instantiate_effects, list_effects, parse_derivation, run_effects
67
from .options import EffectsOptions
7-
from . import list_effects, instantiate_effects, parse_derivation, run_effects
88

99

1010
def list_command(options: EffectsOptions) -> None:
@@ -16,10 +16,7 @@ def run_command(options: EffectsOptions) -> None:
1616
drvs = parse_derivation(drv_path)
1717
drv = next(iter(drvs.values()))
1818

19-
if options.secrets:
20-
secrets = json.loads(options.secrets.read_text())
21-
else:
22-
secrets = {}
19+
secrets = json.loads(options.secrets.read_text()) if options.secrets else {}
2320
run_effects(drv_path, drv, secrets=secrets)
2421

2522

0 commit comments

Comments
 (0)