From f7ca47ccba67ed0827c295fcd775cfbd1b0e9b9e Mon Sep 17 00:00:00 2001 From: Tip ten Brink Date: Thu, 13 Jun 2024 18:16:01 +0200 Subject: [PATCH] some project structure cleanup --- Cargo.toml | 3 --- README.md | 23 ++++++++++++++++++++++- pyproject.toml | 3 +++ python/rustfrc/__init__.py | 2 ++ src/lib.rs | 3 --- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1a2be1a..fd2e941 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,3 @@ criterion = "0.3" [[bench]] name = "rustfrc_bench" harness = false - -[package.metadata.maturin] -python-source = "python" diff --git a/README.md b/README.md index d9c25c5..7046808 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 ` + +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` \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index b3f6f77..57906b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] +packages = [ + { include = "rustfrc", from = "python" }, +] [tool.poetry.dependencies] python = ">= 3.8, <3.13" diff --git a/python/rustfrc/__init__.py b/python/rustfrc/__init__.py index e6841c0..cee98bb 100644 --- a/python/rustfrc/__init__.py +++ b/python/rustfrc/__init__.py @@ -1 +1,3 @@ from .split import binom_split, pois_gen, sqr_abs + +__all__ = ["binom_split", "pois_gen", "sqr_abs"] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index d05d13d..b845183 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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> { let a = a.to_owned_array(); @@ -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> { let a = a.to_owned_array(); @@ -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>> { let shape_vec: Vec = shape.extract(py)?; let shape = shape_vec.as_slice();