Fix python module invocation (#2563)

This commit is contained in:
Matteo Vitali 2023-02-04 14:23:13 +01:00 committed by GitHub
parent dd0145624b
commit 5a9258327b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,23 @@ import sys
import sysconfig
from pathlib import Path
RUFF_PATHS = [
Path(sysconfig.get_config_var("userbase")) / "bin" / "ruff",
Path(sysconfig.get_path("scripts")) / "ruff",
]
def find_ruff_bin() -> Path:
"""Return the ruff binary path."""
for ruff_path in RUFF_PATHS:
if ruff_path.is_file():
return ruff_path
raise FileNotFoundError(ruff_path)
if __name__ == "__main__":
ruff = Path(sysconfig.get_path("scripts")) / "ruff"
try:
ruff = find_ruff_bin()
except FileNotFoundError as e:
raise FileNotFoundError(e) from e
sys.exit(os.spawnv(os.P_WAIT, ruff, [ruff, *sys.argv[1:]]))