Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path search upon python3 -m maturin #1038

Merged
merged 2 commits into from
Aug 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:])