diff --git a/CHANGELOG.md b/CHANGELOG.md index 61756b47..d6962f28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.1.2 (UNRELEASED) +### Changed +- Removed dependency on `tomli` to simplify installation. + ## 1.1.1 (2021-12-01) ### Fixed - 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) diff --git a/setup.cfg b/setup.cfg index 18cef1dd..9cf0237a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,7 +26,7 @@ classifiers = [options] packages = setuptools_rust zip_safe = True -install_requires = setuptools>=46.1; semantic_version>=2.8.2,<3; tomli>=1.2.1; typing_extensions>=3.7.4.3 +install_requires = setuptools>=46.1; semantic_version>=2.8.2,<3; typing_extensions>=3.7.4.3 setup_requires = setuptools>=46.1; setuptools_scm>=6.3.2 python_requires = >=3.6 diff --git a/setuptools_rust/extension.py b/setuptools_rust/extension.py index c0d4c0db..fb213961 100644 --- a/setuptools_rust/extension.py +++ b/setuptools_rust/extension.py @@ -1,10 +1,11 @@ +import json import os import re +import subprocess from distutils.errors import DistutilsSetupError from enum import IntEnum, auto from typing import Dict, List, Optional, Union -import tomli from semantic_version import SimpleSpec from typing_extensions import Literal @@ -146,23 +147,23 @@ def __init__( def get_lib_name(self) -> str: """Parse Cargo.toml to get the name of the shared library.""" - 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") - if name is None: - raise Exception( - "Can not parse library name from Cargo.toml. " - "Cargo.toml missing value for 'name' key " - "in both the [package] section and the [lib] section" + data = json.loads( + subprocess.check_output( + [ + "cargo", + "metadata", + "--manifest-path", + self.path, + "--format-version", + "1", + ] ) - if not isinstance(name, str): - raise Exception( - f"Expected string for Rust library name in Cargo.toml, got {name}" - ) - name = re.sub(r"[./\\-]", "_", name) - return name + ) + root_key = data["resolve"]["root"] + [pkg] = [p for p in data["packages"] if p["id"] == root_key] + name = pkg["targets"][0]["name"] + assert isinstance(name, str) + return re.sub(r"[./\\-]", "_", name) def get_rust_version(self) -> Optional[SimpleSpec]: # type: ignore[no-any-unimported] if self.rust_version is None: