Skip to content

deps: update versions; switch to tomli #174

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

Merged
merged 2 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
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
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
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ classifiers =
[options]
packages = setuptools_rust
zip_safe = True
install_requires = setuptools>=46.1; semantic_version>=2.6.0; toml>=0.9.0; typing_extensions>=3.7.4.3
setup_requires = setuptools>=46.1; setuptools_scm[toml]>=3.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

[options.entry_points]
Expand Down
27 changes: 23 additions & 4 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(
min_version=max(
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
13 changes: 6 additions & 7 deletions setuptools_rust/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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 @@ -145,10 +146,8 @@ def __init__(

def get_lib_name(self):
"""Parse Cargo.toml to get the name of the shared library."""
# We import in here to make sure the the setup_requires are already installed
import toml

cfg = toml.load(self.path)
with open(self.path, "rb") as f:
cfg = tomli.load(f)
name = cfg.get("lib", {}).get("name")
if name is None:
name = cfg.get("package", {}).get("name")
Expand All @@ -161,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