Skip to content

Commit b56d126

Browse files
authored
Fix RustExtension.install_script (#154)
* Fix `RustExtension.install_script` * Add exec binding example * Make directories for exec binding extension * Update changelog for #154
1 parent 255e073 commit b56d126

File tree

10 files changed

+46
-2
lines changed

10 files changed

+46
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
### Fixed
1414
- Use info from sysconfig when cross-compiling. [#139](https://github.com/PyO3/setuptools-rust/pull/139)
1515
- Put Rust extension module binary under `build/lib.*` directory. [#150](https://github.com/PyO3/setuptools-rust/pull/150)
16+
- Fix `Exec` binding with console scripts. [#154](https://github.com/PyO3/setuptools-rust/pull/154)
1617

1718
## 0.12.1 (2021-03-11)
1819
### Fixed

examples/hello-world/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/hello-world/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "hello-world"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

examples/hello-world/MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include Cargo.toml
2+
recursive-include src *

examples/hello-world/hello_world/__init__.py

Whitespace-only changes.

examples/hello-world/setup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from setuptools import setup
2+
from setuptools_rust import Binding, RustExtension
3+
4+
setup(
5+
name="hello-world",
6+
version="1.0",
7+
rust_extensions=[
8+
RustExtension("hello_world.hello_world", binding=Binding.Exec, script=True)
9+
],
10+
# rust extensions are not zip safe, just like C-extensions.
11+
zip_safe=False,
12+
)

examples/hello-world/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

examples/hello-world/tox.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[tox]
2+
requires =
3+
setuptools-rust @ file://{toxinidir}/../../
4+
5+
[testenv]
6+
description = Run the unit tests under {basepython}
7+
deps =
8+
setuptools-rust @ file://{toxinidir}/../../
9+
commands = hello_world {posargs}
10+
passenv = *

setuptools_rust/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,12 @@ def install_extension(self, ext: RustExtension, dylib_paths):
386386
# remove python3 extension (i.e. cpython-36m)
387387
ext_path, _ = os.path.splitext(ext_path)
388388

389+
os.makedirs(os.path.dirname(ext_path), exist_ok=True)
389390
ext.install_script(ext_path)
390391
else:
391392
ext_path = self.get_dylib_ext_path(ext, target_fname)
393+
os.makedirs(os.path.dirname(ext_path), exist_ok=True)
392394

393-
os.makedirs(os.path.dirname(ext_path), exist_ok=True)
394395
shutil.copyfile(dylib_path, ext_path)
395396

396397
if sys.platform != "win32" and not debug_build:

setuptools_rust/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def install_script(self, ext_path):
184184
dirname, name = os.path.split(ext_path)
185185
file = os.path.join(dirname, "_gen_%s.py" % name)
186186
with open(file, "w") as f:
187-
f.write(TMPL.format({"name": name}))
187+
f.write(TMPL.format(name=name))
188188

189189

190190
TMPL = """

0 commit comments

Comments
 (0)