Skip to content

Commit 116c8a5

Browse files
authored
PDM + Meson Build System (#36)
1 parent 2ed19a5 commit 116c8a5

File tree

18 files changed

+1966
-50361
lines changed

18 files changed

+1966
-50361
lines changed

.gitattributes

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
poetry.lock linguist-generated=true
2-
src/cynetdiff/models.cpp linguist-generated=true
1+
pdm.lock linguist-generated=true

.github/workflows/benchmark.yml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,19 @@ on:
88
branches: ["*"]
99

1010
jobs:
11-
build:
11+
benchmark:
1212
runs-on: ubuntu-latest
13-
strategy:
14-
fail-fast: false
15-
matrix:
16-
python-version: ["3.12"]
17-
poetry-version: ["1.8.5"]
18-
1913
steps:
2014
- uses: actions/checkout@v4
2115

22-
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v5
24-
with:
25-
python-version: ${{ matrix.python-version }}
26-
27-
- uses: abatilo/actions-poetry@v2
16+
- name: Setup PDM
17+
uses: pdm-project/setup-pdm@v4
2818
with:
29-
poetry-version: ${{ matrix.poetry-version }}
19+
python-version: "3.12"
20+
cache: true
3021

3122
- name: Install dependencies
32-
run: poetry install --with dev,benchmark
23+
run: pdm install -G test,build
3324

34-
- name: Benchmark with pytest-benchmark
35-
run: poetry run pytest --benchmark-only --benchmark-warmup-iterations=0 benchmarks/test_benchmark.py
25+
- name: Run benchmarks
26+
run: pdm run pytest benchmarks

.github/workflows/docs.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
name: docs
22
# Based on https://squidfunk.github.io/mkdocs-material/publishing-your-site/
33
on:
4-
push:
5-
tags:
6-
- "v*.*.*"
4+
workflow_dispatch:
5+
release:
6+
types:
7+
- published
78
permissions:
89
contents: write
910
jobs:
@@ -16,17 +17,14 @@ jobs:
1617
git config user.name github-actions[bot]
1718
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
1819
- uses: actions/setup-python@v5
19-
with:
20-
python-version: 3.12
21-
- uses: abatilo/actions-poetry@v2
22-
with:
23-
poetry-version: 1.8.2
20+
- name: Setup PDM
21+
uses: pdm-project/setup-pdm@v4
2422
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
2523
- uses: actions/cache@v3
2624
with:
2725
key: mkdocs-material-${{ env.cache_id }}
2826
path: .cache
2927
restore-keys: |
3028
mkdocs-material-
31-
- run: poetry install --with docs
32-
- run: poetry run mkdocs gh-deploy --force
29+
- run: pdm install -G docs --no-self
30+
- run: pdm run mkdocs gh-deploy --force

.github/workflows/lint.yml

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,28 @@ on:
1010
branches: ["*"]
1111

1212
jobs:
13-
ci:
14-
strategy:
15-
matrix:
16-
python-version: ["3.12"]
17-
poetry-version: ["1.8.1"]
18-
os: [ubuntu-latest]
19-
runs-on: ${{ matrix.os }}
13+
lint:
14+
runs-on: ubuntu-latest
2015
steps:
2116
- uses: actions/checkout@v4
22-
with:
23-
submodules: recursive
24-
- uses: actions/setup-python@v5
25-
with:
26-
python-version: ${{ matrix.python-version }}
2717

28-
- uses: abatilo/actions-poetry@v2
18+
- name: Setup PDM
19+
uses: pdm-project/setup-pdm@v4
2920
with:
30-
poetry-version: ${{ matrix.poetry-version }}
21+
python-version: "3.10"
22+
cache: true
23+
3124
- name: Install dependencies
32-
run: poetry install --with dev,benchmark
25+
run: pdm install -G lint --no-self
3326

3427
- name: Run ruff lint check
35-
run: poetry run ruff check .
28+
run: pdm run ruff check .
3629

3730
- name: Run ruff format check
38-
run: poetry run ruff format --check .
31+
run: pdm run ruff format --check .
3932

4033
- name: Run Cython lint
41-
run: poetry run cython-lint .
34+
run: pdm run cython-lint .
4235

4336
- name: Run mypy
44-
run: poetry run mypy .
37+
run: pdm run mypy .

.github/workflows/publish.yml

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,63 @@
11
# Automatically publishes version of the package on tagged release
2+
# Largely copied from https://learn.scientific-python.org/development/guides/gha-wheels/
23
name: publish
34
on:
4-
push:
5-
tags:
6-
- "v*.*.*"
5+
workflow_dispatch:
6+
release:
7+
types:
8+
- published
9+
pull_request:
10+
paths:
11+
- .github/workflows/publish.yml
12+
713
jobs:
8-
build:
14+
make_sdist:
15+
name: Make SDist
916
runs-on: ubuntu-latest
1017
steps:
1118
- uses: actions/checkout@v4
12-
- name: Build and publish to pypi
13-
uses: JRubics/[email protected]
19+
20+
- name: Build SDist
21+
run: pipx run build --sdist
22+
23+
- uses: actions/upload-artifact@v4
1424
with:
15-
pypi_token: ${{ secrets.PYPI_TOKEN }}
25+
name: cibw-sdist
26+
path: dist/*.tar.gz
27+
28+
build_wheels:
29+
name: Wheel on ${{ matrix.os }}
30+
runs-on: ${{ matrix.os }}
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
# TODO add back windows-latest, when I can fix it
35+
os: [ubuntu-latest, macos-13, macos-14]
36+
37+
steps:
38+
- uses: actions/checkout@v4
39+
40+
- uses: astral-sh/setup-uv@v6
41+
42+
- uses: pypa/[email protected]
43+
44+
- name: Upload wheels
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: cibw-wheels-${{ matrix.os }}
48+
path: wheelhouse/*.whl
49+
50+
upload_all:
51+
needs: [build_wheels, make_sdist]
52+
runs-on: ubuntu-latest
53+
if: github.event_name == 'release' && github.event.action == 'published'
54+
steps:
55+
- uses: actions/download-artifact@v4
56+
with:
57+
pattern: cibw-*
58+
path: dist
59+
merge-multiple: true
60+
61+
- uses: pypa/gh-action-pypi-publish@release/v1
62+
with:
63+
password: ${{ secrets.PYPI_TOKEN }}

.github/workflows/tests.yml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3-
41
name: tests
52

63
on:
@@ -10,28 +7,19 @@ on:
107
branches: ["*"]
118

129
jobs:
13-
build:
10+
test:
1411
runs-on: ubuntu-latest
15-
strategy:
16-
fail-fast: false
17-
matrix:
18-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
19-
poetry-version: ["1.8.1"]
20-
2112
steps:
2213
- uses: actions/checkout@v4
2314

24-
- name: Set up Python ${{ matrix.python-version }}
25-
uses: actions/setup-python@v5
26-
with:
27-
python-version: ${{ matrix.python-version }}
28-
29-
- uses: abatilo/actions-poetry@v2
15+
- name: Setup PDM
16+
uses: pdm-project/setup-pdm@v4
3017
with:
31-
poetry-version: ${{ matrix.poetry-version }}
18+
python-version: "3.10"
19+
cache: true
3220

3321
- name: Install dependencies
34-
run: poetry install --with dev
22+
run: pdm install -G test,build
3523

36-
- name: Test with pytest
37-
run: poetry run pytest
24+
- name: Run tests
25+
run: pdm run pytest

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ venv
112112

113113
# Cython
114114
*.html
115+
*.cpp
116+
*.c
115117

116118
speed/
117119

118120
get_graph_hashes.py
121+
122+
.pdm-python

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"editor.defaultFormatter": "tamasfe.even-better-toml",
1313
"editor.formatOnSave": true
1414
},
15+
"[json][yaml]": {
16+
"editor.formatOnSave": true
17+
},
1518
"files.trimTrailingWhitespace": true,
1619
"files.insertFinalNewline": true,
1720
"files.trimFinalNewlines": true,

build_package.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

demo/demo_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def plot_num_nodes_activated(
300300
)
301301
for i in range(max_length)
302302
]
303-
lower_quartile, upper_quartile = zip(*iqr_values)
303+
lower_quartile, upper_quartile = zip(*iqr_values, strict=True)
304304

305305
for y in mean_infected:
306306
plt.axhline(y=y, color=colors[idx], linestyle="--", alpha=0.2)

meson.build

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
project('cynetdiff', 'cython', 'c',
2+
meson_version : '>= 1.1',
3+
default_options : ['warning_level=3']
4+
)
5+
6+
python = import('python').find_installation('python3', pure: false)
7+
8+
if python.language_version().version_compare('< 3.10')
9+
error('Requires Python >= 3.10')
10+
endif
11+
12+
python_dep = python.dependency()
13+
14+
# https://numpy.org/doc/2.0/reference/random/examples/cython/meson.build.html
15+
_numpy_abs = run_command(python, ['-c',
16+
'import os; os.chdir(".."); import numpy; print(os.path.abspath(numpy.get_include() + "../../.."))'],
17+
check: true).stdout().strip()
18+
19+
cc = meson.get_compiler('c')
20+
21+
npymath_path = _numpy_abs / '_core' / 'lib'
22+
npy_include_path = _numpy_abs / '_core' / 'include'
23+
npyrandom_path = _numpy_abs / 'random' / 'lib'
24+
npymath_lib = cc.find_library('npymath', dirs: npymath_path)
25+
npyrandom_lib = cc.find_library('npyrandom', dirs: npyrandom_path)
26+
27+
numpy_dep = dependency('numpy', required: true)
28+
29+
package_name = 'cynetdiff'
30+
# Path to your Python package sources relative to meson.build
31+
package_source_dir = 'src' / package_name
32+
33+
# Install the Cython extension module
34+
python.extension_module(
35+
'models',
36+
package_source_dir / 'models.pyx',
37+
dependencies: [npyrandom_lib, python_dep, numpy_dep],
38+
override_options : ['cython_language=cpp'],
39+
install: true,
40+
subdir: 'cynetdiff',
41+
cpp_args: ['-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION', '-Wno-pedantic'],
42+
)
43+
44+
# Install pure python files
45+
install_subdir(
46+
package_source_dir,
47+
install_dir: python.get_install_dir()
48+
)

0 commit comments

Comments
 (0)