| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import os |
| 4 |
import sys |
| 5 |
from pathlib import Path |
| 6 |
import sysconfig |
| 7 |
from typing import Optional |
| 8 |
|
| 9 |
|
| 10 |
def get_maturin_path() -> Optional[Path]: |
| 11 |
SCRIPT_NAME = "maturin" |
| 12 |
|
| 13 |
def script_dir(scheme: str) -> str: |
| 14 |
return sysconfig.get_path("scripts", scheme) |
| 15 |
|
| 16 |
def script_exists(dir: str) -> bool: |
| 17 |
for _, _, files in os.walk(dir): |
| 18 |
for f in files: |
| 19 |
name, *_ = os.path.splitext(f) |
| 20 |
if name == SCRIPT_NAME: |
| 21 |
return True |
| 22 |
|
| 23 |
return False |
| 24 |
|
| 25 |
paths = list( |
| 26 |
filter( |
| 27 |
script_exists, |
| 28 |
filter(os.path.exists, map(script_dir, sysconfig.get_scheme_names())), |
| 29 |
) |
| 30 |
) |
| 31 |
|
| 32 |
if paths: |
| 33 |
return Path(paths[0]) / SCRIPT_NAME |
| 34 |
|
| 35 |
return None |
| 36 |
|
| 37 |
|
| 38 |
if __name__ == "__main__": |
| 39 |
maturin = get_maturin_path() |
| 40 |
if maturin is None: |
| 41 |
print("Unable to find `maturin` script") |
| 42 |
exit(1) |
| 43 |
|
| 44 |
if sys.platform == "win32": |
| 45 |
import subprocess |
| 46 |
|
| 47 |
code = subprocess.call([str(maturin)] + sys.argv[1:]) |
| 48 |
sys.exit(code) |
| 49 |
else: |
| 50 |
os.execv(maturin, [str(maturin)] + sys.argv[1:]) |