Skip to content

Commit

Permalink
Merge pull request #200 from alex/drop-tomli
Browse files Browse the repository at this point in the history
Remove the dependency on tomli to simplify installation
  • Loading branch information
davidhewitt authored Dec 4, 2021
2 parents ea35f83 + a0f7a75 commit a9cd47c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
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

0 comments on commit a9cd47c

Please sign in to comment.