maturin.bootstrap

Support installing rust before compiling (bootstrapping) maturin.

Installing a package that uses maturin as build backend on a platform without maturin binaries, we install rust in a cache directory if the user doesn't have a rust installation already. Since this bootstrapping requires more dependencies but is only required if rust is missing, we check if cargo is present before requesting those dependencies.

https://setuptools.pypa.io/en/stable/build_meta.html#dynamic-build-dependencies-and-other-build-meta-tweaks

 1"""Support installing rust before compiling (bootstrapping) maturin.
 2
 3Installing a package that uses maturin as build backend on a platform without maturin
 4binaries, we install rust in a cache directory if the user doesn't have a rust
 5installation already. Since this bootstrapping requires more dependencies but is only
 6required if rust is missing, we check if cargo is present before requesting those
 7dependencies.
 8
 9https://setuptools.pypa.io/en/stable/build_meta.html#dynamic-build-dependencies-and-other-build-meta-tweaks
10"""
11
12from __future__ import annotations
13
14import os
15import shutil
16from typing import Any
17
18# noinspection PyUnresolvedReferences
19from setuptools.build_meta import *  # noqa:F403
20
21
22def get_requires_for_build_wheel(config_settings: dict[str, Any] | None = None) -> list[str]:
23    if not os.environ.get("MATURIN_NO_INSTALL_RUST") and not shutil.which("cargo"):
24        return ["puccinialin>=0.1,<0.2"]
25    return []
26
27
28def get_requires_for_build_sdist(config_settings: dict[str, Any] | None = None) -> list[str]:
29    if not os.environ.get("MATURIN_NO_INSTALL_RUST") and not shutil.which("cargo"):
30        return ["puccinialin>=0.1,<0.2"]
31    return []
def get_requires_for_build_wheel(config_settings: dict[str, typing.Any] | None = None) -> list[str]:
23def get_requires_for_build_wheel(config_settings: dict[str, Any] | None = None) -> list[str]:
24    if not os.environ.get("MATURIN_NO_INSTALL_RUST") and not shutil.which("cargo"):
25        return ["puccinialin>=0.1,<0.2"]
26    return []
def get_requires_for_build_sdist(config_settings: dict[str, typing.Any] | None = None) -> list[str]:
29def get_requires_for_build_sdist(config_settings: dict[str, Any] | None = None) -> list[str]:
30    if not os.environ.get("MATURIN_NO_INSTALL_RUST") and not shutil.which("cargo"):
31        return ["puccinialin>=0.1,<0.2"]
32    return []