Skip to content

Commit

Permalink
Sketch out rust extension layout using maturin/PyO3
Browse files Browse the repository at this point in the history
  • Loading branch information
tomalrussell committed Sep 26, 2023
1 parent 19f84f5 commit 96ebdf5
Show file tree
Hide file tree
Showing 9 changed files with 489 additions and 113 deletions.
120 changes: 120 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# This file is autogenerated by maturin v1.2.3
# To update, run
#
# maturin generate-ci github
#
name: build

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
linux:
runs-on: ubuntu-latest
strategy:
matrix:
target: [x86_64, x86, aarch64, armv7, s390x, ppc64le]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

windows:
runs-on: windows-latest
strategy:
matrix:
target: [x64, x86]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: ${{ matrix.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

macos:
runs-on: macos-latest
strategy:
matrix:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v3
with:
name: wheels
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing *
42 changes: 0 additions & 42 deletions .github/workflows/package.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
build
dist

# rust
target
*.so

docs/source/api/*

# data
Expand Down
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,37 @@ Clone this repository:

git clone [email protected]:tomalrussell/snkit.git

Maybe set up a virtualenv or conda environment, as you wish. Then install `snkit` in editable
mode, with development packages:
Maybe set up a virtualenv or conda environment, as you wish.

For example, using
[`micromamba`](https://mamba.readthedocs.io/en/latest/user_guide/micromamba.html)
to create an environment with all dependencies:

```bash
micromamba create -n snkit python=3.11 \
"geopandas>=0.13" \
"shapely>=2.0" \
"networkx>=3.0" \
"maturin>=1.2,<2.0" \
pytest \
pytest-cov \
black \
nbstripout
micromamba activate snkit
```

For reference, [`maturin`](https://www.maturin.rs) is used to build the rust
extension module `snkit.core`. The rust-Python bindings are created using
[`PyO3`](https://pyo3.rs/). The project is currently laid out with the rust
source code in `rust/src` and Python in `src/snkit`.

Install `snkit` in editable mode, with development packages:

pip install -e .[dev]
maturin develop --extras=dev,networkx

Run the tests:

python -m pytest tests/
python -m pytest

## Testimonials 💯 👍 😊

Expand Down
42 changes: 39 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
[tool.pytest.ini_options]
pythonpath = [
"src",
[project]
name = "snkit"
description = "a spatial networks toolkit"
dynamic = ["version"]
readme = "README.md"
authors = [{ name = "Tom Russell", email = "[email protected]" }]
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python",
"Programming Language :: Rust",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Topic :: Scientific/Engineering :: GIS",
"Topic :: Utilities",
]
dependencies = ["geopandas>=0.13", "shapely>=2.0"]

[project.optional-dependencies]
"dev" = ["black", "nbstripout", "pytest", "pytest-cov"]
"networkx" = ["networkx>=3.0"]

[project.urls]
Homepage = "https://github.com/tomalrussell/snkit"
Documentation = "https://snkit.readthedocs.io/en/latest/"

[build-system]
requires = ["maturin>=1.2,<2.0"]
build-backend = "maturin"

[tool.maturin]
features = ["pyo3/extension-module"]
python-source = "src"
module-name = "snkit.core"

[tool.pytest.ini_options]
pythonpath = ["src"]
Loading

0 comments on commit 96ebdf5

Please sign in to comment.