Skip to content

Commit db20e75

Browse files
committed
feat: UNURAN as submodule with build
1 parent 5c3c777 commit db20e75

13 files changed

Lines changed: 868 additions & 2 deletions

File tree

.github/workflows/docs_deploy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ jobs:
2323
steps:
2424
- uses: actions/checkout@v4
2525

26+
- name: Sync submodules to tracked branches
27+
run: |
28+
git submodule sync --recursive
29+
git submodule update --init --remote --recursive
30+
2631
- uses: actions/setup-python@v5
2732
with:
2833
python-version: "3.12"

.github/workflows/docs_preview.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515

16+
- name: Sync submodules to tracked branches
17+
run: |
18+
git submodule sync --recursive
19+
git submodule update --init --remote --recursive
20+
1621
- uses: actions/setup-python@v5
1722
with:
1823
python-version: "3.12"

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ __pycache__/
55

66
# C extensions
77
*.so
8+
*.o
89

910
# Distribution / packaging
1011
.Python
@@ -127,7 +128,12 @@ poetry.lock
127128
.cursorindexingignore
128129

129130
# Docs
130-
131131
docs/build/*
132132
docs/source/api/*
133133
docs/source/examples/*
134+
135+
# Log files
136+
*.log
137+
138+
# Unuran build artifacts
139+
src/pysatl_core/sampling/unuran/bindings/_unuran_cffi.c

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "subprojects/unuran-pysatl"]
2+
path = subprojects/unuran-pysatl
3+
url = https://github.com/PySATL/unuran.git
4+
branch = main

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exclude: >
2020
| LICENSE$
2121
| .*\.md$
2222
| .*\.jpg$
23+
| subprojects/.*
2324
)$
2425
2526
repos:
@@ -68,3 +69,4 @@ repos:
6869
- scipy>=1.13
6970
- pytest>=8
7071
- scipy-stubs>=1.13
72+
- types-setuptools>=75

pyproject.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
[build-system]
22
build-backend = "poetry.core.masonry.api"
33

4-
requires = [ "poetry-core>=1.9" ]
4+
requires = [
5+
"cffi>=1.16",
6+
"meson>=0.64",
7+
"ninja>=1.10",
8+
"poetry-core>=1.9",
9+
"setuptools>=69",
10+
]
511

612
[tool.poetry]
713
name = "pysatl-core"
@@ -41,10 +47,15 @@ homepage = "https://github.com/PySATL/pysatl-core"
4147
repository = "https://github.com/PySATL/pysatl-core"
4248
urls.Issues = "https://github.com/PySATL/pysatl-core/issues"
4349

50+
[tool.poetry.build]
51+
script = "src/pysatl_core/sampling/unuran/bindings/_cffi_build.py"
52+
4453
[tool.poetry.dependencies]
4554
python = ">=3.12"
4655
numpy = "^2.0.0"
4756
scipy = ">=1.13"
57+
cffi = "^1.16.0"
58+
mypy_extensions = ">=1.0.0"
4859

4960
[tool.poetry.group.dev.dependencies]
5061
ruff = ">=0.6"
@@ -55,6 +66,7 @@ coverage = { version = ">=7.5", extras = [ "toml" ] }
5566
pre-commit = ">=3.6"
5667
types-setuptools = "*"
5768
scipy-stubs = ">=1.13.0.0"
69+
types-cffi = ">=1.17.0.0"
5870

5971
[tool.poetry.group.docs.dependencies]
6072
jupyter = "^1.1.1"
@@ -70,6 +82,7 @@ linkify-it-py = "^2.0.3"
7082
[tool.ruff]
7183
target-version = "py312"
7284
line-length = 100
85+
exclude = [ "subprojects" ]
7386

7487
format.line-ending = "lf"
7588

@@ -84,6 +97,9 @@ lint.isort.force-single-line = false
8497
lint.isort.known-first-party = [ "pysatl_core" ]
8598
lint.isort.order-by-type = true
8699

100+
[tool.codespell]
101+
skip = "subprojects/**"
102+
87103
[tool.pytest.ini_options]
88104
addopts = "-q --cov=pysatl_core --cov-report=term-missing"
89105
testpaths = [ "tests" ]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
PySATL Core — UNU.RAN CFFI Bindings
3+
=====================================
4+
5+
Lazy loader for the compiled CFFI extension module ``_unuran_cffi``.
6+
Tries the fully-qualified package path first, then falls back to a
7+
bare top-level import so the extension can be found regardless of
8+
how it was installed. Exposes ``_unuran_cffi`` (``None`` when the
9+
binary extension is not available).
10+
"""
11+
12+
from __future__ import annotations
13+
14+
__author__ = "Artem Romanyuk"
15+
__copyright__ = "Copyright (c) 2025 PySATL project"
16+
__license__ = "SPDX-License-Identifier: MIT"
17+
18+
from importlib import import_module
19+
from types import ModuleType
20+
21+
_unuran_cffi_module = None
22+
23+
for name in (
24+
"pysatl_core.sampling.unuran.bindings._unuran_cffi",
25+
"_unuran_cffi",
26+
):
27+
try:
28+
_unuran_cffi_module = import_module(name)
29+
break
30+
except ModuleNotFoundError: # pragma: no cover - optional binary module
31+
pass
32+
33+
_unuran_cffi: ModuleType | None = _unuran_cffi_module
34+
35+
__all__ = [
36+
"_unuran_cffi",
37+
]

0 commit comments

Comments
 (0)