Skip to content

Commit 445d65c

Browse files
authored
Merge pull request #144 from lcpp-org/143-python-bindings-optional
Made pyo3 optional.
2 parents a61666f + fbdc452 commit 445d65c

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

.github/workflows/rustbca_compile_check.yml

+15-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- name: Install rust
2222
run: |
2323
curl --proto '=https' --tlsv1.2 -sSf -y https://sh.rustup.rs | sh
24+
sudo apt-get install rustc
2425
- name: Install pip for Python-3
2526
run: |
2627
sudo apt-get install python3-pip
@@ -35,17 +36,23 @@ jobs:
3536
- name: Install HDF5 Libraries
3637
run: |
3738
sudo apt install libhdf5-dev
39+
- name: test Python Bindings
40+
run: |
41+
sudo python3 -m pip install setuptools_rust testresources
42+
sudo python3 setup.py install
43+
python3 -c "from libRustBCA.pybca import *; print(simple_bca_py)"
3844
- name: Test RustBCA
3945
run: |
40-
cargo test --features cpr_rootfinder_netlib,hdf5_input,distributions,parry3d
46+
sudo cargo test --features cpr_rootfinder_netlib,hdf5_input,distributions,parry3d
4147
- name: Run Examples
4248
run: |
43-
cargo run --release 0D examples/boron_nitride_0D.toml
44-
./target/release/RustBCA 0D examples/titanium_dioxide_0D.toml
45-
./target/release/RustBCA 1D examples/layered_geometry_1D.toml
49+
sudo cargo run --release 0D examples/boron_nitride_0D.toml
50+
sudo ./target/release/RustBCA 0D examples/titanium_dioxide_0D.toml
51+
sudo ./target/release/RustBCA 1D examples/layered_geometry_1D.toml
4652
cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output
47-
./target/release/RustBCA examples/boron_nitride.toml
48-
./target/release/RustBCA examples/layered_geometry.toml
53+
sudo ./target/release/RustBCA examples/boron_nitride.toml
54+
sudo ./target/release/RustBCA examples/layered_geometry.toml
4955
cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output
50-
./target/release/RustBCA SPHERE examples/boron_nitride_sphere.toml
51-
cargo run --release --features parry3d TRIMESH examples/tungsten_twist_trimesh.toml
56+
sudo ./target/release/RustBCA SPHERE examples/boron_nitride_sphere.toml
57+
sudo cargo run --release --features parry3d TRIMESH examples/tungsten_twist_trimesh.toml
58+

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ parry3d-f64 = {version = "0.2.0", optional = true}
3232
[dependencies.pyo3]
3333
version = "0.13.2"
3434
features = ["extension-module"]
35+
optional = true
3536

3637
[dev-dependencies]
3738
float-cmp = "0.8.0"
@@ -50,4 +51,5 @@ cpr_rootfinder_intel_mkl = ["rcpr", "intel-mkl-src"]
5051
distributions = ["ndarray"]
5152
no_list_output = []
5253
parry3d = ["parry3d-f64"]
53-
accelerated_ions = []
54+
accelerated_ions = []
55+
python = ["pyo3"]

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="RustBCA",
6-
rust_extensions=[RustExtension("libRustBCA.pybca", binding=Binding.PyO3)],
6+
rust_extensions=[RustExtension("libRustBCA.pybca", binding=Binding.PyO3, features=["python"])],
77
# rust extensions are not zip safe, just like C-extensions.
88
zip_safe=False,
99
)

src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ use std::f64::consts::FRAC_2_SQRT_PI;
3939
use std::f64::consts::PI;
4040
use std::f64::consts::SQRT_2;
4141

42+
#[cfg(feature = "python")]
4243
use pyo3::prelude::*;
44+
#[cfg(feature = "python")]
4345
use pyo3::wrap_pyfunction;
4446

4547
//Load internal modules
@@ -70,6 +72,7 @@ pub use crate::sphere::{Sphere, SphereInput, InputSphere};
7072
#[cfg(feature = "parry3d")]
7173
pub use crate::parry::{ParryBall, ParryBallInput, InputParryBall, ParryTriMesh, ParryTriMeshInput, InputParryTriMesh};
7274

75+
#[cfg(feature = "python")]
7376
#[pymodule]
7477
pub fn pybca(py: Python, m: &PyModule) -> PyResult<()> {
7578
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
467470
}
468471
}
469472

473+
#[cfg(feature = "python")]
470474
#[pyfunction]
471475
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]> {
472476
simple_bca(x, y, z, ux, uy, uz, E1, Z1, m1, Ec1, Es1, Z2, m2, Ec2, Es2, n2, Eb2)
473477
}
474478

479+
#[cfg(feature = "python")]
475480
#[pyfunction]
476481
pub fn simple_bca_list_py(energies: Vec<f64>, usx: Vec<f64>, usy: Vec<f64>, usz: Vec<f64>, Z1: f64, m1: f64, Ec1: f64, Es1: f64, Z2: f64, m2: f64, Ec2: f64, Es2: f64, n2: f64, Eb2: f64) -> Vec<[f64; 9]> {
477482

0 commit comments

Comments
 (0)