Skip to content

Commit fcab70a

Browse files
committed
Merge branch 'bcmeyers'
2 parents 3b18726 + 4879fe8 commit fcab70a

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

build-wheels.sh

100644100755
File mode changed.

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: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
from __future__ import print_function, absolute_import
22
import os
33
import re
4-
import sys
54
from distutils.errors import DistutilsSetupError
65
from .utils import Binding, Strip
76

8-
try:
9-
import configparser
10-
except ImportError:
11-
import ConfigParser as configparser
12-
13-
147
import semantic_version
158

169

@@ -99,18 +92,28 @@ def __init__(self, target, path,
9992
self.path = path
10093

10194
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)
95+
""" Parse Cargo.toml to get the name of the shared library. """
96+
# We import in here to make sure the the setup_requires are already installed
97+
import toml
98+
99+
cfg = toml.load(self.path)
100+
name = cfg.get('lib', {}).get('name')
101+
if name is None:
102+
name = cfg.get('package', {}).get('name')
103+
if name is None:
104+
raise Exception(
105+
"Can not parse library name from Cargo.toml. "
106+
"Cargo.toml missing value for 'name' key "
107+
"in both the [package] section and the [lib] section")
108+
name = re.sub(r"[./\\-]", "_", name)
109+
return name
107110

108111
def get_rust_version(self):
109112
if self.rust_version is None:
110113
return None
111114
try:
112115
return semantic_version.Spec(self.rust_version)
113-
except:
116+
except ValueError:
114117
raise DistutilsSetupError(
115118
'Can not parse rust compiler version: %s', self.rust_version)
116119

0 commit comments

Comments
 (0)