From a3198b80f8a993ac01501d8e3fbdd76e7aaf92dc Mon Sep 17 00:00:00 2001 From: Angel LoGa <98213868+AngeLoGa@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:05:06 +0100 Subject: [PATCH] New flag and code update for its use (#942) Signed-off-by: AngeLoGa --- ros2doctor/README.md | 3 +++ ros2doctor/ros2doctor/api/__init__.py | 12 ++++++++++-- ros2doctor/ros2doctor/command/doctor.py | 11 +++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ros2doctor/README.md b/ros2doctor/README.md index 9122612b0..71860365f 100644 --- a/ros2doctor/README.md +++ b/ros2doctor/README.md @@ -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`. diff --git a/ros2doctor/ros2doctor/api/__init__.py b/ros2doctor/ros2doctor/api/__init__.py index f90cdbced..2f29dd0fc 100644 --- a/ros2doctor/ros2doctor/api/__init__.py +++ b/ros2doctor/ros2doctor/api/__init__.py @@ -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. @@ -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() @@ -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. @@ -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() diff --git a/ros2doctor/ros2doctor/command/doctor.py b/ros2doctor/ros2doctor/command/doctor.py index e754c20d9..56f8b75c0 100644 --- a/ros2doctor/ros2doctor/command/doctor.py +++ b/ros2doctor/ros2doctor/command/doctor.py @@ -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.' @@ -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)