Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
poetry.lock linguist-generated=true
src/cynetdiff/models.cpp linguist-generated=true
pdm.lock linguist-generated=true
25 changes: 8 additions & 17 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,19 @@ on:
branches: ["*"]

jobs:
build:
benchmark:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.12"]
poetry-version: ["1.8.5"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- uses: abatilo/actions-poetry@v2
- name: Setup PDM
uses: pdm-project/setup-pdm@v4
with:
poetry-version: ${{ matrix.poetry-version }}
python-version: "3.12"
cache: true

- name: Install dependencies
run: poetry install --with dev,benchmark
run: pdm install -G test,build

- name: Benchmark with pytest-benchmark
run: poetry run pytest --benchmark-only --benchmark-warmup-iterations=0 benchmarks/test_benchmark.py
- name: Run benchmarks
run: pdm run pytest benchmarks
18 changes: 8 additions & 10 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: docs
# Based on https://squidfunk.github.io/mkdocs-material/publishing-your-site/
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
release:
types:
- published
permissions:
contents: write
jobs:
Expand All @@ -16,17 +17,14 @@ jobs:
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v5
with:
python-version: 3.12
- uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.8.2
- name: Setup PDM
uses: pdm-project/setup-pdm@v4
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: poetry install --with docs
- run: poetry run mkdocs gh-deploy --force
- run: pdm install -G docs --no-self
- run: pdm run mkdocs gh-deploy --force
31 changes: 12 additions & 19 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,28 @@ on:
branches: ["*"]

jobs:
ci:
strategy:
matrix:
python-version: ["3.12"]
poetry-version: ["1.8.1"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- uses: abatilo/actions-poetry@v2
- name: Setup PDM
uses: pdm-project/setup-pdm@v4
with:
poetry-version: ${{ matrix.poetry-version }}
python-version: "3.10"
cache: true

- name: Install dependencies
run: poetry install --with dev,benchmark
run: pdm install -G lint --no-self

- name: Run ruff lint check
run: poetry run ruff check .
run: pdm run ruff check .

- name: Run ruff format check
run: poetry run ruff format --check .
run: pdm run ruff format --check .

- name: Run Cython lint
run: poetry run cython-lint .
run: pdm run cython-lint .

- name: Run mypy
run: poetry run mypy .
run: pdm run mypy .
62 changes: 55 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,63 @@
# Automatically publishes version of the package on tagged release
# Largely copied from https://learn.scientific-python.org/development/guides/gha-wheels/
name: publish
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
release:
types:
- published
pull_request:
paths:
- .github/workflows/publish.yml

jobs:
build:
make_sdist:
name: Make SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build and publish to pypi
uses: JRubics/[email protected]

- name: Build SDist
run: pipx run build --sdist

- uses: actions/upload-artifact@v4
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}
name: cibw-sdist
path: dist/*.tar.gz

build_wheels:
name: Wheel on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# TODO add back windows-latest, when I can fix it
os: [ubuntu-latest, macos-13, macos-14]

steps:
- uses: actions/checkout@v4

- uses: astral-sh/setup-uv@v6

- uses: pypa/[email protected]

- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}
path: wheelhouse/*.whl

upload_all:
needs: [build_wheels, make_sdist]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v4
with:
pattern: cibw-*
path: dist
merge-multiple: true

- uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
28 changes: 8 additions & 20 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: tests

on:
Expand All @@ -10,28 +7,19 @@ on:
branches: ["*"]

jobs:
build:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
poetry-version: ["1.8.1"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- uses: abatilo/actions-poetry@v2
- name: Setup PDM
uses: pdm-project/setup-pdm@v4
with:
poetry-version: ${{ matrix.poetry-version }}
python-version: "3.10"
cache: true

- name: Install dependencies
run: poetry install --with dev
run: pdm install -G test,build

- name: Test with pytest
run: poetry run pytest
- name: Run tests
run: pdm run pytest
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ venv

# Cython
*.html
*.cpp
*.c

speed/

get_graph_hashes.py

.pdm-python
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"editor.defaultFormatter": "tamasfe.even-better-toml",
"editor.formatOnSave": true
},
"[json][yaml]": {
"editor.formatOnSave": true
},
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
Expand Down
62 changes: 0 additions & 62 deletions build_package.py

This file was deleted.

2 changes: 1 addition & 1 deletion demo/demo_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def plot_num_nodes_activated(
)
for i in range(max_length)
]
lower_quartile, upper_quartile = zip(*iqr_values)
lower_quartile, upper_quartile = zip(*iqr_values, strict=True)

for y in mean_infected:
plt.axhline(y=y, color=colors[idx], linestyle="--", alpha=0.2)
Expand Down
48 changes: 48 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
project('cynetdiff', 'cython', 'c',
meson_version : '>= 1.1',
default_options : ['warning_level=3']
)

python = import('python').find_installation('python3', pure: false)

if python.language_version().version_compare('< 3.10')
error('Requires Python >= 3.10')
endif

python_dep = python.dependency()

# https://numpy.org/doc/2.0/reference/random/examples/cython/meson.build.html
_numpy_abs = run_command(python, ['-c',
'import os; os.chdir(".."); import numpy; print(os.path.abspath(numpy.get_include() + "../../.."))'],
check: true).stdout().strip()

cc = meson.get_compiler('c')

npymath_path = _numpy_abs / '_core' / 'lib'
npy_include_path = _numpy_abs / '_core' / 'include'
npyrandom_path = _numpy_abs / 'random' / 'lib'
npymath_lib = cc.find_library('npymath', dirs: npymath_path)
npyrandom_lib = cc.find_library('npyrandom', dirs: npyrandom_path)

numpy_dep = dependency('numpy', required: true)

package_name = 'cynetdiff'
# Path to your Python package sources relative to meson.build
package_source_dir = 'src' / package_name

# Install the Cython extension module
python.extension_module(
'models',
package_source_dir / 'models.pyx',
dependencies: [npyrandom_lib, python_dep, numpy_dep],
override_options : ['cython_language=cpp'],
install: true,
subdir: 'cynetdiff',
cpp_args: ['-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION', '-Wno-pedantic'],
)

# Install pure python files
install_subdir(
package_source_dir,
install_dir: python.get_install_dir()
)
Loading