Skip to content

Commit 8276c95

Browse files
committed
scan-headers: make it more useful by default
- Show only missing headers by default since that's what you usually want - Add the ability to ignore headers
1 parent e32b8af commit 8276c95

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

docs/tools.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,20 @@ your python package.
1515

1616
This will scan all of your defined includes directories (including those of
1717
downloaded artifacts) and output something you can paste into the ``generate``
18-
key of ``pyproject.toml``.
18+
key of ``pyproject.toml``. By default it will only show files that are not
19+
present in ``pyproject.toml`` -- to show all files use the ``--all`` argument.
20+
21+
Often there are files that you don't want to wrap. You can add them to the
22+
``pyproject.toml`` file and they will be ignored. The list accepts glob patterns
23+
supported by the fnmatch module.
24+
25+
.. code-block:: toml
26+
27+
[tool.robotpy-build]
28+
scan_headers_ignore = [
29+
"ignored_header.h",
30+
"ignore_dir/*",
31+
]
1932
2033
.. _create_gen:
2134

robotpy_build/config/pyproject_toml.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ class RobotpyBuildConfig(Model):
416416
#: Python package to store version information and robotpy-build metadata in
417417
base_package: str
418418

419+
#: List of headers for the scan-headers tool to ignore
420+
scan_headers_ignore: List[str] = []
421+
419422
#: List of python packages with __init__.py to update when ``python setup.py update_init``
420423
#: is called -- this is an argument to the ``robotpy-build create-imports`` command, and
421424
#: may contain a space and the second argument to create-imports.

robotpy_build/tool.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import fnmatch
23
import glob
34
import inspect
45
from itertools import chain
@@ -132,14 +133,22 @@ def add_subparser(cls, parent_parser, subparsers):
132133
help="Generate a list of headers in TOML form",
133134
parents=[parent_parser],
134135
)
135-
parser.add_argument("--only-missing", default=False, action="store_true")
136+
parser.add_argument("--all", default=False, action="store_true")
136137
return parser
137138

138139
def run(self, args):
139140
s = get_setup()
140141

142+
to_ignore = s.project.scan_headers_ignore
143+
144+
def _should_ignore(f):
145+
for pat in to_ignore:
146+
if fnmatch.fnmatch(f, pat):
147+
return True
148+
return False
149+
141150
already_present = {}
142-
if args.only_missing:
151+
if not args.all:
143152
for i, wrapper in enumerate(s.project.wrappers.values()):
144153
files = set()
145154
if wrapper.autogen_headers:
@@ -156,9 +165,7 @@ def run(self, args):
156165
ifiles.add(f)
157166

158167
for wrapper in s.wrappers:
159-
print(
160-
f'[tool.robotpy-build.wrappers."{wrapper.package_name}".autogen_headers]'
161-
)
168+
printed = False
162169

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

186+
files = [f for f in files if f not in wpresent]
187+
if not files:
188+
continue
189+
190+
if not printed:
191+
print(
192+
f'[tool.robotpy-build.wrappers."{wrapper.package_name}".autogen_headers]'
193+
)
194+
printed = True
195+
179196
lastdir = None
180197
for f in files:
181-
if f in wpresent:
182-
continue
183-
184198
thisdir = f.parent
185199
if lastdir is None:
186200
if thisdir:

0 commit comments

Comments
 (0)