Skip to content

Commit 6535531

Browse files
committed
avoid shell=True in subcommands; use conda.bat on windows
1 parent d337434 commit 6535531

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/bioimageio/core/_resource_tests.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
from .digest_spec import get_test_input_sample, get_test_output_sample
7575
from .sample import Sample
7676

77+
CONDA_CMD = "conda.bat" if platform.system() == "Windows" else "conda"
78+
7779

7880
class DeprecatedKwargs(TypedDict):
7981
absolute_tolerance: NotRequired[AbsoluteTolerance]
@@ -191,7 +193,7 @@ def test_model(
191193

192194
def default_run_command(args: Sequence[str]):
193195
logger.info("running '{}'...", " ".join(args))
194-
_ = subprocess.run(args, shell=True, text=True, check=True)
196+
_ = subprocess.check_call(args)
195197

196198

197199
def test_description(
@@ -379,21 +381,22 @@ def _test_in_env(
379381
env_name = hashlib.sha256(encoded_env).hexdigest()
380382

381383
try:
382-
run_command(["where" if platform.system() == "Windows" else "which", "conda"])
384+
run_command(["where" if platform.system() == "Windows" else "which", CONDA_CMD])
383385
except Exception as e:
384386
raise RuntimeError("Conda not available") from e
385387

386388
try:
387-
run_command(["conda", "activate", env_name])
389+
run_command([CONDA_CMD, "activate", env_name])
388390
except Exception:
391+
working_dir.mkdir(parents=True, exist_ok=True)
389392
path = working_dir / "env.yaml"
390393
try:
391394
_ = path.write_bytes(encoded_env)
392395
logger.debug("written conda env to {}", path)
393396
run_command(
394-
["conda", "env", "create", f"--file={path}", f"--name={env_name}"]
397+
[CONDA_CMD, "env", "create", f"--file={path}", f"--name={env_name}"]
395398
)
396-
run_command(["conda", "activate", env_name])
399+
run_command([CONDA_CMD, "activate", env_name])
397400
except Exception as e:
398401
summary = descr.validation_summary
399402
summary.add_detail(
@@ -424,7 +427,7 @@ def _test_in_env(
424427
run_command(
425428
cmd := (
426429
[
427-
"conda",
430+
CONDA_CMD,
428431
"run",
429432
"-n",
430433
env_name,

0 commit comments

Comments
 (0)