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
24 changes: 11 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ on:
- 'v*'

jobs:
format:
runs-on: ubuntu-latest
name: Format
steps:
- uses: actions/checkout@v5
- uses: astral-sh/setup-uv@v7
- run: uvx hatch fmt

checks:
strategy:
fail-fast: false
Expand All @@ -27,12 +35,10 @@ jobs:
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

- name: Install package
run: python -m pip install .[test] "clang<19"
- uses: astral-sh/setup-uv@v7

- name: Test package
run: python -m pytest --forked
run: uv run --with "clang<19" --extra test pytest --forked

# Commented for now -- msys2 Clang (v15) and the clang Python package (v14) are incompatible
#
Expand Down Expand Up @@ -69,12 +75,4 @@ jobs:
name: Build distribution
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6

- name: Build
run: pipx run build

- uses: actions/upload-artifact@v5
with:
name: DistPackage
path: dist
- uses: hynek/build-and-inspect-python-package@v2
91 changes: 56 additions & 35 deletions pybind11_mkdoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
(Docs WIP).
"""


import argparse
import os
import re
import shlex
import sys

from .mkdoc_lib import mkdoc

from pybind11_mkdoc.mkdoc_lib import mkdoc

__version__ = "2.6.2.dev1"


def _append_include_dir(args: list, include_dir: str, verbose: bool = True):
def _append_include_dir(args: list, include_dir: str, *, verbose: bool = True):
"""
Add an include directory to an argument list (if it exists).

Expand All @@ -37,10 +33,10 @@ def _append_include_dir(args: list, include_dir: str, verbose: bool = True):
if os.path.isdir(include_dir):
args.append(f"-I{include_dir}")
elif verbose:
print(f"Include directory {include_dir!r} does not exist!")
pass


def _append_definition(args: list, definition: str, verbose: bool = True):
def _append_definition(args: list, definition: str):
"""
Add a compiler definition to an argument list.

Expand All @@ -61,21 +57,20 @@ def _append_definition(args: list, definition: str, verbose: bool = True):
"""

try:
macro, _, value = definition.partition('=')
macro, _, value = definition.partition("=")
macro = macro.strip()
value = value.strip() if value else '1'
value = value.strip() if value else "1"

args.append(f"-D{macro}={value}")
except ValueError as exc:
except ValueError:
# most likely means there was no '=' given
# check if argument is valid identifier
if re.search(r'^[A-Za-z_][A-Za-z0-9_]*', definition):
if re.search(r"^[A-Za-z_][A-Za-z0-9_]*", definition):
args.append(f"-D{definition}")
else:
print(f"Failed to parse definition: {definition}")
except:
print(f"Failed to parse definition: {definition}")

pass
except Exception:
pass


def main():
Expand All @@ -86,26 +81,53 @@ def main():
"""

parser = argparse.ArgumentParser(
prog='pybind11_mkdoc',
description="Processes a sequence of C/C++ headers and extracts comments for use in pybind11 binding code.",
epilog="(Other compiler flags that Clang understands can also be supplied)",
allow_abbrev=False)
prog="pybind11_mkdoc",
description="Processes a sequence of C/C++ headers and extracts comments for use in pybind11 binding code.",
epilog="(Other compiler flags that Clang understands can also be supplied)",
allow_abbrev=False,
)

parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {__version__}")

parser.add_argument("-o", "--output", action="store", type=str, dest="output", metavar="<file>",
help="Write to the specified file (default: use stdout).")

parser.add_argument("-w", "--width", action="store", type=int, dest="width", metavar="<width>",
help="Specify docstring width before wrapping.")

parser.add_argument("-I", action="append", type=str, dest="include_dirs", metavar="<dir>",
help="Specify an directory to add to the list of include search paths.")

parser.add_argument("-D", action="append", type=str, metavar="<macro>=<value>", dest="definitions",
help="Specify a compiler definition, i.e. define <macro> to <value> (or 1 if <value> omitted).")

parser.add_argument("header", type=str, nargs='+', help="A header file to process.")
parser.add_argument(
"-o",
"--output",
action="store",
type=str,
dest="output",
metavar="<file>",
help="Write to the specified file (default: use stdout).",
)

parser.add_argument(
"-w",
"--width",
action="store",
type=int,
dest="width",
metavar="<width>",
help="Specify docstring width before wrapping.",
)

parser.add_argument(
"-I",
action="append",
type=str,
dest="include_dirs",
metavar="<dir>",
help="Specify an directory to add to the list of include search paths.",
)

parser.add_argument(
"-D",
action="append",
type=str,
metavar="<macro>=<value>",
dest="definitions",
help="Specify a compiler definition, i.e. define <macro> to <value> (or 1 if <value> omitted).",
)

parser.add_argument("header", type=str, nargs="+", help="A header file to process.")

[parsed_args, unparsed_args] = parser.parse_known_args()

Expand All @@ -130,8 +152,7 @@ def main():
# append argument as is and hope for the best
mkdoc_args.append(arg)

for header in parsed_args.header:
mkdoc_args.append(header)
mkdoc_args.extend(header for header in parsed_args.header)

mkdoc(mkdoc_args, docstring_width, mkdoc_out)

Expand Down
5 changes: 2 additions & 3 deletions pybind11_mkdoc/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

if __name__ == "__main__":
from . import main
main()
from pybind11_mkdoc import main

main()
Loading