Skip to content

Commit

Permalink
Merge pull request #41 from qognitive/feature/setuptools_cmake
Browse files Browse the repository at this point in the history
[feature] Switching to `scikit-build`
  • Loading branch information
jamesETsmith authored Oct 1, 2024
2 parents 39b5bd7 + ed9c731 commit a115556
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/all_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
- name: Install
run: |
cmake --install ${{github.workspace}}/build
python -m pip install .[dev]
python -m pip install "scikit-build-core"
python -m pip install ".[dev]" --no-build-isolation
- name: Test C++
env:
OMP_NUM_THREADS: 2
Expand Down
27 changes: 12 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@
# BUILD
###############################################################################

build-cpp:
cmake -B build
cmake --build build --parallel
cmake --install build
# TODO in general python build should internally trigger cmake, but for now
# let's keep cmake lines here as we don't have any python build process yet

build-py:
python -m pip cache purge
python -m pip install --upgrade pip
python -m pip install ".[dev]"
python -m build .

# Build the C++/Python package from scratch (ignore existing build dir)
.PHONY: build
build: build-cpp build-py
build:
python -m pip install -e ".[dev]"

# Build the C++/Python package will try to reuse existing build directory, will
# not always work on a fresh checkout bc it requires prereqs to be installed.
# See https://scikit-build-core.readthedocs.io/en/latest/configuration.html#editable-installs
.PHONY: rebuild
rebuild:
python -m pip install -e ".[dev]" --no-build-isolation


###############################################################################
# DOCS
###############################################################################

.PHONY: docs
docs: build-cpp
docs: build
python -m pip install ".[docs]"
cd docs && doxygen Doxyfile
sphinx-autobuild -b html docs/ docs/html --host 0.0.0.0 --port 1900
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ There are two strategies for building `fast_pauli` from source. One is a quick a
- C++ compiler with OpenMP and C++20 support (LLVM recommended)
- Python >= 3.10

#### Quick Start
#### Quick Start (Users)
```bash
make build
make test
python -m pip install -e ".[dev]"
pytest -v tests/fast_pauli
```

#### Configurable Build
#### Configurable Build (Developers)
```bash
cmake -B build # + other cmake flags
cmake --build build --target install --parallel
ctest --test-dir build

python -m pip install -e ".[dev]"
python -m pip install --no-build-isolation -ve.
pytest -v tests/fast_pauli # + other pytest flags
```
Compiled `_fast_pauli` python module gets installed into `fast_pauli` directory.
Expand Down
1 change: 0 additions & 1 deletion fast_pauli/cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
nanobind_add_module(_fast_pauli NOMINSIZE NOSTRIP PROTECT_STACK fast_pauli.cpp)
target_link_libraries(_fast_pauli PRIVATE fast_pauli)

install(TARGETS _fast_pauli LIBRARY DESTINATION "${PROJECT_BINARY_DIR}/fppy")
install(TARGETS _fast_pauli
LIBRARY DESTINATION "${PROJECT_SOURCE_DIR}/fast_pauli")
86 changes: 60 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
################################################################################
# Build System
################################################################################

[build-system]
requires = ["setuptools>=64", "build", "setuptools_scm[toml]>=8","cmake>=3.25"]
build-backend = "setuptools.build_meta"
requires = [
# scikit-build-core uses cmake as needed (do not list it here)
"scikit-build-core",
]
build-backend = "scikit_build_core.build"


################################################################################
# Project
################################################################################

[project]
name = "fast_pauli"
readme = "README.md"
description = "fast pauli"
authors = [
{ name="James. E. T. Smith", email="[email protected]" },
{ name="Eugene Rublenko", email="[email protected]" },
{ name="Alex Lerner", email="[email protected]" },
{ name="Sebastien Roy", email="[email protected]" },
{ name="Jeffrey Berger", email="[email protected]" },
]
dependencies = ["numpy", "scipy", "qiskit", "qiskit-algorithms"]
dynamic = ["version"]
version = "0.0.1"
classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]


[project.optional-dependencies]
dev = [
"clang-format",
"cmake-format",
"pre-commit",
"build",
"mypy",
"ruff",
"pytest",
"pytest-benchmark",
"setuptools_scm[toml]>=8",
"sphinx",
"sphinx_rtd_theme",
"sphinx-autobuild",
]
docs = [
"cmake>=3.25",
Expand All @@ -35,14 +62,10 @@ docs = [
examples = [
]

[tool.setuptools]
packages = ["fast_pauli"]

[tool.setuptools.package-dir]
fast_pauli = "fast_pauli"

[tool.setuptools_scm]
version_file = "fast_pauli/__version__.py"
################################################################################
# Linting/Formatting
################################################################################

[tool.mypy]
warn_redundant_casts = true
Expand Down Expand Up @@ -103,20 +126,18 @@ indent-width = 4
target-version = "py38"

[tool.ruff.lint]

# Ruff Rules https://docs.astral.sh/ruff/rules/
# F - PyFlakes (https://docs.astral.sh/ruff/rules/#pyflakes-f)
# E, W - pycodestyle (https://docs.astral.sh/ruff/rules/#pycodestyle-e-w)
# I - Isort (https://docs.astral.sh/ruff/rules/#isort-i)
# N - PEP-8 Naming (https://docs.astral.sh/ruff/rules/#pep8-naming-n)
# D - pydocstyle (https://docs.astral.sh/ruff/rules/#pydocstyle-d)
# YTT - flake8-2020 (https://docs.astral.sh/ruff/rules/#flake8-2020-ytt)
# ASYNC flake8-async (https://docs.astral.sh/ruff/rules/#flake8-async-async)
# B flake8-bugbear (https://docs.astral.sh/ruff/rules/#flake8-bugbear-b)
# UP flake8-bandit (https://docs.astral.sh/ruff/rules/#flake8-bandit-up)
# SIM flake8-simplify (https://docs.astral.sh/ruff/rules/#flake8-simplify-sim)

select = ["F", "E", "W", "I", "N", "D", "YTT", "ASYNC", "B", "UP", "SIM"]
select = [
"F", # PyFlakes (https://docs.astral.sh/ruff/rules/#pyflakes-f)
"E", "W", # pycodestyle (https://docs.astral.sh/ruff/rules/#pycodestyle-e-w)
"I", # Isort (https://docs.astral.sh/ruff/rules/#isort-i)
"N", # PEP-8 Naming (https://docs.astral.sh/ruff/rules/#pep8-naming-n)
"D", # pydocstyle (https://docs.astral.sh/ruff/rules/#pydocstyle-d)
"YTT", # flake8-2020 (https://docs.astral.sh/ruff/rules/#flake8-2020-ytt)
"ASYNC", # flake8-async (https://docs.astral.sh/ruff/rules/#flake8-async-async)
"B", # flake8-bugbear (https://docs.astral.sh/ruff/rules/#flake8-bugbear-b)
"UP", # flake8-bandit (https://docs.astral.sh/ruff/rules/#flake8-bandit-up)
"SIM", # flake8-simplify (https://docs.astral.sh/ruff/rules/#flake8-simplify-sim)
]

ignore = [
# Allow non-lowercase variable names to help the code match the math better
Expand All @@ -131,3 +152,16 @@ convention = "numpy"
[tool.ruff.format]
quote-style = "double"
docstring-code-format = true


################################################################################
# Packaging
################################################################################

# https://scikit-build-core.readthedocs.io/en/latest/#configuration
# Example: use LLVM
# pip install -e . --verbose -C cmake.args="-DCMAKE_CXX_COMPILER=clang++-18"
[tool.scikit-build]
cmake.build-type = "Release"
build-dir = "build"
# TODO add more options here

0 comments on commit a115556

Please sign in to comment.