From 1ff4c0c135fc22e0ad3fd17aeaccc69a30219484 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Tue, 3 Aug 2021 12:01:47 -0700 Subject: [PATCH 1/9] Made pyo3 optional. --- Cargo.toml | 4 +++- src/lib.rs | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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/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]> { From 8a4d96e767fe07c39dbee1b224afbc2ba9c83794 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Tue, 3 Aug 2021 12:15:14 -0700 Subject: [PATCH 2/9] Updated setup.py to ensure pyo3 is built. --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 6e08107..5d5fc7e 100644 --- a/setup.py +++ b/setup.py @@ -5,5 +5,6 @@ name="RustBCA", rust_extensions=[RustExtension("libRustBCA.pybca", binding=Binding.PyO3)], # rust extensions are not zip safe, just like C-extensions. + features=["python"] zip_safe=False, ) From 7848735d510fc92d039f990f48baf7f3edb7c635 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Tue, 3 Aug 2021 12:15:45 -0700 Subject: [PATCH 3/9] Fixed missing comma. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5d5fc7e..bd5ea1e 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,6 @@ name="RustBCA", rust_extensions=[RustExtension("libRustBCA.pybca", binding=Binding.PyO3)], # rust extensions are not zip safe, just like C-extensions. - features=["python"] + features=["python"], zip_safe=False, ) From 64bcac7ce81a6d058cbe4f201688d4648e7f64e9 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Tue, 3 Aug 2021 12:27:00 -0700 Subject: [PATCH 4/9] More fixes to setup.py - I was using the setuptools Rust API incorrectly, and it was silently failing. --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index bd5ea1e..e2ab17b 100644 --- a/setup.py +++ b/setup.py @@ -3,8 +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. - features=["python"], zip_safe=False, ) From 35e3ea14880d65f2d1e5309ff3a1a36fb3d56124 Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Tue, 3 Aug 2021 12:36:54 -0700 Subject: [PATCH 5/9] Add python binding installation to workflow I've added a simple check to make sure the python bindings install correctly from scratch. --- .github/workflows/rustbca_compile_check.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index 5cd3005..996794a 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -35,6 +35,11 @@ jobs: - name: Install HDF5 Libraries run: | sudo apt install libhdf5-dev + - name: test Python Bindings + run: | + suto 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 @@ -49,3 +54,4 @@ jobs: 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 + From 7cf1af54b175b5a4c28746a52c44295e862a2bf1 Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Tue, 3 Aug 2021 12:38:52 -0700 Subject: [PATCH 6/9] Fix to workflow; typo. --- .github/workflows/rustbca_compile_check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index 996794a..c5d77fa 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -37,7 +37,7 @@ jobs: sudo apt install libhdf5-dev - name: test Python Bindings run: | - suto python3 -m pip install setuptools_rust testresources + 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 From 0943871fc11397d9faceff50450196d5980f3c4a Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Tue, 3 Aug 2021 12:40:45 -0700 Subject: [PATCH 7/9] Ensure rust compiler is installed Python was having trouble finding the rust compiler, so I've added that to the workflow. --- .github/workflows/rustbca_compile_check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index c5d77fa..0033171 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 From 8dbc9c561c6106a46789674f4be2c33ad04e983c Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Tue, 3 Aug 2021 12:46:48 -0700 Subject: [PATCH 8/9] Add sudo For some reason, cargo test is now throwing a permission denied error in the workflow - sudo added to see if that fixes it. --- .github/workflows/rustbca_compile_check.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index 0033171..7f3cbe8 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -43,10 +43,10 @@ jobs: 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 + sudo 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 cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output @@ -54,5 +54,5 @@ jobs: ./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 cargo run --release --features parry3d TRIMESH examples/tungsten_twist_trimesh.toml From fbdc452280642dcce40fd53110e552aa8aa0a460 Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Tue, 3 Aug 2021 12:59:18 -0700 Subject: [PATCH 9/9] More permissions issues --- .github/workflows/rustbca_compile_check.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index 7f3cbe8..3aff6a6 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -47,12 +47,12 @@ jobs: - name: Run Examples run: | sudo 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 ./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 + sudo ./target/release/RustBCA SPHERE examples/boron_nitride_sphere.toml sudo cargo run --release --features parry3d TRIMESH examples/tungsten_twist_trimesh.toml