Skip to content

Commit 4879fe8

Browse files
committed
Replaced configparser with toml package for parsing Cargo.toml as configparser was unable to handle array of tables, e.g. multiple [[bench]]s or [[example]]s
1 parent d25a66f commit 4879fe8

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Cargo.lock
1111
/example/target/
1212
/example/*.egg-info
1313
.idea/
14+
.mypy_cache/

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
(open('README.rst').read(), open('CHANGES.rst').read())),
1616
license='MIT',
1717
packages=['setuptools_rust'],
18-
install_requires=['semantic_version>=2.6.0'],
18+
install_requires=['semantic_version>=2.6.0', 'toml>=0.9.0'],
1919
zip_safe=True,
2020
classifiers=[
2121
"Topic :: Software Development :: Version Control",

setuptools_rust/extension.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@
55
from distutils.errors import DistutilsSetupError
66
from .utils import Binding, Strip
77

8-
try:
9-
import configparser
10-
except ImportError:
11-
import ConfigParser as configparser
12-
13-
148
import semantic_version
9+
import toml
1510

1611

1712
class RustExtension:
@@ -99,11 +94,17 @@ def __init__(self, target, path,
9994
self.path = path
10095

10196
def get_lib_name(self):
102-
cfg = configparser.ConfigParser()
103-
cfg.read(self.path)
104-
section = 'lib' if cfg.has_option('lib', 'name') else 'package'
105-
name = cfg.get(section, 'name').strip('\'\"').strip()
106-
return re.sub(r"[./\\-]", "_", name)
97+
cfg = toml.load(self.path)
98+
name = cfg.get('lib', {}).get('name')
99+
if name is None:
100+
name = cfg.get('package', {}).get('name')
101+
if name is None:
102+
raise Exception(
103+
"Can not parse library name from Cargo.toml. "
104+
"Cargo.toml missing value for 'name' key "
105+
"in both the [package] section and the [lib] section")
106+
name = re.sub(r"[./\\-]", "_", name)
107+
return name
107108

108109
def get_rust_version(self):
109110
if self.rust_version is None:

0 commit comments

Comments
 (0)