Skip to content

Commit

Permalink
New flag and code update for its use (#942)
Browse files Browse the repository at this point in the history
Signed-off-by: AngeLoGa <[email protected]>
  • Loading branch information
AngeLoGa authored Oct 28, 2024
1 parent 8e46bf2 commit a3198b8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ros2doctor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Run `ros2 doctor -rf/--report-fail` to see report of failed checks only.
Run `ros2 doctor -iw/--include-warnings` to include warnings as failed checks.
`-iw` and `-rf` can be used in combination.

Run `ros2 doctor -ep/--exclude-packages` to exclude package checks or report.


## Add New Checks

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`.
Expand Down
12 changes: 10 additions & 2 deletions ros2doctor/ros2doctor/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def add_warning(self):
self.warning += 1


def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]:
def run_checks(*, include_warnings=False, exclude_packages=False) -> Tuple[Set[str], int, int]:
"""
Run all checks and return check results.
Expand All @@ -96,6 +96,10 @@ def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]:
groups = entry_points.select(group='ros2doctor.checks')
else:
groups = entry_points.get('ros2doctor.checks', [])

if exclude_packages:
groups = [ep for ep in groups if ep.name != 'PackageCheck']

for check_entry_pt in groups:
try:
check_class = check_entry_pt.load()
Expand All @@ -119,7 +123,7 @@ def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]:
return fail_categories, fail, total


def generate_reports(*, categories=None) -> List[Report]:
def generate_reports(*, categories=None, exclude_packages=False) -> List[Report]:
"""
Print all reports or reports of failed checks to terminal.
Expand All @@ -131,6 +135,10 @@ def generate_reports(*, categories=None) -> List[Report]:
groups = entry_points.select(group='ros2doctor.report')
else:
groups = entry_points.get('ros2doctor.report', [])

if exclude_packages:
groups = [ep for ep in groups if ep.name != 'PackageReport']

for report_entry_pt in groups:
try:
report_class = report_entry_pt.load()
Expand Down
11 changes: 9 additions & 2 deletions ros2doctor/ros2doctor/command/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def add_arguments(self, parser, cli_name):
'--report-failed', '-rf', action='store_true',
help='Print reports of failed checks only.'
)
parser.add_argument(
'--exclude-packages', '-ep', action='store_true',
help='Exclude package checks or report.'
)
parser.add_argument(
'--include-warnings', '-iw', action='store_true',
help='Include warnings as failed checks. Warnings are ignored by default.'
Expand All @@ -46,15 +50,18 @@ def main(self, *, parser, args):
extension = getattr(args, '_verb')
return extension.main(args=args)

# Local Variables to reduce code length
iw, ep = (args.include_warnings, args.exclude_packages)
# `ros2 doctor -r`
if args.report:
all_reports = generate_reports()
all_reports = generate_reports(exclude_packages=ep)
for report_obj in all_reports:
format_print(report_obj)
return

# `ros2 doctor
fail_category, fail, total = run_checks(include_warnings=args.include_warnings)

fail_category, fail, total = run_checks(include_warnings=iw, exclude_packages=ep)
if fail:
print(f'\n{fail}/{total} check(s) failed\n')
print('Failed modules:', *fail_category)
Expand Down

0 comments on commit a3198b8

Please sign in to comment.