diff --git a/README_py.md b/README_py.md index a680b6d..2069165 100644 --- a/README_py.md +++ b/README_py.md @@ -1,16 +1,15 @@ # Porting an algorithm from C++ to Python ## Table of Contents -- [Why?](#why?) +- [Why?](#why) - [How it works](#how-it-works) -- [Requirements](#Requirements) - - [Creating python-env with pybind11](#Creating-python-env-with-pybind11) - - [Using venv (recommended)](#Using-venv) - - [Using anaconda](#Using-anaconda) -- [Examples](#Examples) - - [Rounder](#Rounder) - - [EmotiBitPacket](#EmotiBitPacket) -- [Adapting this to your C++ code](#Adapting-this-to-your-C++-code) +- [Requirements](#requirements) + - [Setting up Python virtual environment](#setting-up-python-virtual-environment) +- [Adapting this to your C++ code](#adapting-this-to-your-c-code) +- [Examples](#examples) + - [Rounder](#rounder) + - [EmotiBitPacket](#emotibitpacket) + - [Brainflow SpO2 Algorithm](#brainflow-spo2-algorithm) ## Why? The goal of this project is to allow users to take an algorithm written in C++ and translate it into runnable Python code. @@ -37,38 +36,33 @@ PYBIND11_MODULE(EmotiBitPacket, m) { - Build the files created in the previous step to create the `.pyd` file ## Requirements -### Creating python-env with pybind11 -#### Using venv +### Setting up Python Virtual Environment - Open a new command prompt window -- `cd` to the EmotiBit_Plugins repository -- Run the following command `python -m venv .\py_envs\` - - replace `` with the environment name -- Activate the new environment by running the command `.\py_envs\\Scripts\activate.bat` - - You will see the prompt in the terminal change. It now shows the python environment in parenthesis. -- Run the following command to install bypind11. `pip install pybind11==2.13.5` +- `cd` to `EmotiBit_Plugins/py_envs` +- Run the following command `python -m venv emotibit_plugins` + - This creates a new folder called `plugins` containing the virtual Python environment +- Activate the new environment: + - Windows (cmd): `.\emotibit_plugins\Scripts\activate.bat` + - Windows (PowerShell): `.\emotibit_plugins\Scripts\Activate.ps1` + - macOS/Linux (bash/zsh): `source emotibit_plugins/bin/activate` +- Run the following command to install pybind11. `pip install pybind11==2.13.5` -#### Using anaconda -- Download [Anaconda](https://www.anaconda.com/download/) as shown here. -- ***Do not close out of the Anaconda Powershell Prompt until completely done with an example*** -- Open an Anaconda Powershell Prompt through the search feature on your machine and run the command below -```bash -cd C:\path\to\your\EmotiBit_Plugins\pyExample_alg01 -conda config --set channel_priority flexible -conda env update --name EmotiBit-pyenv-modern --file .\EmotiBit-pyenv-modern.yml -conda activate EmotiBit-pyenv-modern -``` +## Adapting this to your C++ code +- Add pybind11 bindings to a file `bindings_.cpp`. Refer the [pybind11 documentation](https://pybind11.readthedocs.io/en/stable/basics.html) for more information. +- Create a new CMakeLists.txt file that + - Builds a library from your source files + - Builds the Python module (`.pyd` or `.so`) file from that library +- Run the `cmake` commands from the examples below to create a build the project. + +Refer to the examples below to see what `bindings.cpp` and `CMakeLists.txt` should look like. ## Examples ### Rounder -#### Steps to Run Example - - cd to `pyExample_alg01` - run the following commands ```bash -mkdir build -cd build -cmake .. -cmake --build . --config Release +cmake -B build +cmake --build build --config Release ``` - The following command runs the python example. The expected result is for the script to round the input. ```bash @@ -76,23 +70,17 @@ python example.py -i 3.4 ``` ### EmotiBitPacket -#### Building the example - To make this example work, you will need to copy/clone the `EmotiBit_XPlat_Utils` repository into the `src` folder. - cd to the `src` folder. - clone using `git clone https://github.com/EmotiBit/EmotiBit_XPlat_Utils`. Checkout the following commit `393b611ee0d0c1f1cec70e243fd5b643c2e25250` - cd to `pyExample_emotibitPacket` and run the following commands ```bash -mkdir build -cd build -cmake .. -cmake --build . --config Release +cmake -B build +cmake --build build --config Release ``` - Run the Python example script `pyExample_emotibitPacket\example.py` -## Adapting this to your C++ code -- Add pybind11 bindings to a file `bindings_.cpp`. Refer the [pybind11 documentation](https://pybind11.readthedocs.io/en/stable/basics.html) for more information. -- Create a new CMakeLists.txt file that - - creates a lib from your source files - - creates the pyd file from the src library -- Run the cmake commands above to create a build the project. - +### Brainflow SpO2 Algorithm +- Clone the EmotiBit Brainflow SpO2 Algorithm [repo](https://github.com/EmotiBit/EmotiBit_Brainflow_SpO2_Algorithm) into any directory +- `cd` into the `EmotiBit Brainflow SpO2 Algorithm` folder and checkout the following commit: `7bc9dc3b02f361c37e9e917477abefe9f5468a68` +- Follow the instructions under `pybind/README.md` to finish building the algorithm \ No newline at end of file