Skip to content

Commit a0f7a75

Browse files
committed
Remove the dependency on tomli to simplify installation
Depending on tomli produces circular dependencies when attempting to install from sdists only: pyca/cryptography#6671
1 parent ea35f83 commit a0f7a75

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.1.2 (UNRELEASED)
4+
### Changed
5+
- Removed dependency on `tomli` to simplify installation.
6+
37
## 1.1.1 (2021-12-01)
48
### Fixed
59
- Fix regression from `setuptools-rust` 1.1.0 which broke builds for the `x86_64-unknown-linux-musl` target. [#194](https://github.com/PyO3/setuptools-rust/pull/194)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ classifiers =
2626
[options]
2727
packages = setuptools_rust
2828
zip_safe = True
29-
install_requires = setuptools>=46.1; semantic_version>=2.8.2,<3; tomli>=1.2.1; typing_extensions>=3.7.4.3
29+
install_requires = setuptools>=46.1; semantic_version>=2.8.2,<3; typing_extensions>=3.7.4.3
3030
setup_requires = setuptools>=46.1; setuptools_scm>=6.3.2
3131
python_requires = >=3.6
3232

setuptools_rust/extension.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import json
12
import os
23
import re
4+
import subprocess
35
from distutils.errors import DistutilsSetupError
46
from enum import IntEnum, auto
57
from typing import Dict, List, Optional, Union
68

7-
import tomli
89
from semantic_version import SimpleSpec
910
from typing_extensions import Literal
1011

@@ -146,23 +147,23 @@ def __init__(
146147

147148
def get_lib_name(self) -> str:
148149
"""Parse Cargo.toml to get the name of the shared library."""
149-
with open(self.path, "rb") as f:
150-
cfg = tomli.load(f)
151-
name = cfg.get("lib", {}).get("name")
152-
if name is None:
153-
name = cfg.get("package", {}).get("name")
154-
if name is None:
155-
raise Exception(
156-
"Can not parse library name from Cargo.toml. "
157-
"Cargo.toml missing value for 'name' key "
158-
"in both the [package] section and the [lib] section"
150+
data = json.loads(
151+
subprocess.check_output(
152+
[
153+
"cargo",
154+
"metadata",
155+
"--manifest-path",
156+
self.path,
157+
"--format-version",
158+
"1",
159+
]
159160
)
160-
if not isinstance(name, str):
161-
raise Exception(
162-
f"Expected string for Rust library name in Cargo.toml, got {name}"
163-
)
164-
name = re.sub(r"[./\\-]", "_", name)
165-
return name
161+
)
162+
root_key = data["resolve"]["root"]
163+
[pkg] = [p for p in data["packages"] if p["id"] == root_key]
164+
name = pkg["targets"][0]["name"]
165+
assert isinstance(name, str)
166+
return re.sub(r"[./\\-]", "_", name)
166167

167168
def get_rust_version(self) -> Optional[SimpleSpec]: # type: ignore[no-any-unimported]
168169
if self.rust_version is None:

0 commit comments

Comments
 (0)