Skip to content

Commit ba1d77e

Browse files
authored
Merge pull request #174 from davidhewitt/update-deps
deps: update versions; switch to tomli
2 parents 4a577d1 + c56b79d commit ba1d77e

File tree

5 files changed

+39
-39
lines changed

5 files changed

+39
-39
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
- Add new default `"auto"` setting for `RustExtension.py_limited_api`. [#137](https://github.com/PyO3/setuptools-rust/pull/137)
77
- Support very verbose cargo build.rs output. [#140](https://github.com/PyO3/setuptools-rust/pull/140)
88

9+
### Changed
10+
- Switch to `tomli` dependency. [#174](https://github.com/PyO3/setuptools-rust/pull/174)
11+
912
### Removed
1013
- Remove `test_rust` command. (`python setup.py test` is deprecated.) [#129](https://github.com/PyO3/setuptools-rust/pull/129)
1114
- Remove `check_rust` command. [#131](https://github.com/PyO3/setuptools-rust/pull/131)

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ classifiers =
2626
[options]
2727
packages = setuptools_rust
2828
zip_safe = True
29-
install_requires = setuptools>=46.1; semantic_version>=2.6.0; toml>=0.9.0; typing_extensions>=3.7.4.3
30-
setup_requires = setuptools>=46.1; setuptools_scm[toml]>=3.4.3
29+
install_requires = setuptools>=46.1; semantic_version>=2.8.2,<3; tomli>=1.2.1; typing_extensions>=3.7.4.3
30+
setup_requires = setuptools>=46.1; setuptools_scm>=6.3.2
3131
python_requires = >=3.6
3232

3333
[options.entry_points]

setuptools_rust/command.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from abc import ABC, abstractmethod
2-
32
from distutils.cmd import Command
43
from distutils.errors import DistutilsPlatformError
54

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

2726
all_optional = all(ext.optional for ext in self.extensions)
2827
try:
29-
version = get_rust_version(
30-
min_version=max(
28+
version = get_rust_version()
29+
if version is None:
30+
min_version = max(
3131
filter(
3232
lambda version: version is not None,
3333
(ext.get_rust_version() for ext in self.extensions),
3434
),
3535
default=None,
3636
)
37-
)
37+
raise DistutilsPlatformError(
38+
"can't find Rust compiler\n\n"
39+
"If you are using an outdated pip version, it is possible a "
40+
"prebuilt wheel is available for this package but pip is not able "
41+
"to install from it. Installing from the wheel would avoid the "
42+
"need for a Rust compiler.\n\n"
43+
"To update pip, run:\n\n"
44+
" pip install --upgrade pip\n\n"
45+
"and then retry package installation.\n\n"
46+
"If you did intend to build this package from source, try "
47+
"installing a Rust compiler from your system package manager and "
48+
"ensure it is on the PATH during installation. Alternatively, "
49+
"rustup (available at https://rustup.rs) is the recommended way "
50+
"to download and update the Rust compiler toolchain."
51+
+ (
52+
f"\n\nThis package requires Rust {min_version}."
53+
if min_version is not None
54+
else ""
55+
)
56+
)
3857
except DistutilsPlatformError as e:
3958
if not all_optional:
4059
raise

setuptools_rust/extension.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from enum import IntEnum, auto
55
from typing import Dict, List, Optional, Union
66

7-
import semantic_version
7+
import tomli
8+
from semantic_version import SimpleSpec
89
from typing_extensions import Literal
910

1011

@@ -145,10 +146,8 @@ def __init__(
145146

146147
def get_lib_name(self):
147148
"""Parse Cargo.toml to get the name of the shared library."""
148-
# We import in here to make sure the the setup_requires are already installed
149-
import toml
150-
151-
cfg = toml.load(self.path)
149+
with open(self.path, "rb") as f:
150+
cfg = tomli.load(f)
152151
name = cfg.get("lib", {}).get("name")
153152
if name is None:
154153
name = cfg.get("package", {}).get("name")
@@ -161,11 +160,11 @@ def get_lib_name(self):
161160
name = re.sub(r"[./\\-]", "_", name)
162161
return name
163162

164-
def get_rust_version(self):
163+
def get_rust_version(self) -> Optional[SimpleSpec]:
165164
if self.rust_version is None:
166165
return None
167166
try:
168-
return semantic_version.SimpleSpec.parse(self.rust_version)
167+
return SimpleSpec(self.rust_version)
169168
except ValueError:
170169
raise DistutilsSetupError(
171170
"Can not parse rust compiler version: %s", self.rust_version

setuptools_rust/utils.py

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import subprocess
22
from distutils.errors import DistutilsPlatformError
3-
from typing import Set, Union
3+
from typing import Optional, Set, Union
44

5-
import semantic_version
5+
from semantic_version import Version
66
from typing_extensions import Literal
77

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

3333

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

6241

6342
def get_rust_target_info(target_triple=None):

0 commit comments

Comments
 (0)