Skip to content

Commit 6d87a5b

Browse files
tomtaudavidhewitt
andauthored
fix get_lib_name (#280)
* fix `get_lib_name` before it fails with `TypeError: _metadata() missing 1 required positional argument: 'cargo'` * Add changelog and test Co-authored-by: David Hewitt <[email protected]>
1 parent f53455e commit 6d87a5b

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
### Fixed
5+
- Fix regression in `get_lib_name` crashing since 1.5.0. [#280](https://github.com/PyO3/setuptools-rust/pull/280)
6+
37
## 1.5.0 (2022-08-09)
48
### Added
59
- Add support for extension modules built for wasm32-unknown-emscripten with Pyodide. [#244](https://github.com/PyO3/setuptools-rust/pull/244)
@@ -12,7 +16,6 @@
1216
- Fix RustBin build without wheel. [#273](https://github.com/PyO3/setuptools-rust/pull/273)
1317
- Fix RustBin setuptools install. [#275](https://github.com/PyO3/setuptools-rust/pull/275)
1418

15-
1619
## 1.4.1 (2022-07-05)
1720
### Fixed
1821
- Fix crash when checking Rust version. [#263](https://github.com/PyO3/setuptools-rust/pull/263)

setuptools_rust/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def __init__(
174174

175175
def get_lib_name(self, *, quiet: bool) -> str:
176176
"""Parse Cargo.toml to get the name of the shared library."""
177-
metadata = self._metadata(quiet=quiet)
177+
metadata = self.metadata(quiet=quiet)
178178
root_key = metadata["resolve"]["root"]
179179
[pkg] = [p for p in metadata["packages"] if p["id"] == root_key]
180180
name = pkg["targets"][0]["name"]

tests/test_extension.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,27 @@
33
import pytest
44
from pytest import CaptureFixture, MonkeyPatch
55

6-
from setuptools_rust.extension import RustBin
6+
from setuptools_rust.extension import RustBin, RustExtension
7+
8+
SETUPTOOLS_RUST_DIR = Path(__file__).parent.parent
79

810

911
@pytest.fixture()
1012
def hello_world_bin() -> RustBin:
11-
setuptools_rust_dir = Path(__file__).parent.parent
1213
return RustBin(
1314
"hello-world",
1415
path=(
15-
setuptools_rust_dir / "examples" / "hello-world" / "Cargo.toml"
16+
SETUPTOOLS_RUST_DIR / "examples" / "hello-world" / "Cargo.toml"
17+
).as_posix(),
18+
)
19+
20+
21+
@pytest.fixture()
22+
def namespace_package_extension() -> RustExtension:
23+
return RustExtension(
24+
"namespace_package.rust",
25+
path=(
26+
SETUPTOOLS_RUST_DIR / "examples" / "namespace_package" / "Cargo.toml"
1627
).as_posix(),
1728
)
1829

@@ -38,3 +49,11 @@ def test_metadata_cargo_log(
3849
captured = capfd.readouterr()
3950
assert captured.out == ""
4051
assert captured.err == ""
52+
53+
54+
def test_get_lib_name_namespace_package(
55+
namespace_package_extension: RustExtension,
56+
) -> None:
57+
assert (
58+
namespace_package_extension.get_lib_name(quiet=True) == "namespace_package_rust"
59+
)

0 commit comments

Comments
 (0)