Skip to content

Commit

Permalink
some project structure cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tmtenbrink committed Jun 13, 2024
1 parent b65f477 commit f7ca47c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ criterion = "0.3"
[[bench]]
name = "rustfrc_bench"
harness = false

[package.metadata.maturin]
python-source = "python"
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ However, for an optimal Python experience, use [poetry](https://github.com/pytho

### From source (using maturin)

rustfrc uses [poetry](https://github.com/python-poetry/poetry) as its Python dependency manager. For best results, create a `poetry` virtualenv (be sure to install virtualenv as a systems package) with the `pyproject.toml` and run `poetry update` to install the required packages. I recommend installing [maturin](https://pypi.org/project/maturin/) as a global tool (e.g. with `cargo binstall`).
rustfrc uses [poetry](https://github.com/python-poetry/poetry) as its Python dependency manager. For best results, create a `poetry` virtualenv (be sure to install virtualenv as a systems package) with the `pyproject.toml` and run `poetry install` to install the required packages. I recommend installing [maturin](https://pypi.org/project/maturin/) as a global tool (e.g. with `cargo binstall`).

Build a wheel file like this (if using poetry, append `poetry run` before the command) from the project directory:

Expand All @@ -59,3 +59,24 @@ Take a look at [PyO3](https://github.com/PyO3/pyo3) for other installation optio
#### Manylinux

If you want to build .whl files that are compatible with a wide range of Linux distributions and can be uploaded to PyPI, take a look at the GitHub Actions files and [pyo3/maturin-action](https://github.com/PyO3/maturin-action).

## Development

### Poetry

First, install Poetry. Since we aim for compatibility with Python 3.8+, it's recommended to install Python 3.8 and create a virtual environment with:

`poetry env use <path to Python 3.8 executable>`

Then, do `poetry shell` to activate the virtual environment.

Next, run `poetry install` to install the (development) dependencies.

Finally, build the Rust project using `maturin develop` (it's recommended to install `maturin` globally using `cargo binstall maturin` or `pipx install maturin`).

Run the tests using `pytest`.

Note that type information is not available for the Rust functions, you will have to look at the Rust source code. Maturin builds a package structures as follows:
- root `rustfrc` package
- `_internal`: this includes `binom_split_py`, etc.
- `split`: this is the Python source code in `python/rustfrc/split.py`
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ name = "rustfrc"
version = "1.1.5"
description = "Fast utility functions useful for Fourier Ring/Shell Correlation: binomial splitting of arrays."
authors = ["Tip ten Brink <[email protected]>"]
packages = [
{ include = "rustfrc", from = "python" },
]

[tool.poetry.dependencies]
python = ">= 3.8, <3.13"
Expand Down
2 changes: 2 additions & 0 deletions python/rustfrc/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .split import binom_split, pois_gen, sqr_abs

__all__ = ["binom_split", "pois_gen", "sqr_abs"]
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fn binom_split_py<'py>(py: Python<'py>, a: PyReadonlyArrayDyn<'py, i32>) -> PyRe
/// Takes an array (np.ndarray with dtype complex64) and takes the absolute value and then squares
/// it, element-wise.
#[pyfunction]
#[pyo3(text_signature = "a, /")]
fn sqr_abs32_py<'py>(py: Python<'py>, a: PyReadonlyArrayDyn<'py, Complex32>) -> Bound<'py, PyArrayDyn<f32>> {
let a = a.to_owned_array();

Expand All @@ -54,7 +53,6 @@ fn sqr_abs32_py<'py>(py: Python<'py>, a: PyReadonlyArrayDyn<'py, Complex32>) ->
/// Takes an array (np.ndarray with dtype complex128) and takes the absolute value and then squares
/// it, element-wise.
#[pyfunction]
#[pyo3(text_signature = "a, /")]
fn sqr_abs64_py<'py>(py: Python<'py>, a: PyReadonlyArrayDyn<'py, Complex64>) -> Bound<'py, PyArrayDyn<f64>> {
let a = a.to_owned_array();

Expand All @@ -65,7 +63,6 @@ fn sqr_abs64_py<'py>(py: Python<'py>, a: PyReadonlyArrayDyn<'py, Complex64>) ->
/// parameter lambda for each element. Takes a lambda parameter (positive) and a shape tuple of
/// non-negative ints.
#[pyfunction]
#[pyo3(text_signature = "a, /")]
fn pois_gen_py(py: Python<'_>, shape: PyObject, lambda: f64 ) -> PyResult<Bound<'_, PyArrayDyn<f64>>> {
let shape_vec: Vec<usize> = shape.extract(py)?;
let shape = shape_vec.as_slice();
Expand Down

0 comments on commit f7ca47c

Please sign in to comment.