Skip to content
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

Remove the dependency on tomli to simplify installation #200

Merged
merged 1 commit into from
Dec 4, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
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.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

Expand Down
35 changes: 18 additions & 17 deletions setuptools_rust/extension.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand Down