| 47 | self.extensions = extensions |
| 48 | |
| 49 | def run(self) -> None: |
| 50 | if not self.extensions: |
| 51 | logger.info("%s: no rust_extensions defined", self.get_command_name()) |
| 52 | return |
| 53 | |
| 54 | all_optional = all(ext.optional for ext in self.extensions) |
| 55 | # Use the environment of the first non-optional extension, or the first optional |
| 56 | # extension if there is no non-optional extension. |
| 57 | env = None |
| 58 | for ext in self.extensions: |
| 59 | if ext.env: |
| 60 | env = ext.env |
| 61 | if not ext.optional: |
| 62 | break |
| 63 | try: |
| 64 | version = get_rust_version(env) |
| 65 | if version is None: |
| 66 | min_version = max( # type: ignore[type-var] |
| 67 | filter( |
| 68 | lambda version: version is not None, |
| 69 | (ext.get_rust_version() for ext in self.extensions), |
| 70 | ), |
| 71 | default=None, |
| 72 | ) |
| 73 | raise PlatformError( |
| 74 | "can't find Rust compiler\n\n" |
| 75 | "If you are using an outdated pip version, it is possible a " |
| 76 | "prebuilt wheel is available for this package but pip is not able " |
| 77 | "to install from it. Installing from the wheel would avoid the " |
| 78 | "need for a Rust compiler.\n\n" |
| 79 | "To update pip, run:\n\n" |
| 80 | " pip install --upgrade pip\n\n" |
| 81 | "and then retry package installation.\n\n" |
| 82 | "If you did intend to build this package from source, try " |
| 83 | "installing a Rust compiler from your system package manager and " |
| 84 | "ensure it is on the PATH during installation. Alternatively, " |
| 85 | "rustup (available at https://rustup.rs) is the recommended way " |
| 86 | "to download and update the Rust compiler toolchain." |
| 87 | + ( |
| 88 | f"\n\nThis package requires Rust {min_version}." |
| 89 | if min_version is not None |
| 90 | else "" |
| 91 | ) |
| 92 | ) |
| 93 | except PlatformError as e: |
| 94 | if not all_optional: |
| 95 | raise |
| 96 | else: |
| 97 | print(str(e)) |
| 98 | return |
| 99 | |
| 100 | for ext in self.extensions: |
| 101 | try: |
| 102 | rust_version = ext.get_rust_version() |
| 103 | if rust_version is not None and version not in rust_version: |
| 104 | raise PlatformError( |
| 105 | f"Rust {version} does not match extension requirement {rust_version}" |
| 106 | ) |