Skip to content

Commit 6b54471

Browse files
althonosMartin Larralde
authored andcommitted
Fix get_lib_name crashing on missing name
`Cargo.toml` manifests do not have to explicitly declare a `name` in the `[lib]` section of a library, but use a slugified version of the `[package]` name. This commit make it so `setuptools_rust` no longer crashes on such manifests.
1 parent 1a7ae02 commit 6b54471

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

setuptools_rust/extension.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ def __init__(self, target, path,
101101
def get_lib_name(self):
102102
cfg = configparser.ConfigParser()
103103
cfg.read(self.path)
104-
return cfg.get('lib', 'name').strip('"')
104+
section = 'lib' if cfg.has_option('lib', 'name') else 'package'
105+
name = cfg.get(section, 'name').strip('"')
106+
return name.replace('-', '_').replace('.', '_')
105107

106108
def get_rust_version(self):
107109
if self.rust_version is None:

0 commit comments

Comments
 (0)