Skip to content

Commit 9833866

Browse files
authored
Merge pull request #15 from GeoStat-Framework/cythonize_laplace
Cythonize laplace
2 parents 563bc1d + 7a69a13 commit 9833866

File tree

6 files changed

+582
-221
lines changed

6 files changed

+582
-221
lines changed

.github/workflows/main.yml

Lines changed: 98 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919

2020
steps:
2121
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: "0"
2224

2325
- name: Set up Python 3.11
2426
uses: actions/setup-python@v5
@@ -28,8 +30,7 @@ jobs:
2830
- name: Install dependencies
2931
run: |
3032
python -m pip install --upgrade pip
31-
pip install --editable .[check,test]
32-
pip install "coveralls>=3.0.0"
33+
pip install -v --editable '.[check]'
3334
3435
- name: black check
3536
run: |
@@ -43,64 +44,137 @@ jobs:
4344
run: |
4445
python -m isort --check --diff --color .
4546
46-
- name: pylint check
47+
- name: ruff check
4748
run: |
48-
python -m pylint src/anaflow/
49+
python -m ruff check src/
4950
50-
- name: coveralls check
51+
- name: cython-lint check
5152
run: |
52-
python -m pytest --cov anaflow --cov-report term-missing -v tests/
53-
python -m coveralls --service=github
54-
env:
55-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
cython-lint src/anaflow/
5654
57-
build_sdist:
58-
name: sdist on ${{ matrix.os }} with py ${{ matrix.python-version }}
55+
build_wheels:
56+
name: wheels for ${{ matrix.os }}
5957
runs-on: ${{ matrix.os }}
6058
strategy:
6159
fail-fast: false
6260
matrix:
63-
os: [ubuntu-latest, windows-latest, macos-13]
64-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
61+
os: [ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-15-intel, macos-latest] # windows-11-arm (no scipy)
6562

6663
steps:
6764
- uses: actions/checkout@v4
6865
with:
69-
fetch-depth: '0'
66+
fetch-depth: "0"
67+
68+
- name: Build wheels
69+
uses: pypa/[email protected]
70+
with:
71+
output-dir: dist-wheel-${{ matrix.os }}
72+
73+
- uses: actions/upload-artifact@v4
74+
with:
75+
name: dist-wheel-${{ matrix.os }}
76+
path: ./dist-wheel-${{ matrix.os }}/*.whl
7077

71-
- name: Set up Python ${{ matrix.python-version }}
78+
build_sdist:
79+
name: sdist on ${{ matrix.os }} with py ${{ matrix.ver.py }} numpy${{ matrix.ver.np }}
80+
runs-on: ${{ matrix.os }}
81+
strategy:
82+
fail-fast: false
83+
matrix:
84+
os:
85+
[ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-14]
86+
ver:
87+
- { py: "3.9", np: "==1.20.0", sp: "==1.5.4" }
88+
- { py: "3.10", np: "==1.21.6", sp: "==1.7.2" }
89+
- { py: "3.11", np: "==1.23.2", sp: "==1.9.2" }
90+
- { py: "3.12", np: "==1.26.2", sp: "==1.11.2" }
91+
- { py: "3.13", np: "==2.1.0", sp: "==1.14.1" }
92+
- { py: "3.14", np: "==2.3.2", sp: "==1.16.1" }
93+
- { py: "3.14", np: ">=2.3.2", sp: ">=1.16.1" }
94+
exclude:
95+
- os: ubuntu-24.04-arm
96+
ver: { py: "3.8", np: "==1.20.0", sp: "==1.5.4" }
97+
- os: macos-14
98+
ver: { py: "3.8", np: "==1.20.0", sp: "==1.5.4" }
99+
- os: macos-14
100+
ver: { py: "3.9", np: "==1.20.0", sp: "==1.5.4" }
101+
- os: macos-14
102+
ver: { py: "3.10", np: "==1.21.6", sp: "==1.7.2" }
103+
steps:
104+
- uses: actions/checkout@v4
105+
with:
106+
fetch-depth: "0"
107+
108+
- name: Set up Python ${{ matrix.ver.py }}
72109
uses: actions/setup-python@v5
73110
with:
74-
python-version: ${{ matrix.python-version }}
111+
python-version: ${{ matrix.ver.py }}
75112

76113
- name: Install dependencies
77114
run: |
78115
python -m pip install --upgrade pip
79116
pip install build
80-
pip install --editable .[test]
117+
118+
- name: Install anaflow
119+
run: |
120+
pip install -v --editable .[test]
81121
82122
- name: Run tests
83123
run: |
84-
python -m pytest --cov anaflow --cov-report term-missing -v tests/
124+
pip install "numpy${{ matrix.ver.np }}" "scipy${{ matrix.ver.sp }}"
125+
python -m pytest -v tests/
85126
86127
- name: Build sdist
87128
run: |
88-
python -m build
129+
# PEP 517 package builder from pypa
130+
python -m build --sdist --outdir dist-sdist .
89131
90132
- uses: actions/upload-artifact@v4
91-
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
133+
if: matrix.os == 'ubuntu-latest' && matrix.ver.py == '3.11'
92134
with:
93-
name: dist
94-
path: dist/*
135+
name: dist-sdist
136+
path: dist-sdist/*.tar.gz
137+
138+
coverage:
139+
name: coverage
140+
runs-on: ubuntu-latest
141+
142+
steps:
143+
- uses: actions/checkout@v4
144+
with:
145+
fetch-depth: '0'
146+
147+
- name: Set up Python 3.11
148+
uses: actions/setup-python@v5
149+
with:
150+
python-version: 3.11
151+
152+
- name: Install dependencies
153+
run: |
154+
python -m pip install --upgrade pip
155+
pip install "coveralls>=3.0.0"
156+
157+
- name: Install anaflow
158+
run: |
159+
pip install -v --editable .[test]
160+
161+
- name: Run tests
162+
env:
163+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164+
run: |
165+
pip install "numpy${{ matrix.ver.np }}"
166+
python -m pytest --cov anaflow --cov-report term-missing -v tests/
167+
python -m coveralls --service=github
95168
96169
upload_to_pypi:
97-
needs: [build_sdist]
170+
needs: [build_wheels, build_sdist]
98171
runs-on: ubuntu-latest
99172

100173
steps:
101174
- uses: actions/download-artifact@v4
102175
with:
103-
name: dist
176+
pattern: dist-*
177+
merge-multiple: true
104178
path: dist
105179

106180
- name: Publish to Test PyPI

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
prune **
2+
recursive-include tests *.py
3+
recursive-include src/anaflow *.py *.pyx
4+
include LICENSE README.md pyproject.toml setup.py

pyproject.toml

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
[build-system]
22
requires = [
3-
"hatchling>=1.8.0",
4-
"hatch-vcs",
3+
"setuptools>=77",
4+
"wheel",
5+
"Cython>=3",
6+
"numpy>=2",
7+
"scipy>=1.5.4",
8+
"pentapy>=1.1.0,<2",
9+
"setuptools_scm[toml]>=7",
510
]
6-
build-backend = "hatchling.build"
11+
build-backend = "setuptools.build_meta"
712

813
[project]
9-
requires-python = ">=3.8"
14+
requires-python = ">=3.9"
1015
name = "anaflow"
1116
authors = [{name = "Sebastian Mueller", email = "[email protected]"}]
1217
readme = "README.md"
1318
license = "MIT"
19+
license-files = ["LICENSE"]
1420
dynamic = ["version"]
1521
description = "AnaFlow - analytical solutions for the groundwater-flow equation."
1622
classifiers = [
1723
"Development Status :: 5 - Production/Stable",
1824
"Intended Audience :: Developers",
1925
"Intended Audience :: End Users/Desktop",
2026
"Intended Audience :: Science/Research",
21-
"License :: OSI Approved :: MIT License",
2227
"Natural Language :: English",
2328
"Operating System :: MacOS",
2429
"Operating System :: MacOS :: MacOS X",
@@ -29,20 +34,20 @@ classifiers = [
2934
"Programming Language :: Python",
3035
"Programming Language :: Python :: 3",
3136
"Programming Language :: Python :: 3 :: Only",
32-
"Programming Language :: Python :: 3.8",
3337
"Programming Language :: Python :: 3.9",
3438
"Programming Language :: Python :: 3.10",
3539
"Programming Language :: Python :: 3.11",
3640
"Programming Language :: Python :: 3.12",
3741
"Programming Language :: Python :: 3.13",
42+
"Programming Language :: Python :: 3.14",
3843
"Topic :: Scientific/Engineering",
3944
"Topic :: Software Development",
4045
"Topic :: Utilities",
4146
]
4247
dependencies = [
43-
"numpy>=1.14.5",
48+
"numpy>=1.20.0",
4449
"pentapy>=1.1.0,<2",
45-
"scipy>=1.1.0",
50+
"scipy>=1.5.4",
4651
]
4752

4853
[project.optional-dependencies]
@@ -58,7 +63,8 @@ test = ["pytest-cov>=3"]
5863
check = [
5964
"black>=25",
6065
"isort[colors]",
61-
"pylint",
66+
"ruff>=0.5.0",
67+
"cython-lint",
6268
]
6369

6470
[project.urls]
@@ -69,33 +75,18 @@ Tracker = "https://github.com/GeoStat-Framework/anaflow/issues"
6975
Changelog = "https://github.com/GeoStat-Framework/anaflow/blob/main/CHANGELOG.md"
7076
Conda-Forge = "https://anaconda.org/conda-forge/anaflow"
7177

72-
[tool.hatch.version]
73-
source = "vcs"
74-
fallback_version = "0.0.0.dev0"
75-
76-
[tool.hatch.version.raw-options]
78+
[tool.setuptools_scm]
79+
write_to = "src/anaflow/_version.py"
80+
write_to_template = "__version__ = '{version}'"
7781
local_scheme = "no-local-version"
78-
79-
[tool.hatch.build.hooks.vcs]
80-
version-file = "src/anaflow/_version.py"
81-
template = "__version__ = '{version}'"
82-
83-
[tool.hatch.build.targets.sdist]
84-
include = [
85-
"/src",
86-
"/tests",
87-
]
88-
89-
[tool.hatch.build.targets.wheel]
90-
packages = ["src/anaflow"]
82+
fallback_version = "0.0.0.dev0"
9183

9284
[tool.isort]
9385
profile = "black"
9486
multi_line_output = 3
9587

9688
[tool.black]
9789
target-version = [
98-
"py38",
9990
"py39",
10091
"py310",
10192
"py311",
@@ -120,27 +111,27 @@ target-version = [
120111
"def __str__",
121112
]
122113

123-
[tool.pylint]
124-
[tool.pylint.master]
125-
extension-pkg-whitelist = [
126-
"numpy",
127-
"scipy",
128-
]
129-
ignore = "_version.py"
130-
131-
[tool.pylint.message_control]
132-
disable = [
133-
"R0801",
134-
]
135-
136-
[tool.pylint.reports]
137-
output-format = "colorized"
114+
[tool.ruff]
115+
line-length = 88
116+
target-version = "py39"
117+
exclude = ["_version.py"]
118+
119+
[tool.ruff.lint]
120+
select = [
121+
"E",
122+
"F",
123+
"W",
124+
"I",
125+
]
138126

139-
[tool.pylint.design]
140-
max-args = 25
141-
max-locals = 50
142-
max-branches = 30
143-
max-statements = 80
144-
max-attributes = 25
145-
max-public-methods = 75
146-
max-positional-arguments=25
127+
[tool.cibuildwheel]
128+
# Switch to using build
129+
build-frontend = "build"
130+
# Disable building py3.6/7/8, pp3.8, 32bit linux
131+
skip = ["*-win32", "*_i686", "*-musllinux_*", "cp31?t-*"]
132+
# Run the package tests using `pytest`
133+
test-extras = "test"
134+
test-command = "pytest -v {package}/tests"
135+
136+
environment.PIP_ONLY_BINARY = "numpy,scipy"
137+
environment.PIP_PREFER_BINARY = "1"

setup.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path
4+
5+
import numpy as np
6+
from Cython.Build import cythonize
7+
from setuptools import Extension, setup
8+
9+
SRC_DIR = Path("src")
10+
MODULE_PATH = SRC_DIR / "anaflow" / "flow"
11+
MODULE_NAME = "anaflow.flow._laplace_accel"
12+
13+
extensions = [
14+
Extension(
15+
MODULE_NAME,
16+
[str(MODULE_PATH / "_laplace_accel.pyx")],
17+
include_dirs=[np.get_include()],
18+
)
19+
]
20+
21+
extensions = cythonize(
22+
extensions,
23+
language_level=3,
24+
compiler_directives={
25+
"boundscheck": False,
26+
"wraparound": False,
27+
"initializedcheck": False,
28+
},
29+
)
30+
31+
setup(ext_modules=extensions, package_dir={"": "src"})

0 commit comments

Comments
 (0)