Skip to content

Commit

Permalink
deps: update semantic_version
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Sep 22, 2021
1 parent c1813ac commit 45a192a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
- Add new default `"auto"` setting for `RustExtension.py_limited_api`. [#137](https://github.com/PyO3/setuptools-rust/pull/137)
- Support very verbose cargo build.rs output. [#140](https://github.com/PyO3/setuptools-rust/pull/140)

### Changed
- Switch to `tomli` dependency. [#174](https://github.com/PyO3/setuptools-rust/pull/174)

### Removed
- Remove `test_rust` command. (`python setup.py test` is deprecated.) [#129](https://github.com/PyO3/setuptools-rust/pull/129)
- Remove `check_rust` command. [#131](https://github.com/PyO3/setuptools-rust/pull/131)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers =
[options]
packages = setuptools_rust
zip_safe = True
install_requires = setuptools>=46.1; semantic_version>=2.6.0; tomli>=1.2.1; typing_extensions>=3.7.4.3
install_requires = setuptools>=46.1; semantic_version>=2.8.2,<3; tomli>=1.2.1; typing_extensions>=3.7.4.3
setup_requires = setuptools>=46.1; setuptools_scm>=6.3.2
python_requires = >=3.6

Expand Down
25 changes: 22 additions & 3 deletions setuptools_rust/command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from abc import ABC, abstractmethod

from distutils.cmd import Command
from distutils.errors import DistutilsPlatformError

Expand All @@ -26,15 +25,35 @@ def run(self):

all_optional = all(ext.optional for ext in self.extensions)
try:
version = get_rust_version(
version = get_rust_version()
if version is None:
min_version=max(
filter(
lambda version: version is not None,
(ext.get_rust_version() for ext in self.extensions),
),
default=None,
)
)
raise DistutilsPlatformError(
"can't find Rust compiler\n\n"
"If you are using an outdated pip version, it is possible a "
"prebuilt wheel is available for this package but pip is not able "
"to install from it. Installing from the wheel would avoid the "
"need for a Rust compiler.\n\n"
"To update pip, run:\n\n"
" pip install --upgrade pip\n\n"
"and then retry package installation.\n\n"
"If you did intend to build this package from source, try "
"installing a Rust compiler from your system package manager and "
"ensure it is on the PATH during installation. Alternatively, "
"rustup (available at https://rustup.rs) is the recommended way "
"to download and update the Rust compiler toolchain."
+ (
f"\n\nThis package requires Rust {min_version}."
if min_version is not None
else ""
)
)
except DistutilsPlatformError as e:
if not all_optional:
raise
Expand Down
6 changes: 3 additions & 3 deletions setuptools_rust/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from enum import IntEnum, auto
from typing import Dict, List, Optional, Union

import semantic_version
import tomli
from semantic_version import SimpleSpec
from typing_extensions import Literal


Expand Down Expand Up @@ -160,11 +160,11 @@ def get_lib_name(self):
name = re.sub(r"[./\\-]", "_", name)
return name

def get_rust_version(self):
def get_rust_version(self) -> Optional[SimpleSpec]:
if self.rust_version is None:
return None
try:
return semantic_version.SimpleSpec.parse(self.rust_version)
return SimpleSpec(self.rust_version)
except ValueError:
raise DistutilsSetupError(
"Can not parse rust compiler version: %s", self.rust_version
Expand Down
31 changes: 5 additions & 26 deletions setuptools_rust/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import subprocess
from distutils.errors import DistutilsPlatformError
from typing import Set, Union
from typing import Optional, Set, Union

import semantic_version
from semantic_version import Version
from typing_extensions import Literal

from .extension import Binding, RustExtension
Expand Down Expand Up @@ -31,33 +31,12 @@ def binding_features(
raise DistutilsPlatformError(f"unknown Rust binding: '{ext.binding}'")


def get_rust_version(min_version=None):
def get_rust_version() -> Optional[Version]:
try:
output = subprocess.check_output(["rustc", "-V"]).decode("latin-1")
return semantic_version.Version(output.split(" ")[1], partial=True)
return Version(output.split(" ")[1])
except (subprocess.CalledProcessError, OSError):
raise DistutilsPlatformError(
"can't find Rust compiler\n\n"
"If you are using an outdated pip version, it is possible a "
"prebuilt wheel is available for this package but pip is not able "
"to install from it. Installing from the wheel would avoid the "
"need for a Rust compiler.\n\n"
"To update pip, run:\n\n"
" pip install --upgrade pip\n\n"
"and then retry package installation.\n\n"
"If you did intend to build this package from source, try "
"installing a Rust compiler from your system package manager and "
"ensure it is on the PATH during installation. Alternatively, "
"rustup (available at https://rustup.rs) is the recommended way "
"to download and update the Rust compiler toolchain."
+ (
f"\n\nThis package requires Rust {min_version}."
if min_version is not None
else ""
)
)
except Exception as exc:
raise DistutilsPlatformError(f"can't get rustc version: {str(exc)}")
return None


def get_rust_target_info(target_triple=None):
Expand Down

0 comments on commit 45a192a

Please sign in to comment.