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
71 changes: 71 additions & 0 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
parse:
additional_commands:
pybind11_mkdoc:
kwargs:
OUTPUT: 1
PYBIND11_MODULE: 1
HEADERS: "*"
EXTRA_ARGS: "*"

format:
line_width: 99
tab_size: 2

# If an argument group contains more than this many sub-groups
# (parg or kwarg groups) then force it to a vertical layout.
max_subgroups_hwrap: 2

# If a positional argument group contains more than this many
# arguments, then force it to a vertical layout.
max_pargs_hwrap: 6

# If a cmdline positional group consumes more than this many
# lines without nesting, then invalidate the layout (and nest)
max_rows_cmdline: 2
separate_ctrl_name_with_space: false
separate_fn_name_with_space: false
dangle_parens: false

# If the trailing parenthesis must be 'dangled' on its on
# 'line, then align it to this reference: `prefix`: the start'
# 'of the statement, `prefix-indent`: the start of the'
# 'statement, plus one indentation level, `child`: align to'
# the column of the arguments
dangle_align: prefix
# If the statement spelling length (including space and
# parenthesis) is smaller than this amount, then force reject
# nested layouts.
min_prefix_chars: 4

# If the statement spelling length (including space and
# parenthesis) is larger than the tab width by more than this
# amount, then force reject un-nested layouts.
max_prefix_chars: 10

# If a candidate layout is wrapped horizontally but it exceeds
# this many lines, then reject the layout.
max_lines_hwrap: 2

line_ending: unix

# Format command names consistently as 'lower' or 'upper' case
command_case: canonical

# Format keywords consistently as 'lower' or 'upper' case
# unchanged is valid too
keyword_case: "upper"

# A list of command names which should always be wrapped
always_wrap: []

# If true, the argument lists which are known to be sortable
# will be sorted lexicographically
enable_sort: true

# If true, the parsers may infer whether or not an argument
# list is sortable (without annotation).
autosort: false

# Reflowing comments destroys hand-made lists and examples
markup:
enable_markup: false
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ name: CI
on:
pull_request:
push:
branches:
branches:
- master
tags:
- 'v*'

jobs:
format:
lint:
runs-on: ubuntu-latest
name: Format
name: Lint
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v9.0.0
- run: uvx hatch fmt
- run: uvx prek run -a --show-diff-on-failure

checks:
strategy:
Expand All @@ -41,7 +41,7 @@ jobs:

- name: Test package
run: uv run --with "clang<19" --group test pytest

checks_windows:
strategy:
fail-fast: false
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,3 @@ dmypy.json

# Cython debug symbols
cython_debug/

119 changes: 119 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# To use locally:
#
# prek -a
#
# Or:
#
# prek install # (runs every time you commit in git)
#
# To update this file:
#
# prek autoupdate
#
# See https://github.com/pre-commit/pre-commit

ci:
autoupdate_commit_msg: "chore(deps): update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"
autoupdate_schedule: monthly

# Test fixtures are compared byte-for-byte against generated output
exclude: ^tests/.*_docs/

repos:

# Ruff, the Python auto-correcting linter/formatter written in Rust
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.16.1
hooks:
- id: ruff-check
args: ["--fix", "--show-fixes"]
- id: ruff-format

# Check static types with mypy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v2.3.0"
hooks:
- id: mypy
exclude: ^tests/
additional_dependencies:
- pytest

# CMake formatting
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: "v0.6.13"
hooks:
- id: cmake-format
additional_dependencies: [pyyaml]
types: [file]
files: (\.cmake|CMakeLists.txt)(.in)?$
# These two are written by CMake itself
exclude: ^pybind11_mkdoc/share/cmake/pybind11_mkdoc/pybind11_mkdocConfig(Version)?\.cmake$

# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v6.0.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace

# Also code format the docs
- repo: https://github.com/adamchainz/blacken-docs
rev: "1.20.0"
hooks:
- id: blacken-docs
additional_dependencies:
- black==23.*

# Changes tabs to spaces
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: "v1.5.6"
hooks:
- id: remove-tabs

# Avoid directional quotes
- repo: https://github.com/sirosen/texthooks
rev: "0.7.1"
hooks:
- id: fix-ligatures
- id: fix-smartquotes

# Check for spelling
- repo: https://github.com/codespell-project/codespell
rev: "v2.4.3"
hooks:
- id: codespell

# Also check spelling
# Use mirror because pre-commit autoupdate confuses tags in the upstream repo.
# See https://github.com/crate-ci/typos/issues/390
- repo: https://github.com/adhtruong/mirrors-typos
rev: "v1.48.0"
hooks:
- id: typos
args: []

# Disallow some common capitalization mistakes
- repo: local
hooks:
- id: disallow-caps
name: Disallow improper capitalization
language: pygrep
entry: PyBind|\bNumpy\b|Cmake|CCache|PyTest
exclude: ^\.pre-commit-config.yaml$

# Check schemas on some of our YAML files
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.37.4
hooks:
- id: check-github-workflows
- id: check-dependabot
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ py::class_<MyClass>(m, "MyClass", DOC(MyClass))

### CMake
The `pybind11_mkdoc` CMake function is included to easily generate header for a pybind11 module when
compiling said module in CMake. The function generates the headers based on the arguments provided.
In addition, it add target dependencies so the pybind11-mkdoc header file is generated before
the pybind11 module. Also, it will automatically add the current binary directory to the pybind11
compiling said module in CMake. The function generates the headers based on the arguments provided.
In addition, it add target dependencies so the pybind11-mkdoc header file is generated before
the pybind11 module. Also, it will automatically add the current binary directory to the pybind11
module's includes, so it can easily be included when compiling the module.

The required parameters are:
* OUTPUT - The name of the output file.
* PYBIND11_MODULE - The pybind11 module target that these docs will be used for.
* HEADERS - The header files to create docs for. These can be absoulte paths or relative to the
* HEADERS - The header files to create docs for. These can be absolute paths or relative to the
current source directory.

The optional parameters are:
* EXTRA_ARGS - This string argument will be added verbatim to the pybind11-mkdoc command.

Below is an exmaple of how it is used:
Below is an example of how it is used:
```cmake
# Find pybind11-mkdoc
# This assumes you have already run a find_package for Python.
Expand All @@ -104,9 +104,9 @@ find_package(pybind11_mkdoc REQUIRED CONFIG)
# Add the pybind11 module
pybind11_add_module(my_pybind11_module my_src_files.cc)
pybind11_mkdoc(
OUTPUT my_pybind11_module_docs.h
OUTPUT my_pybind11_module_docs.h
PYBIND11_MODULE my_pybind11_module
HEADERS
HEADERS
header_1.h
/absolute/path/to/header_2.h
)
Expand Down
32 changes: 12 additions & 20 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ cmake_minimum_required(VERSION 3.25...4.3)
# Read the version from the Python package; project() accepts numeric components only,
# so any dev/pre-release suffix is dropped.
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/../pybind11_mkdoc/__init__.py" version_line
REGEX "^__version__ *= *[\"']"
)
REGEX "^__version__ *= *[\"']")
if(NOT version_line MATCHES "([0-9]+(\\.[0-9]+)*)")
message(FATAL_ERROR "Could not read __version__ from pybind11_mkdoc/__init__.py")
message(FATAL_ERROR "Could not read __version__ from pybind11_mkdoc/__init__.py")
endif()

project(pybind11_mkdoc VERSION "${CMAKE_MATCH_1}")
Expand All @@ -15,27 +14,20 @@ include(CMakePackageConfigHelpers)

# Generate version file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/pybind11_mkdocConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
"${CMAKE_CURRENT_BINARY_DIR}/pybind11_mkdocConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

# Create config file
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/pybind11_mkdocConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/pybind11_mkdocConfig.cmake"
INSTALL_DESTINATION pybind11_mkdoc
)
"${CMAKE_CURRENT_SOURCE_DIR}/pybind11_mkdocConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/pybind11_mkdocConfig.cmake" INSTALL_DESTINATION pybind11_mkdoc)

# Install config + version
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/pybind11_mkdocConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/pybind11_mkdocConfigVersion.cmake"
DESTINATION pybind11_mkdoc
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pybind11_mkdocConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/pybind11_mkdocConfigVersion.cmake"
DESTINATION pybind11_mkdoc)

# Install functions
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/pybind11_mkdoc_functions.cmake"
DESTINATION pybind11_mkdoc
)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pybind11_mkdoc_functions.cmake"
DESTINATION pybind11_mkdoc)
Loading