Skip to content

Commit a3198b8

Browse files
authored
New flag and code update for its use (#942)
Signed-off-by: AngeLoGa <angeloga.rea@gmail.com>
1 parent 8e46bf2 commit a3198b8

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

ros2doctor/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Run `ros2 doctor -rf/--report-fail` to see report of failed checks only.
1818
Run `ros2 doctor -iw/--include-warnings` to include warnings as failed checks.
1919
`-iw` and `-rf` can be used in combination.
2020

21+
Run `ros2 doctor -ep/--exclude-packages` to exclude package checks or report.
22+
23+
2124
## Add New Checks
2225

2326
To add your own checks or information to report, use [Python entry points](https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points) to add modules to `setup.py`.

ros2doctor/ros2doctor/api/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def add_warning(self):
8181
self.warning += 1
8282

8383

84-
def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]:
84+
def run_checks(*, include_warnings=False, exclude_packages=False) -> Tuple[Set[str], int, int]:
8585
"""
8686
Run all checks and return check results.
8787
@@ -96,6 +96,10 @@ def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]:
9696
groups = entry_points.select(group='ros2doctor.checks')
9797
else:
9898
groups = entry_points.get('ros2doctor.checks', [])
99+
100+
if exclude_packages:
101+
groups = [ep for ep in groups if ep.name != 'PackageCheck']
102+
99103
for check_entry_pt in groups:
100104
try:
101105
check_class = check_entry_pt.load()
@@ -119,7 +123,7 @@ def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]:
119123
return fail_categories, fail, total
120124

121125

122-
def generate_reports(*, categories=None) -> List[Report]:
126+
def generate_reports(*, categories=None, exclude_packages=False) -> List[Report]:
123127
"""
124128
Print all reports or reports of failed checks to terminal.
125129
@@ -131,6 +135,10 @@ def generate_reports(*, categories=None) -> List[Report]:
131135
groups = entry_points.select(group='ros2doctor.report')
132136
else:
133137
groups = entry_points.get('ros2doctor.report', [])
138+
139+
if exclude_packages:
140+
groups = [ep for ep in groups if ep.name != 'PackageReport']
141+
134142
for report_entry_pt in groups:
135143
try:
136144
report_class = report_entry_pt.load()

ros2doctor/ros2doctor/command/doctor.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def add_arguments(self, parser, cli_name):
3232
'--report-failed', '-rf', action='store_true',
3333
help='Print reports of failed checks only.'
3434
)
35+
parser.add_argument(
36+
'--exclude-packages', '-ep', action='store_true',
37+
help='Exclude package checks or report.'
38+
)
3539
parser.add_argument(
3640
'--include-warnings', '-iw', action='store_true',
3741
help='Include warnings as failed checks. Warnings are ignored by default.'
@@ -46,15 +50,18 @@ def main(self, *, parser, args):
4650
extension = getattr(args, '_verb')
4751
return extension.main(args=args)
4852

53+
# Local Variables to reduce code length
54+
iw, ep = (args.include_warnings, args.exclude_packages)
4955
# `ros2 doctor -r`
5056
if args.report:
51-
all_reports = generate_reports()
57+
all_reports = generate_reports(exclude_packages=ep)
5258
for report_obj in all_reports:
5359
format_print(report_obj)
5460
return
5561

5662
# `ros2 doctor
57-
fail_category, fail, total = run_checks(include_warnings=args.include_warnings)
63+
64+
fail_category, fail, total = run_checks(include_warnings=iw, exclude_packages=ep)
5865
if fail:
5966
print(f'\n{fail}/{total} check(s) failed\n')
6067
print('Failed modules:', *fail_category)

0 commit comments

Comments
 (0)