Skip to content
Open
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
20 changes: 0 additions & 20 deletions .vscode/tasks.json

This file was deleted.

71 changes: 71 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
cmake_minimum_required(VERSION 3.15...3.26)

project(humanleague LANGUAGES CXX)

if (NOT SKBUILD)
message(WARNING "\
This CMake file is meant to be executed using 'scikit-build'. Running
it directly will almost certainly not produce the desired result. If
you are a user trying to install this package, please use the command
below, which will install all necessary build dependencies, compile
the package in an isolated environment, and then install it.
=====================================================================
$ pip install .
=====================================================================
If you are a software developer, and this is your own package, then
it is usually much more efficient to install the build dependencies
in your environment once and use the following command that avoids
a costly creation of a new virtual environment at every compilation:
=====================================================================
$ pip install nanobind scikit-build-core[pyproject]
$ pip install --no-build-isolation -ve .
=====================================================================
You may optionally add -Ceditable.rebuild=true to auto-rebuild when
the package is imported. Otherwise, you need to re-run the above
after editing C++ files.")
endif()

# Try to import all Python components potentially needed by nanobind
find_package(Python 3.12
REQUIRED COMPONENTS Interpreter Development.Module
OPTIONAL_COMPONENTS Development.SABIModule)

# Import nanobind through CMake's find_package mechanism
find_package(nanobind CONFIG REQUIRED)

# We are now ready to compile the actual extension module
nanobind_add_module(
humanleague_ext

# Target the stable ABI for Python 3.12+, which reduces
# the number of binary wheels that must be built. This
# does nothing on older Python versions
STABLE_ABI

# Build libnanobind statically
NB_STATIC
# NB_SHARED creates path issues

# Source code goes here
src/Index.cpp
src/QIS.cpp
src/StatFuncs.cpp
src/TestReduce.cpp
src/TestStatFuncs.cpp
src/Integerise.cpp
src/QISI.cpp
src/Sobol.cpp
src/TestIndex.cpp
src/TestSlice.cpp
src/UnitTester.cpp
src/module.cpp
src/SobolImpl.cpp
src/TestNDArray.cpp
src/TestSobol.cpp
)

target_compile_definitions(humanleague_ext PUBLIC PYTHON_MODULE)

# Install directive for scikit-build-core
install(TARGETS humanleague_ext LIBRARY DESTINATION humanleague)

22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,25 @@ pip install humanleague

[uv](https://docs.astral.sh/uv/) is highly recommended for managing environments.


```bash
uv sync --dev
uv run pytest
```

Nanobind docs suggest a dev workflow where the build happens directly in the dev env - first manually install
the build deps (required after every `uv sync`)

```sh
uv pip install nanobind scikit-build-core[pyproject]
```

Then build with

```sh
uv pip install --no-build-isolation -ve .
```

### R

Official release:
Expand Down Expand Up @@ -105,7 +119,13 @@ The package now contains type annotations and your IDE should automatically disp

![help](./doc/help.png)

NB type stubs are generated using the `pybind11-stubgen` package, with some [manual corrections](./doc/type-stubs.md).
~~NB type stubs are generated using the `pybind11-stubgen` package, with some [manual corrections](./doc/type-stubs.md).~~

`nanobind` now has stubgen functionality (but appears limited as of 2.9.2)

```sh
uv run python -m nanobind.stubgen -P -m humanleague.humanleague_ext -o humanleague/__init__.pyi -M humanleague/py.typed
```

### Multidimensional integerisation

Expand Down
3 changes: 1 addition & 2 deletions humanleague/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

__version__ = importlib.metadata.version("humanleague")

from _humanleague import SobolSequence, flatten, integerise, ipf, qis, qisi

from .humanleague_ext import SobolSequence, flatten, integerise, ipf, qis, qisi
from .utils import tabulate_counts, tabulate_individuals

__all__ = [
Expand Down
12 changes: 4 additions & 8 deletions humanleague/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Microsynthesis using quasirandom sampling and IPF, plus related functionality
"""
"""Microsynthesis using quasirandom sampling and IPF, plus related functionality"""

from __future__ import annotations

Expand Down Expand Up @@ -52,16 +51,13 @@ class SobolSequence:

"""
def __iter__(self) -> SobolSequence:
"""__iter__ dunder
"""
"""__iter__ dunder"""
def __next__(self) -> npt.NDArray[np.float64]:
"""__next__ dunder
"""
"""__next__ dunder"""
pass

def _unittest() -> dict:
"""For developers. Runs the C++ unit tests.
"""
"""For developers. Runs the C++ unit tests."""

def flatten(pop: npt.NDArray[np.int64]) -> list:
"""Converts an n-dimensional array of counts into an n-column table with a row for each unit
Expand Down
29 changes: 17 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
[build-system]
requires = [
"setuptools>=42",
"wheel",
"pybind11>=2.10.3",
"pytest"
]
requires = ["scikit-build-core >=0.10", "nanobind >=2.3.2"]
build-backend = "scikit_build_core.build"

build-backend = "setuptools.build_meta"

[project]
name = "humanleague"
version = "2.4.3"
version = "2.5.0"
authors = [
{ name="Andrew Smith", email="andrew@friarswood.net" },
]
license = "MIT"
license-files = ["LICENCE", "LICENSE.md"]
description = "Microsynthesis using quasirandom sampling and/or IPF"
readme = "README.md"
Expand All @@ -32,26 +28,35 @@ dependencies = [

[dependency-groups]
dev = [
"pybind11>=3.0.0",
"pytest>=8.1.4",
"mypy>=1.5.0",
"mypy-extensions>=1.0.0",
"ruff>=0.12.9",
"build>=1.2.2.post1",
"typing-extensions>=4.15.0",
"scikit-build-core[pyproject]"
]

[tool.pytest.ini_options]
testpaths = [
"tests"
]

[tool.scikit-build]
# Protect the configuration against future changes in scikit-build-core
minimum-version = "build-system.requires"

# Setuptools-style build caching in a local directory
build-dir = "build/{wheel_tag}"

# Build stable ABI wheels for CPython 3.12+
wheel.py-api = "cp312"

[tool.ruff]
line-length = 120

[tool.ruff.lint]
select = ["B", "C", "E", "F", "I"]
ignore = ["E501"]
select = ["B", "C", "E", "F", "I", "N", "W"]
ignore = ["E501", "N802"]

[tool.ruff.lint.per-file-ignores]
"**/__init__.py" = ["F401", "F403"]
44 changes: 0 additions & 44 deletions setup.py

This file was deleted.

Loading
Loading