Skip to content

Commit 832763e

Browse files
committed
use which for PATH check
1 parent a1c09fe commit 832763e

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

noxfile.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from os import environ
3-
from pathlib import Path
3+
from shutil import which
44
import platform
55
import re
66
import sys
@@ -37,17 +37,12 @@ def __init__(self, session: nox.Session):
3737
ci_logger.info("Found %s: %s" % (dep, ver))
3838
self.cargo_install_cmd: tuple[str, ...] = ("cargo", "install")
3939

40-
installed_path = Path("~/.cargo/bin")
41-
4240
if CARGO_BINSTALL in cargo_bins:
4341
ci_logger.info(
4442
"Found %s: %s" % (CARGO_BINSTALL, cargo_bins[CARGO_BINSTALL])
4543
)
46-
elif (
47-
installed_path
48-
/ (CARGO_BINSTALL + "" if platform.system() != "Windows" else ".exe")
49-
).exists():
50-
ci_logger.info("Found %s" % CARGO_BINSTALL)
44+
elif which(CARGO_BINSTALL) is not None:
45+
ci_logger.info("Found: %s in PATH" % CARGO_BINSTALL)
5146
elif not IS_CI:
5247
ci_logger.info("Installing %s" % CARGO_BINSTALL)
5348
match platform.system():
@@ -85,16 +80,12 @@ def install():
8580
dep = req if not ver else f"{req}@{ver}"
8681
session.run(*self.cargo_install_cmd, dep, "--locked", external=True)
8782

88-
installed_path = Path("~/.cargo/bin")
89-
9083
installed = False
9184
if req in self.cargo_bins:
9285
ci_logger.info("Found %s %s" % (req, self.cargo_bins[req]))
9386
installed = True
94-
elif (
95-
installed_path / (req + "" if platform.system() != "Windows" else ".exe")
96-
).exists():
97-
ci_logger.info("Found %s" % req)
87+
elif which(req) is not None:
88+
ci_logger.info("Found: %s in PATH" % req)
9889
installed = True
9990
if ver or not installed:
10091
install()

0 commit comments

Comments
 (0)