Skip to content

Commit

Permalink
scan-headers: make it more useful by default
Browse files Browse the repository at this point in the history
- Show only missing headers by default since that's what you usually want
- Add the ability to ignore headers
  • Loading branch information
virtuald committed Aug 25, 2024
1 parent b21b526 commit 6b27c27
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
15 changes: 14 additions & 1 deletion docs/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,20 @@ your python package.

This will scan all of your defined includes directories (including those of
downloaded artifacts) and output something you can paste into the ``generate``
key of ``pyproject.toml``.
key of ``pyproject.toml``. By default it will only show files that are not
present in ``pyproject.toml`` -- to show all files use the ``--all`` argument.

Often there are files that you don't want to wrap. You can add them to the
``pyproject.toml`` file and they will be ignored. The list accepts glob patterns
supported by the fnmatch module.

.. code-block:: toml
[tool.robotpy-build]
scan_headers_ignore = [
"ignored_header.h",
"ignore_dir/*",
]
.. _create_gen:

Expand Down
3 changes: 3 additions & 0 deletions robotpy_build/config/pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ class RobotpyBuildConfig(Model):
#: Python package to store version information and robotpy-build metadata in
base_package: str

#: List of headers for the scan-headers tool to ignore
scan_headers_ignore: List[str] = []

#: List of python packages with __init__.py to update when ``python setup.py update_init``
#: is called -- this is an argument to the ``robotpy-build create-imports`` command, and
#: may contain a space and the second argument to create-imports.
Expand Down
32 changes: 23 additions & 9 deletions robotpy_build/tool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import fnmatch
import glob
import inspect
from itertools import chain
Expand Down Expand Up @@ -132,14 +133,22 @@ def add_subparser(cls, parent_parser, subparsers):
help="Generate a list of headers in TOML form",
parents=[parent_parser],
)
parser.add_argument("--only-missing", default=False, action="store_true")
parser.add_argument("--all", default=False, action="store_true")
return parser

def run(self, args):
s = get_setup()

to_ignore = s.project.scan_headers_ignore

def _should_ignore(f):
for pat in to_ignore:
if fnmatch.fnmatch(f, pat):
return True
return False

already_present = {}
if args.only_missing:
if not args.all:
for i, wrapper in enumerate(s.project.wrappers.values()):
files = set()
if wrapper.autogen_headers:
Expand All @@ -156,9 +165,7 @@ def run(self, args):
ifiles.add(f)

for wrapper in s.wrappers:
print(
f'[tool.robotpy-build.wrappers."{wrapper.package_name}".autogen_headers]'
)
printed = False

# This uses the direct include directories instead of the generation
# search path as we only want to output a file once
Expand All @@ -172,15 +179,22 @@ def run(self, args):
glob.glob(join(incdir, "**", "*.h"), recursive=True),
glob.glob(join(incdir, "**", "*.hpp"), recursive=True),
)
if "rpygen" not in f
if "rpygen" not in f and not _should_ignore(relpath(f, incdir))
)
)

files = [f for f in files if f not in wpresent]
if not files:
continue

if not printed:
print(
f'[tool.robotpy-build.wrappers."{wrapper.package_name}".autogen_headers]'
)
printed = True

lastdir = None
for f in files:
if f in wpresent:
continue

thisdir = f.parent
if lastdir is None:
if thisdir:
Expand Down

0 comments on commit 6b27c27

Please sign in to comment.