This project uses maturin
to create a Python library from Rust code. Follow the steps below to install and build the library.
-
(Optional) Install build tools (for Linux users)
Install the
build-essential
package or its equivalent packages using your distribution's package manager.Ubuntu/Debian:
sudo apt install build-essential
Arch Linux:
sudo pacman -S base-devel
RHEL/CentOS/Fedora:
sudo yum install gcc gcc-c++ make openssl-dev
-
Ensure Rust is installed: Verify Rust installation by running:
cargo --version
If Rust is not installed, you can install it from here.
-
Set up a virtual environment:
-
Install
venv
for your platform by following the instructions here. -
Create a virtual environment:
python3 -m venv venv
-
-
Activate the virtual environment: Follow the instructions here to activate the virtual environment.
Example for Linux/macOS:
source venv/bin/activate
Example for Windows:
.\venv\Scripts\activate
-
Install
maturin
pip install maturin
For Linux, install patchelf dependency:
pip install maturin[patchelf]
-
Clone the repository:
git clone https://github.com/JanssenProject/jans.git
-
Navigate to the
cedarling_python
folder:cd jans/jans-cedarling/bindings/cedarling_python
-
Build and install the package: Build the Rust crate and install it into the virtual environment:
maturin develop --release
-
Verify installation: Check that the library is installed by listing the installed Python packages:
pip list
You should see
cedarling_python
listed among the available packages. -
Read documentation After installing the package you can read the documentation from python using the following command:
python -m pydoc cedarling_python
To verify that the library works correctly, you can run the provided example.py
script. Make sure the virtual environment is activated before running the script:
CEDARLING_POLICY_STORE_LOCAL=example_files/policy-store.json python example.py
If you only want to build the library without installing it in the Python environment, follow these steps:
-
Complete the prerequisites
-
Navigate to the
cedarling_python
folder:cd jans/jans-cedarling/bindings/cedarling_python
-
Build the crate: To build the library:
maturin build --release
The python types definitions are available in the PYTHON_TYPES.md
file. Or by clicking here.
Also after installing the library you can get same information using:
python -m pydoc cedarling_python
We use pytest
and tox
to create reproduceable environments for testing.
To run the tests, with pytest
:
-
Make sure that you have installed the
cedarling_python
package in your virtual environment or system. -
Install
pytest
:pip install pytest
-
Make sure that you are in the
jans/jans-cedarling/bindings/cedarling_python/
folder. -
Run the following command:
pytest
Or run
pytest
without capturing the output:pytest -s
-
See the results in the terminal.
-
Ensure that you installed rust compiler and toolchain. You can install it by following the official rust installation guide.
-
Ensure tox is installed: You can install tox in your environment using pip:
pip install tox
-
Make sure that you are in the
jans/jans-cedarling/bindings/cedarling_python/
folder. -
Run the following command:
tox
-
See the results in the terminal.