Skip to content

Commit

Permalink
Merge pull request #1038 from bhrollins/patch-1
Browse files Browse the repository at this point in the history
Fix path search upon `python3 -m  maturin`
  • Loading branch information
messense authored Aug 5, 2022
2 parents 07360b0 + 3ff682e commit 2876dbe
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions maturin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,41 @@
import sys
from pathlib import Path
import sysconfig
from typing import Optional


def get_maturin_path() -> Optional[Path]:
SCRIPT_NAME = "maturin"

def script_dir(scheme: str) -> Path:
return sysconfig.get_path("scripts", scheme)

def script_exists(dir: Path) -> bool:
for _, _, files in os.walk(dir):
for f in files:
name, *_ = os.path.splitext(f)
if name == SCRIPT_NAME:
return True

return False

paths = list(
filter(
script_exists,
filter(os.path.exists, map(script_dir, sysconfig.get_scheme_names())),
)
)

if paths:
return Path(paths[0]) / SCRIPT_NAME

return None


if __name__ == "__main__":
scripts_dir = sysconfig.get_path("scripts")
maturin = Path(scripts_dir) / "maturin"
maturin = get_maturin_path()
if maturin is None:
print("Unable to find `maturin` script")
exit(1)

os.execv(maturin, [str(maturin)] + sys.argv[1:])

0 comments on commit 2876dbe

Please sign in to comment.