|
1 | 1 | import logging |
2 | 2 | from os import environ |
3 | | -from pathlib import Path |
| 3 | +from shutil import which |
4 | 4 | import platform |
5 | 5 | import re |
6 | 6 | import sys |
@@ -37,17 +37,12 @@ def __init__(self, session: nox.Session): |
37 | 37 | ci_logger.info("Found %s: %s" % (dep, ver)) |
38 | 38 | self.cargo_install_cmd: tuple[str, ...] = ("cargo", "install") |
39 | 39 |
|
40 | | - installed_path = Path("~/.cargo/bin") |
41 | | - |
42 | 40 | if CARGO_BINSTALL in cargo_bins: |
43 | 41 | ci_logger.info( |
44 | 42 | "Found %s: %s" % (CARGO_BINSTALL, cargo_bins[CARGO_BINSTALL]) |
45 | 43 | ) |
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) |
51 | 46 | elif not IS_CI: |
52 | 47 | ci_logger.info("Installing %s" % CARGO_BINSTALL) |
53 | 48 | match platform.system(): |
@@ -85,16 +80,12 @@ def install(): |
85 | 80 | dep = req if not ver else f"{req}@{ver}" |
86 | 81 | session.run(*self.cargo_install_cmd, dep, "--locked", external=True) |
87 | 82 |
|
88 | | - installed_path = Path("~/.cargo/bin") |
89 | | - |
90 | 83 | installed = False |
91 | 84 | if req in self.cargo_bins: |
92 | 85 | ci_logger.info("Found %s %s" % (req, self.cargo_bins[req])) |
93 | 86 | 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) |
98 | 89 | installed = True |
99 | 90 | if ver or not installed: |
100 | 91 | install() |
|
0 commit comments