Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbuche committed Jul 3, 2024
1 parent e00783e commit f9b238d
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 26 deletions.
55 changes: 45 additions & 10 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,41 @@ on:
release:
types: published
jobs:
test:
if: github.event_name != 'release'
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
runs-on: ${{ matrix.os }}
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.79.0
default: true
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: maturin
run: |
pip install maturin
maturin build --features python --release --out .
pip install --find-links=. polymers
- name: pytest
run: |
pip install pytest
pytest --verbose .
- name: pycodestyle
run: |
pip install pycodestyle
pycodestyle --verbose .
- name: pylint
run: |
pip install pylint
pylint --verbose .
wheels:
strategy:
fail-fast: false
Expand Down Expand Up @@ -33,13 +68,13 @@ jobs:
needs: wheels
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
- name: check
run: |
mkdir -p wheelhouse/
mv ./*-wheel*/*.whl wheelhouse/
pip install twine
twine check wheelhouse/*.whl
- name: upload
if: github.event_name == 'release'
run: twine upload -u __token__ -p ${{ secrets.PYPI_TOKEN }} wheelhouse/*.whl
- uses: actions/download-artifact@v4
- name: check
run: |
mkdir -p wheelhouse/
mv ./*-wheel*/*.whl wheelhouse/
pip install twine
twine check wheelhouse/*.whl
- name: upload
if: github.event_name == 'release'
run: twine upload -u __token__ -p ${{ secrets.PYPI_TOKEN }} wheelhouse/*.whl
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ Cargo.lock

**.whl
*.vscode
**__pycache__
**.pytest_cache
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ version = "0.1.2"
crate-type = ["cdylib", "rlib"]

[dependencies]
pyo3 = {version = "=0.22", features = ["extension-module"], optional = true}
numpy = {version = "=0.21", optional = true}
pyo3 = {version = "=0.21", features = ["extension-module"], optional = true}

[features]
python = ["dep:pyo3"]
python = ["dep:numpy", "dep:pyo3"]

[profile.release]
codegen-units = 1
Expand Down
45 changes: 31 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
[build-system]
build-backend = 'maturin'
requires = [
"cffi==1.16.0",
"maturin==1.6.0"
'cffi==1.16.0',
'maturin==1.6.0'
]
build-backend = "maturin"

[project]
name = "automesh"
description = "automesh"
authors = [
{email = "[email protected]"},
{name = "Chad Brian Hovey"},
{email = "[email protected]"},
{name = "Michael R. Buche"},
{email = '[email protected]'},
{name = 'Chad Brian Hovey'},
{email = '[email protected]'},
{name = 'Michael R. Buche'},
]
requires-python = ">=3.8,<=3.12"
classifiers = [
'License :: OSI Approved :: BSD License',
'Development Status :: 5 - Production/Stable',
Expand All @@ -23,13 +20,33 @@ classifiers = [
'Programming Language :: Python',
'Programming Language :: Rust',
]
description = 'automesh'
dependencies = [
'numpy'
]
name = 'automesh'
requires-python = '>=3.8,<=3.12'

[project.optional-dependencies]
dev = [
"pre-commit"
'pre-commit',
'pycodestyle',
'pylint',
'pytest'
]

[project.urls]
Documentation = "https://github.com/autotwin/automesh"
Homepage = "https://github.com/autotwin/automesh"
Repository = "https://github.com/autotwin/automesh"
Documentation = 'https://github.com/autotwin/automesh'
Homepage = 'https://github.com/autotwin/automesh'
Repository = 'https://github.com/autotwin/automesh'

[tool.pytest.ini_options]
python_files = [
'*.py'
]
python_functions = [
'*'
]
testpaths = [
'tests'
]
4 changes: 4 additions & 0 deletions src/spn/py.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::super::py::Exodus;
use numpy::PyArray3;
use pyo3::prelude::*;

pub fn register_module(parent_module: &Bound<'_, PyModule>) -> PyResult<()> {
Expand All @@ -13,6 +14,9 @@ pub struct Spn {

#[pymethods]
impl Spn {
pub fn get_data<'py>(&self, python: Python<'py>) -> Bound<'py, PyArray3<u8>> {
PyArray3::from_vec3_bound(python, &self.data).unwrap()
}
pub fn exodus(&self) -> Exodus {
let _ = self.data;
Exodus {}
Expand Down
14 changes: 14 additions & 0 deletions tests/spn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import numpy as np
from automesh import Spn

gold = np.array([
[[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]],
[[1, 1, 1], [1, 0, 0], [1, 1, 0], [1, 0, 0], [1, 0, 0]],
[[1, 1, 1], [1, 0, 0], [1, 1, 0], [1, 0, 0], [1, 0, 0]],
[[1, 1, 1], [1, 0, 0], [1, 1, 0], [1, 0, 0], [1, 0, 0]],
])


def read():
spn = Spn('tests/spn/f.spn', 3, 5, 4)
assert (spn.get_data() == gold).all()

0 comments on commit f9b238d

Please sign in to comment.