diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index 5cd3005..3aff6a6 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -21,6 +21,7 @@ jobs: - name: Install rust run: | curl --proto '=https' --tlsv1.2 -sSf -y https://sh.rustup.rs | sh + sudo apt-get install rustc - name: Install pip for Python-3 run: | sudo apt-get install python3-pip @@ -35,17 +36,23 @@ jobs: - name: Install HDF5 Libraries run: | sudo apt install libhdf5-dev + - name: test Python Bindings + run: | + sudo python3 -m pip install setuptools_rust testresources + sudo python3 setup.py install + python3 -c "from libRustBCA.pybca import *; print(simple_bca_py)" - name: Test RustBCA run: | - cargo test --features cpr_rootfinder_netlib,hdf5_input,distributions,parry3d + sudo cargo test --features cpr_rootfinder_netlib,hdf5_input,distributions,parry3d - name: Run Examples run: | - cargo run --release 0D examples/boron_nitride_0D.toml - ./target/release/RustBCA 0D examples/titanium_dioxide_0D.toml - ./target/release/RustBCA 1D examples/layered_geometry_1D.toml + sudo cargo run --release 0D examples/boron_nitride_0D.toml + sudo ./target/release/RustBCA 0D examples/titanium_dioxide_0D.toml + sudo ./target/release/RustBCA 1D examples/layered_geometry_1D.toml cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output - ./target/release/RustBCA examples/boron_nitride.toml - ./target/release/RustBCA examples/layered_geometry.toml + sudo ./target/release/RustBCA examples/boron_nitride.toml + sudo ./target/release/RustBCA examples/layered_geometry.toml cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output - ./target/release/RustBCA SPHERE examples/boron_nitride_sphere.toml - cargo run --release --features parry3d TRIMESH examples/tungsten_twist_trimesh.toml + sudo ./target/release/RustBCA SPHERE examples/boron_nitride_sphere.toml + sudo cargo run --release --features parry3d TRIMESH examples/tungsten_twist_trimesh.toml + diff --git a/Cargo.toml b/Cargo.toml index 2d8bc21..fa02929 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ parry3d-f64 = {version = "0.2.0", optional = true} [dependencies.pyo3] version = "0.13.2" features = ["extension-module"] +optional = true [dev-dependencies] float-cmp = "0.8.0" @@ -50,4 +51,5 @@ cpr_rootfinder_intel_mkl = ["rcpr", "intel-mkl-src"] distributions = ["ndarray"] no_list_output = [] parry3d = ["parry3d-f64"] -accelerated_ions = [] \ No newline at end of file +accelerated_ions = [] +python = ["pyo3"] diff --git a/setup.py b/setup.py index 6e08107..e2ab17b 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="RustBCA", - rust_extensions=[RustExtension("libRustBCA.pybca", binding=Binding.PyO3)], + rust_extensions=[RustExtension("libRustBCA.pybca", binding=Binding.PyO3, features=["python"])], # rust extensions are not zip safe, just like C-extensions. zip_safe=False, ) diff --git a/src/lib.rs b/src/lib.rs index 6862ae4..bb3ba11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,9 @@ use std::f64::consts::FRAC_2_SQRT_PI; use std::f64::consts::PI; use std::f64::consts::SQRT_2; +#[cfg(feature = "python")] use pyo3::prelude::*; +#[cfg(feature = "python")] use pyo3::wrap_pyfunction; //Load internal modules @@ -70,6 +72,7 @@ pub use crate::sphere::{Sphere, SphereInput, InputSphere}; #[cfg(feature = "parry3d")] pub use crate::parry::{ParryBall, ParryBallInput, InputParryBall, ParryTriMesh, ParryTriMeshInput, InputParryTriMesh}; +#[cfg(feature = "python")] #[pymodule] pub fn pybca(py: Python, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(simple_bca_py, m)?)?; @@ -467,11 +470,13 @@ pub extern "C" fn simple_bca_c(x: f64, y: f64, z: f64, ux: f64, uy: f64, uz: f64 } } +#[cfg(feature = "python")] #[pyfunction] pub fn simple_bca_py(x: f64, y: f64, z: f64, ux: f64, uy: f64, uz: f64, E1: f64, Z1: f64, m1: f64, Ec1: f64, Es1: f64, Z2: f64, m2: f64, Ec2: f64, Es2: f64, n2: f64, Eb2: f64) -> Vec<[f64; 9]> { simple_bca(x, y, z, ux, uy, uz, E1, Z1, m1, Ec1, Es1, Z2, m2, Ec2, Es2, n2, Eb2) } +#[cfg(feature = "python")] #[pyfunction] pub fn simple_bca_list_py(energies: Vec, usx: Vec, usy: Vec, usz: Vec, Z1: f64, m1: f64, Ec1: f64, Es1: f64, Z2: f64, m2: f64, Ec2: f64, Es2: f64, n2: f64, Eb2: f64) -> Vec<[f64; 9]> {