Skip to content

Commit

Permalink
fix: Fix generation for maturin build-system (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab authored May 4, 2024
1 parent 2a1102c commit 9aecb55
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/scicookie/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def clean_up_build_system():
build_system_base_dir = PROJECT_DIRECTORY / "build-system"
build_system_dir = build_system_base_dir / BUILD_SYSTEM

os.makedirs(COMPILE_SOURCE_DIR, exist_ok=True)

if BUILD_SYSTEM == "flit":
shutil.move(
build_system_dir / "pyproject.toml",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "{{ cookiecutter.project_slug }}"
name = "{{ cookiecutter.package_slug }}"
version = "{{ cookiecutter.project_version }}"
authors = ["{{ cookiecutter.author_full_name }} <{{ cookiecutter.author_email }}>"]
edition = "2021"

[lib]
name = "_core"
name = "{{ cookiecutter.package_slug }}"
# "cdylib" is necessary to produce a shared library for Python to import from.
crate-type = ["cdylib"]

Expand All @@ -14,6 +14,8 @@ rand = "0.8.4"

[dependencies.pyo3]
version = "0.19.1"
# "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so)
# "abi3-py38" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.8
# "extension-module" tells pyo3 we want to build an extension module (skips
# linking against libpython.so)
# "abi3-py38" tells pyo3 (and maturin) to build using the stable ABI with
# minimum Python version 3.8
features = ["extension-module", "abi3-py38"]
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn subtract(x: i64, y: i64) -> i64 {
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
/// import the module.
#[pymodule]
fn _core(_py: Python, m: &PyModule) -> PyResult<()> {
fn {{ cookiecutter.package_slug }}(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(add, m)?)?;
m.add_function(wrap_pyfunction!(subtract, m)?)?;
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
Expand Down
8 changes: 5 additions & 3 deletions tests/smoke/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ else

fi

if [[ "$BUILD_SYSTEM" != "maturin" ]]; then
python -c "import osl_python_package as mypkg; assert mypkg.__version__ == '0.1.0'"
python -c "import osl_python_package as mypkg; assert mypkg.__version__ == '0.1.0'"

if [[ "$BUILD_SYSTEM" == "maturin" ]]; then
python -c "from osl_python_package import add; add(1, 1)"
fi

if [[ "$BUILD_SYSTEM" == "mesonpy" ]]; then
python -c "from osl_python_package import core; core.foo()"
python -c "from osl_python_package import core; core.foo()"
fi

export PATH=${PATH_ORI}
Expand Down

0 comments on commit 9aecb55

Please sign in to comment.