From c283467009b14d22fdeb466a160b7d4db7fa0c4d Mon Sep 17 00:00:00 2001 From: claireyywang Date: Tue, 28 Jan 2020 15:10:04 -0800 Subject: [PATCH 1/7] update doctor warn Signed-off-by: claireyywang --- ros2doctor/ros2doctor/api/__init__.py | 12 ++++++------ ros2doctor/ros2doctor/api/platform.py | 10 +++++----- ros2doctor/ros2doctor/api/topic.py | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ros2doctor/ros2doctor/api/__init__.py b/ros2doctor/ros2doctor/api/__init__.py index abb4da992..d5ddab64e 100644 --- a/ros2doctor/ros2doctor/api/__init__.py +++ b/ros2doctor/ros2doctor/api/__init__.py @@ -94,11 +94,11 @@ def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]: try: check_class = check_entry_pt.load() except (ImportError, UnknownExtra): - doctor_warn('Check entry point %s fails to load.' % check_entry_pt.name) + doctor_warn(f'Check entry point {check_entry_pt.name} fails to load.') try: check_instance = check_class() except Exception: - doctor_warn('Unable to instantiate check object from %s.' % check_entry_pt.name) + doctor_warn(f'Unable to instantiate check object from {check_entry_pt.name}.') try: check_category = check_instance.category() result = check_instance.check() @@ -107,7 +107,7 @@ def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]: failed_cats.add(check_category) total += 1 except Exception: - doctor_warn('Fail to call %s class functions.' % check_entry_pt.name) + doctor_warn(f'Fail to call {check_entry_pt.name} class functions.') return failed_cats, fail, total @@ -122,11 +122,11 @@ def generate_reports(*, categories=None) -> List[Report]: try: report_class = report_entry_pt.load() except (ImportError, UnknownExtra): - doctor_warn('Report entry point %s fails to load.' % report_entry_pt.name) + doctor_warn(f'Report entry point {report_entry_pt.name} fails to load.') try: report_instance = report_class() except Exception: - doctor_warn('Unable to instantiate report object from %s.' % report_entry_pt.name) + doctor_warn(f'Unable to instantiate report object from {report_entry_pt.name}.') try: report_category = report_instance.category() report = report_instance.report() @@ -136,5 +136,5 @@ def generate_reports(*, categories=None) -> List[Report]: else: reports.append(report) except Exception: - doctor_warn('Fail to call %s class functions.' % report_entry_pt.name) + doctor_warn(f'Fail to call {report_entry_pt.name} class functions.') return reports diff --git a/ros2doctor/ros2doctor/api/platform.py b/ros2doctor/ros2doctor/api/platform.py index cee6ea35c..02d2c3634 100644 --- a/ros2doctor/ros2doctor/api/platform.py +++ b/ros2doctor/ros2doctor/api/platform.py @@ -44,7 +44,7 @@ def _check_platform_helper() -> Tuple[str, dict, dict]: i = rosdistro.get_index(u) distro_info = i.distributions.get(distro_name) if not distro_info: - doctor_warn("Distribution name '%s' is not found" % distro_name) + doctor_warn(f"Distribution name {distro_name} is not found") return distro_data = rosdistro.get_distribution(i, distro_name).get_data() return distro_name, distro_info, distro_data @@ -67,13 +67,13 @@ def check(self): # check distro status if distro_info.get('distribution_status') == 'prerelease': - result.add_warning('Distribution %s is not fully supported or tested. ' + result.add_warning(f'Distribution {distro_name} is not fully supported or tested. ' 'To get more consistent features, download a stable version at ' - 'https://index.ros.org/doc/ros2/Installation/' % distro_name) + 'https://index.ros.org/doc/ros2/Installation/') elif distro_info.get('distribution_status') == 'end-of-life': - result.add_warning('Distribution %s is no longer supported or deprecated. ' + result.add_warning(f'Distribution {distro_name} is no longer supported or deprecated. ' 'To get the latest features, download the new versions at ' - 'https://index.ros.org/doc/ros2/Installation/' % distro_name) + 'https://index.ros.org/doc/ros2/Installation/') return result diff --git a/ros2doctor/ros2doctor/api/topic.py b/ros2doctor/ros2doctor/api/topic.py index ccc2255d6..bf899e4af 100644 --- a/ros2doctor/ros2doctor/api/topic.py +++ b/ros2doctor/ros2doctor/api/topic.py @@ -49,9 +49,9 @@ def check(self): pub_count = node.count_publishers(topic) sub_count = node.count_subscribers(topic) if pub_count > sub_count: - result.add_warning('Publisher without subscriber detected on %s.' % topic) + result.add_warning(f'Publisher without subscriber detected on {topic}.') elif pub_count < sub_count: - result.add_warning('Subscriber without publisher detected on %s.' % topic) + result.add_warning(f'Subscriber without publisher detected on {topic}.') return result From cfb719719fac368a4bef4c82da23f39cbec17c35 Mon Sep 17 00:00:00 2001 From: claireyywang Date: Wed, 29 Jan 2020 16:32:50 -0800 Subject: [PATCH 2/7] decouple warning/error msg from result to show traceback Signed-off-by: claireyywang --- ros2doctor/ros2doctor/api/__init__.py | 18 ++++--- ros2doctor/ros2doctor/api/format.py | 35 ++++---------- ros2doctor/ros2doctor/api/network.py | 26 +++++++---- ros2doctor/ros2doctor/api/package.py | 62 +++++++++++++++++-------- ros2doctor/ros2doctor/api/platform.py | 27 ++++++----- ros2doctor/ros2doctor/api/topic.py | 8 ++-- ros2doctor/ros2doctor/command/doctor.py | 10 ++-- 7 files changed, 101 insertions(+), 85 deletions(-) diff --git a/ros2doctor/ros2doctor/api/__init__.py b/ros2doctor/ros2doctor/api/__init__.py index d5ddab64e..47b07de1d 100644 --- a/ros2doctor/ros2doctor/api/__init__.py +++ b/ros2doctor/ros2doctor/api/__init__.py @@ -71,12 +71,10 @@ def __init__(self): self.error = 0 self.warning = 0 - def add_error(self, msg) -> None: - doctor_warn(msg) + def add_error(self) -> None: self.error += 1 - def add_warning(self, msg) -> None: - doctor_warn(msg) + def add_warning(self) -> None: self.warning += 1 @@ -94,11 +92,11 @@ def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]: try: check_class = check_entry_pt.load() except (ImportError, UnknownExtra): - doctor_warn(f'Check entry point {check_entry_pt.name} fails to load.') + doctor_warn()(f'Check entry point {check_entry_pt.name} fails to load.', RuntimeWarning) try: check_instance = check_class() except Exception: - doctor_warn(f'Unable to instantiate check object from {check_entry_pt.name}.') + doctor_warn()(f'Unable to instantiate check object from {check_entry_pt.name}.', RuntimeWarning) try: check_category = check_instance.category() result = check_instance.check() @@ -107,7 +105,7 @@ def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]: failed_cats.add(check_category) total += 1 except Exception: - doctor_warn(f'Fail to call {check_entry_pt.name} class functions.') + doctor_warn()(f'Fail to call {check_entry_pt.name} class functions.', RuntimeWarning) return failed_cats, fail, total @@ -122,11 +120,11 @@ def generate_reports(*, categories=None) -> List[Report]: try: report_class = report_entry_pt.load() except (ImportError, UnknownExtra): - doctor_warn(f'Report entry point {report_entry_pt.name} fails to load.') + doctor_warn()(f'Report entry point {report_entry_pt.name} fails to load.', RuntimeWarning) try: report_instance = report_class() except Exception: - doctor_warn(f'Unable to instantiate report object from {report_entry_pt.name}.') + doctor_warn()(f'Unable to instantiate report object from {report_entry_pt.name}.', RuntimeWarning) try: report_category = report_instance.category() report = report_instance.report() @@ -136,5 +134,5 @@ def generate_reports(*, categories=None) -> List[Report]: else: reports.append(report) except Exception: - doctor_warn(f'Fail to call {report_entry_pt.name} class functions.') + doctor_warn()(f'Fail to call {report_entry_pt.name} class functions.', RuntimeWarning) return reports diff --git a/ros2doctor/ros2doctor/api/format.py b/ros2doctor/ros2doctor/api/format.py index dbf984e65..67abd846c 100644 --- a/ros2doctor/ros2doctor/api/format.py +++ b/ros2doctor/ros2doctor/api/format.py @@ -24,7 +24,8 @@ def format_print(report): :param report: Report object with name and items list """ print('\n ', report.name) - padding_num = compute_padding(report.items) + if report.items: + padding_num = compute_padding(report.items) for item_name, item_content in report.items: print('{:{padding}}: {}'.format(item_name, item_content, padding=padding_num)) @@ -44,33 +45,13 @@ def compute_padding(report_items: List[Tuple[str, str]]) -> int: return padding -def custom_warning_format(msg, cat, filename, linenum, file=None, line=None): - return '%s: %s: %s: %s\n' % (filename, linenum, cat.__name__, msg) - - -class CustomWarningFormat: - """Support custom warning format without modifying default format.""" - - def __enter__(self): - self._default_format = warnings.formatwarning - warnings.formatwarning = custom_warning_format - - def __exit__(self, t, v, trb): - """ - Define exit action for context manager. - - :param t: type - :param v: value - :param trb: traceback - """ - warnings.formatwarning = self._default_format - - -def doctor_warn(msg: str) -> None: +def doctor_warn() -> None: """ - Use CustomWarningFormat to print customized warning message. + Print customized warning message with package and line info. :param msg: warning message to be printed """ - with CustomWarningFormat(): - warnings.warn(msg) + def custom_warning_format(message, category, filename, lineno, file=None, line=None): + return '%s:%s: %s: %s\n' % (filename, lineno, category.__name__, message) + warnings.formatwarning = custom_warning_format + return warnings.warn diff --git a/ros2doctor/ros2doctor/api/network.py b/ros2doctor/ros2doctor/api/network.py index 8c02d117b..c38a5fe6d 100644 --- a/ros2doctor/ros2doctor/api/network.py +++ b/ros2doctor/ros2doctor/api/network.py @@ -14,6 +14,7 @@ import os from typing import Tuple +import warnings from ros2doctor.api import DoctorCheck from ros2doctor.api import DoctorReport @@ -24,8 +25,8 @@ try: import ifcfg except ImportError: # check import error for windows and osx - doctor_warn('Failed to import ifcfg. ' - 'Use `python -m pip install ifcfg` to install needed package.') + doctor_warn()('Unable to import ifcfg. ' + 'Use `python -m pip install ifcfg` to install needed package.') def _is_unix_like_platform() -> bool: @@ -62,22 +63,29 @@ def check(self): try: ifcfg_ifaces = ifcfg.interfaces() except NameError: - result.add_error('ERROR: ifcfg is not imported. Unable to run network check.') + doctor_warn()('ERROR: `ifcfg` module is not imported. ' + 'Unable to run network check.') + result.add_error() return result has_loopback, has_non_loopback, has_multicast = _check_network_config_helper(ifcfg_ifaces) if not _is_unix_like_platform(): if not has_loopback and not has_non_loopback: # no flags found, otherwise one of them should be True. - print('No flags found. \ - Run `ipconfig` on cmd to check network interfaces.') + doctor_warn()('ERROR: No flags found. ' + 'Run `ipconfig` on Windows or ' + 'install `ifconfig` on Unix to check network interfaces.') + result.add_error() return result if not has_loopback: - result.add_error('ERROR: No loopback IP address is found.') + doctor_warn()('ERROR: No loopback IP address is found.') + result.add_error() if not has_non_loopback: - result.add_warning('Only loopback IP address is found.') + doctor_warn()('Only loopback IP address is found.') + result.add_warning() if not has_multicast: - result.add_warning('No multicast IP address is found.') + doctor_warn()('No multicast IP address is found.') + result.add_warning() return result @@ -93,7 +101,7 @@ def report(self): try: ifcfg_ifaces = ifcfg.interfaces() except NameError: - doctor_warn('ifcfg is not imported. Unable to generate network report.') + doctor_warn()('ERROR: ifcfg is not imported. Unable to generate network report.') return Report('') network_report = Report('NETWORK CONFIGURATION') diff --git a/ros2doctor/ros2doctor/api/package.py b/ros2doctor/ros2doctor/api/package.py index c0c5641dc..a48a29a17 100644 --- a/ros2doctor/ros2doctor/api/package.py +++ b/ros2doctor/ros2doctor/api/package.py @@ -14,6 +14,7 @@ import os from typing import List +import textwrap from urllib.error import URLError from ament_index_python import get_packages_with_prefixes @@ -24,6 +25,7 @@ from ros2doctor.api import DoctorReport from ros2doctor.api import Report from ros2doctor.api import Result +from ros2doctor.api.format import doctor_warn import rosdistro @@ -35,11 +37,25 @@ def get_distro_package_versions() -> dict: :return: dictionary of rosdistro package name and version """ distro_name = os.environ.get('ROS_DISTRO') + if not distro_name: + doctor_warn()('ERROR: ROS_DISTRO is not set.') + return distro_name = distro_name.lower() url = rosdistro.get_index_url() + if not url: + doctor_warn()('ERROR: Unable to access ROSDISTRO_INDEX_URL or DEFAULT_INDEX_URL. ' + 'Check network setting to make sure machine is connected to internet.') + return i = rosdistro.get_index(url) - distro_data = rosdistro.get_distribution(i, distro_name).get_data() + distro_info = rosdistro.get_distribution(i, distro_name) + if not distro_info: + doctor_warn()(f'Distribution name {distro_name} is not found') + return + distro_data = distro_info.get_data() repos_info = distro_data.get('repositories') + if not repos_info: + doctor_warn()('No repository information found.') + return distro_package_vers = {} for _, info in repos_info.items(): try: @@ -69,7 +85,7 @@ def get_local_package_versions() -> dict: return local_packages -def compare_versions(local_packages: dict, distro_packages: dict) -> List: +def compare_versions(result: Result, local_packages: dict, distro_packages: dict): """ Return warning messages for PackageCheck, and info for PackageReport. @@ -78,7 +94,6 @@ def compare_versions(local_packages: dict, distro_packages: dict) -> List: :param: boolean value determines which output to populate, msgs or report :return: list of warning messages """ - warning_msgs = [] missing_req = '' missing_local = '' for name, local_ver_str in local_packages.items(): @@ -91,14 +106,26 @@ def compare_versions(local_packages: dict, distro_packages: dict) -> List: local_ver = version.parse(local_ver_str).base_version required_ver = version.parse(required_ver_str).base_version if local_ver < required_ver: - warning_msgs.append(f'{name} has been updated to a new version.' - f' local: {local_ver} <' - f' required: {required_ver}') + doctor_warn()(f'{name} has been updated to a new version.' + f' local: {local_ver} <' + f' required: {required_ver}') + result.add_warning() if missing_req: - warning_msgs.append('Cannot find required versions of packages:' + missing_req) + if len(missing_req) > 100: + doctor_warn()('Cannot find required versions of packages: ' + + textwrap.shorten(missing_req, width=100) + + ' Use `ros2 doctor --report` to see full list.') + else: + doctor_warn()('Cannot find required versions of packages: ' + + missing_req) if missing_local: - warning_msgs.append('Cannot find local versions of packages:' + missing_local) - return warning_msgs + if len(missing_local) > 100: + doctor_warn()('Cannot find local versions of packages: ' + + textwrap.shorten(missing_local, width=100) + + ' Use `ros2 doctor --report` to see full list.') + else: + doctor_warn()('Cannot find local versions of packages: ' + + missing_local) class PackageCheck(DoctorCheck): @@ -110,21 +137,18 @@ def category(self): def check(self): """Check packages within the directory where command is called.""" result = Result() - try: - distro_package_vers = get_distro_package_versions() - if not distro_package_vers: - result.add_error('ERROR: distro packages info is not found.') - except (AttributeError, RuntimeError, URLError): - result.add_error('ERROR: Unable to fetch package information from rosdistro.') + distro_package_vers = get_distro_package_versions() + if not distro_package_vers: + doctor_warn()('ERROR: distro packages info is not found.') + result.add_error() local_package_vers = get_local_package_versions() if not local_package_vers: - result.add_error('ERROR: local package info is not found.') + doctor_warn()('ERROR: local package info is not found.') + result.add_error() if result.error != 0: return result - warning_msgs = compare_versions(local_package_vers, distro_package_vers) - for msg in warning_msgs: - result.add_warning(msg) + compare_versions(result, local_package_vers, distro_package_vers) return result diff --git a/ros2doctor/ros2doctor/api/platform.py b/ros2doctor/ros2doctor/api/platform.py index 02d2c3634..4d50828c1 100644 --- a/ros2doctor/ros2doctor/api/platform.py +++ b/ros2doctor/ros2doctor/api/platform.py @@ -33,18 +33,18 @@ def _check_platform_helper() -> Tuple[str, dict, dict]: """ distro_name = os.environ.get('ROS_DISTRO') if not distro_name: - doctor_warn('ROS_DISTRO is not set.') + doctor_warn()('ERROR: ROS_DISTRO is not set.') return - else: - distro_name = distro_name.lower() + distro_name = distro_name.lower() u = rosdistro.get_index_url() if not u: - doctor_warn('Unable to access ROSDISTRO_INDEX_URL or DEFAULT_INDEX_URL.') + doctor_warn()('ERROR: Unable to access ROSDISTRO_INDEX_URL or DEFAULT_INDEX_URL. ' + 'Check network setting to make sure machine is connected to internet.') return i = rosdistro.get_index(u) distro_info = i.distributions.get(distro_name) if not distro_info: - doctor_warn(f"Distribution name {distro_name} is not found") + doctor_warn()(f'Distribution name {distro_name} is not found') return distro_data = rosdistro.get_distribution(i, distro_name).get_data() return distro_name, distro_info, distro_data @@ -61,19 +61,22 @@ def check(self): result = Result() distros = _check_platform_helper() if not distros: - result.add_error('ERROR: Missing rosdistro info. Unable to check platform.') + doctor_warn()('ERROR: Missing rosdistro info. Unable to check platform.') + result.add_error() return result distro_name, distro_info, _ = distros # check distro status if distro_info.get('distribution_status') == 'prerelease': - result.add_warning(f'Distribution {distro_name} is not fully supported or tested. ' - 'To get more consistent features, download a stable version at ' - 'https://index.ros.org/doc/ros2/Installation/') + doctor_warn()(f'Distribution {distro_name} is not fully supported or tested. ' + 'To get more consistent features, download a stable version at ' + 'https://index.ros.org/doc/ros2/Installation/') + result.add_warning() elif distro_info.get('distribution_status') == 'end-of-life': - result.add_warning(f'Distribution {distro_name} is no longer supported or deprecated. ' - 'To get the latest features, download the new versions at ' - 'https://index.ros.org/doc/ros2/Installation/') + doctor_warn()(f'Distribution {distro_name} is no longer supported or deprecated. ' + 'To get the latest features, download the new versions at ' + 'https://index.ros.org/doc/ros2/Installation/') + result.add_warning() return result diff --git a/ros2doctor/ros2doctor/api/topic.py b/ros2doctor/ros2doctor/api/topic.py index bf899e4af..c0de9ce83 100644 --- a/ros2doctor/ros2doctor/api/topic.py +++ b/ros2doctor/ros2doctor/api/topic.py @@ -20,7 +20,7 @@ from ros2doctor.api import DoctorReport from ros2doctor.api import Report from ros2doctor.api import Result - +from ros2doctor.api.format import doctor_warn def _get_topic_names() -> List: """Get all topic names using rclpy API.""" @@ -49,9 +49,11 @@ def check(self): pub_count = node.count_publishers(topic) sub_count = node.count_subscribers(topic) if pub_count > sub_count: - result.add_warning(f'Publisher without subscriber detected on {topic}.') + doctor_warn()(f'Publisher without subscriber detected on {topic}.') + result.add_warning() elif pub_count < sub_count: - result.add_warning(f'Subscriber without publisher detected on {topic}.') + doctor_warn()(f'Subscriber without publisher detected on {topic}.') + result.add_warning() return result diff --git a/ros2doctor/ros2doctor/command/doctor.py b/ros2doctor/ros2doctor/command/doctor.py index 6d8df274b..6a4c7a396 100644 --- a/ros2doctor/ros2doctor/command/doctor.py +++ b/ros2doctor/ros2doctor/command/doctor.py @@ -46,16 +46,16 @@ def main(self, *, parser, args): return # `ros2 doctor - failed_cats, fail, total = run_checks(include_warnings=args.include_warnings) + fail_category, fail, total = run_checks(include_warnings=args.include_warnings) if fail: - print('\n%d/%d checks failed\n' % (fail, total)) - print('Failed modules:', *failed_cats) + print(f'\n{fail}/{total} check(s) failed\n') + print('Failed modules:', *fail_category) else: - print('\nAll %d checks passed\n' % total) + print(f'\nAll {total} checks passed\n') # `ros2 doctor -rf` if args.report_failed and fail != 0: - fail_reports = generate_reports(categories=failed_cats) + fail_reports = generate_reports(categories=fail_category) for report_obj in fail_reports: format_print(report_obj) From 3f090084fef0ad51ccdc757b1bba2b1b5d97e0a8 Mon Sep 17 00:00:00 2001 From: claireyywang Date: Wed, 29 Jan 2020 16:56:26 -0800 Subject: [PATCH 3/7] update print statements Signed-off-by: claireyywang --- ros2doctor/ros2doctor/api/__init__.py | 18 +++++++++--------- ros2doctor/ros2doctor/api/format.py | 4 ++-- ros2doctor/ros2doctor/api/network.py | 3 +-- ros2doctor/ros2doctor/api/package.py | 11 ++++------- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/ros2doctor/ros2doctor/api/__init__.py b/ros2doctor/ros2doctor/api/__init__.py index 47b07de1d..3c7e5e0ea 100644 --- a/ros2doctor/ros2doctor/api/__init__.py +++ b/ros2doctor/ros2doctor/api/__init__.py @@ -85,28 +85,28 @@ def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]: :return: 3-tuple (categories of failed checks, number of failed checks, total number of checks) """ - failed_cats = set() # remove repeating elements + fail_categories = set() # remove repeating elements fail = 0 total = 0 for check_entry_pt in iter_entry_points('ros2doctor.checks'): try: check_class = check_entry_pt.load() except (ImportError, UnknownExtra): - doctor_warn()(f'Check entry point {check_entry_pt.name} fails to load.', RuntimeWarning) + doctor_warn()(f'Check entry point {check_entry_pt.name} fails to load.') try: check_instance = check_class() except Exception: - doctor_warn()(f'Unable to instantiate check object from {check_entry_pt.name}.', RuntimeWarning) + doctor_warn()(f'Unable to instantiate check object from {check_entry_pt.name}.') try: check_category = check_instance.category() result = check_instance.check() if result.error or (include_warnings and result.warning): fail += 1 - failed_cats.add(check_category) + fail_categories.add(check_category) total += 1 except Exception: - doctor_warn()(f'Fail to call {check_entry_pt.name} class functions.', RuntimeWarning) - return failed_cats, fail, total + doctor_warn()(f'Fail to call {check_entry_pt.name} class functions.') + return fail_categories, fail, total def generate_reports(*, categories=None) -> List[Report]: @@ -120,11 +120,11 @@ def generate_reports(*, categories=None) -> List[Report]: try: report_class = report_entry_pt.load() except (ImportError, UnknownExtra): - doctor_warn()(f'Report entry point {report_entry_pt.name} fails to load.', RuntimeWarning) + doctor_warn()(f'Report entry point {report_entry_pt.name} fails to load.') try: report_instance = report_class() except Exception: - doctor_warn()(f'Unable to instantiate report object from {report_entry_pt.name}.', RuntimeWarning) + doctor_warn()(f'Unable to instantiate report object from {report_entry_pt.name}.') try: report_category = report_instance.category() report = report_instance.report() @@ -134,5 +134,5 @@ def generate_reports(*, categories=None) -> List[Report]: else: reports.append(report) except Exception: - doctor_warn()(f'Fail to call {report_entry_pt.name} class functions.', RuntimeWarning) + doctor_warn()(f'Fail to call {report_entry_pt.name} class functions.') return reports diff --git a/ros2doctor/ros2doctor/api/format.py b/ros2doctor/ros2doctor/api/format.py index 67abd846c..b33a07606 100644 --- a/ros2doctor/ros2doctor/api/format.py +++ b/ros2doctor/ros2doctor/api/format.py @@ -23,7 +23,7 @@ def format_print(report): :param report: Report object with name and items list """ - print('\n ', report.name) + print('\n ', report.name) if report.items: padding_num = compute_padding(report.items) for item_name, item_content in report.items: @@ -52,6 +52,6 @@ def doctor_warn() -> None: :param msg: warning message to be printed """ def custom_warning_format(message, category, filename, lineno, file=None, line=None): - return '%s:%s: %s: %s\n' % (filename, lineno, category.__name__, message) + return f'{filename}:{lineno}: {category.__name__}: {message}\n' warnings.formatwarning = custom_warning_format return warnings.warn diff --git a/ros2doctor/ros2doctor/api/network.py b/ros2doctor/ros2doctor/api/network.py index c38a5fe6d..93f6626a5 100644 --- a/ros2doctor/ros2doctor/api/network.py +++ b/ros2doctor/ros2doctor/api/network.py @@ -14,7 +14,6 @@ import os from typing import Tuple -import warnings from ros2doctor.api import DoctorCheck from ros2doctor.api import DoctorReport @@ -26,7 +25,7 @@ import ifcfg except ImportError: # check import error for windows and osx doctor_warn()('Unable to import ifcfg. ' - 'Use `python -m pip install ifcfg` to install needed package.') + 'Use `python3 -m pip install ifcfg` to install needed package.') def _is_unix_like_platform() -> bool: diff --git a/ros2doctor/ros2doctor/api/package.py b/ros2doctor/ros2doctor/api/package.py index a48a29a17..60874909f 100644 --- a/ros2doctor/ros2doctor/api/package.py +++ b/ros2doctor/ros2doctor/api/package.py @@ -51,9 +51,9 @@ def get_distro_package_versions() -> dict: if not distro_info: doctor_warn()(f'Distribution name {distro_name} is not found') return - distro_data = distro_info.get_data() - repos_info = distro_data.get('repositories') - if not repos_info: + try: + repos_info = distro_info.get_data().get('repositories') + except AttributeError: doctor_warn()('No repository information found.') return distro_package_vers = {} @@ -161,11 +161,8 @@ def category(self): def report(self): """Report packages within the directory where command is called.""" report = Report('PACKAGE VERSIONS') - try: - distro_package_vers = get_distro_package_versions() - except (AttributeError, RuntimeError, URLError): - return report local_package_vers = get_local_package_versions() + distro_package_vers = get_distro_package_versions() if not local_package_vers or not distro_package_vers: return report for name, local_ver_str in local_package_vers.items(): From 17e90bbbbd1e2992196d38f5629f3f150f3b278c Mon Sep 17 00:00:00 2001 From: claireyywang Date: Wed, 29 Jan 2020 17:02:39 -0800 Subject: [PATCH 4/7] remove None return and add error catching Signed-off-by: claireyywang --- ros2doctor/ros2doctor/api/__init__.py | 6 +++--- ros2doctor/ros2doctor/api/format.py | 3 ++- ros2doctor/ros2doctor/api/platform.py | 5 ++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ros2doctor/ros2doctor/api/__init__.py b/ros2doctor/ros2doctor/api/__init__.py index 3c7e5e0ea..de025d915 100644 --- a/ros2doctor/ros2doctor/api/__init__.py +++ b/ros2doctor/ros2doctor/api/__init__.py @@ -56,7 +56,7 @@ def __init__(self, name: str): self.name = name self.items = [] - def add_to_report(self, item_name: str, item_info: str) -> None: + def add_to_report(self, item_name: str, item_info: str): """Add report content to items list (list of string tuples).""" self.items.append((item_name, item_info)) @@ -71,10 +71,10 @@ def __init__(self): self.error = 0 self.warning = 0 - def add_error(self) -> None: + def add_error(self): self.error += 1 - def add_warning(self) -> None: + def add_warning(self): self.warning += 1 diff --git a/ros2doctor/ros2doctor/api/format.py b/ros2doctor/ros2doctor/api/format.py index b33a07606..f7b5ef718 100644 --- a/ros2doctor/ros2doctor/api/format.py +++ b/ros2doctor/ros2doctor/api/format.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from typing import Callable from typing import List from typing import Tuple import warnings @@ -45,7 +46,7 @@ def compute_padding(report_items: List[Tuple[str, str]]) -> int: return padding -def doctor_warn() -> None: +def doctor_warn() -> Callable: """ Print customized warning message with package and line info. diff --git a/ros2doctor/ros2doctor/api/platform.py b/ros2doctor/ros2doctor/api/platform.py index 4d50828c1..566a8aa74 100644 --- a/ros2doctor/ros2doctor/api/platform.py +++ b/ros2doctor/ros2doctor/api/platform.py @@ -46,7 +46,10 @@ def _check_platform_helper() -> Tuple[str, dict, dict]: if not distro_info: doctor_warn()(f'Distribution name {distro_name} is not found') return - distro_data = rosdistro.get_distribution(i, distro_name).get_data() + try: + distro_data = rosdistro.get_distribution(i, distro_name).get_data() + except AttributeError: + distro_data = '' return distro_name, distro_info, distro_data From d8af88b08c9769e6468da11c741f803e47133774 Mon Sep 17 00:00:00 2001 From: claireyywang Date: Wed, 29 Jan 2020 17:11:47 -0800 Subject: [PATCH 5/7] update to hanging indentation Signed-off-by: claireyywang --- ros2doctor/ros2doctor/api/network.py | 9 ++++++--- ros2doctor/ros2doctor/api/package.py | 20 ++++++++++++-------- ros2doctor/ros2doctor/api/platform.py | 9 ++++++--- ros2doctor/ros2doctor/api/topic.py | 1 + 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/ros2doctor/ros2doctor/api/network.py b/ros2doctor/ros2doctor/api/network.py index 93f6626a5..c84a800fb 100644 --- a/ros2doctor/ros2doctor/api/network.py +++ b/ros2doctor/ros2doctor/api/network.py @@ -24,7 +24,8 @@ try: import ifcfg except ImportError: # check import error for windows and osx - doctor_warn()('Unable to import ifcfg. ' + doctor_warn()( + 'Unable to import ifcfg. ' 'Use `python3 -m pip install ifcfg` to install needed package.') @@ -62,7 +63,8 @@ def check(self): try: ifcfg_ifaces = ifcfg.interfaces() except NameError: - doctor_warn()('ERROR: `ifcfg` module is not imported. ' + doctor_warn()( + 'ERROR: `ifcfg` module is not imported. ' 'Unable to run network check.') result.add_error() return result @@ -71,7 +73,8 @@ def check(self): if not _is_unix_like_platform(): if not has_loopback and not has_non_loopback: # no flags found, otherwise one of them should be True. - doctor_warn()('ERROR: No flags found. ' + doctor_warn()( + 'ERROR: No flags found. ' 'Run `ipconfig` on Windows or ' 'install `ifconfig` on Unix to check network interfaces.') result.add_error() diff --git a/ros2doctor/ros2doctor/api/package.py b/ros2doctor/ros2doctor/api/package.py index 60874909f..a5857a060 100644 --- a/ros2doctor/ros2doctor/api/package.py +++ b/ros2doctor/ros2doctor/api/package.py @@ -13,9 +13,7 @@ # limitations under the License. import os -from typing import List import textwrap -from urllib.error import URLError from ament_index_python import get_packages_with_prefixes from catkin_pkg.package import parse_package @@ -43,7 +41,8 @@ def get_distro_package_versions() -> dict: distro_name = distro_name.lower() url = rosdistro.get_index_url() if not url: - doctor_warn()('ERROR: Unable to access ROSDISTRO_INDEX_URL or DEFAULT_INDEX_URL. ' + doctor_warn()( + 'ERROR: Unable to access ROSDISTRO_INDEX_URL or DEFAULT_INDEX_URL. ' 'Check network setting to make sure machine is connected to internet.') return i = rosdistro.get_index(url) @@ -106,25 +105,30 @@ def compare_versions(result: Result, local_packages: dict, distro_packages: dict local_ver = version.parse(local_ver_str).base_version required_ver = version.parse(required_ver_str).base_version if local_ver < required_ver: - doctor_warn()(f'{name} has been updated to a new version.' + doctor_warn()( + f'{name} has been updated to a new version.' f' local: {local_ver} <' f' required: {required_ver}') result.add_warning() if missing_req: if len(missing_req) > 100: - doctor_warn()('Cannot find required versions of packages: ' + + doctor_warn()( + 'Cannot find required versions of packages: ' + textwrap.shorten(missing_req, width=100) + ' Use `ros2 doctor --report` to see full list.') else: - doctor_warn()('Cannot find required versions of packages: ' + + doctor_warn()( + 'Cannot find required versions of packages: ' + missing_req) if missing_local: if len(missing_local) > 100: - doctor_warn()('Cannot find local versions of packages: ' + + doctor_warn()( + 'Cannot find local versions of packages: ' + textwrap.shorten(missing_local, width=100) + ' Use `ros2 doctor --report` to see full list.') else: - doctor_warn()('Cannot find local versions of packages: ' + + doctor_warn()( + 'Cannot find local versions of packages: ' + missing_local) diff --git a/ros2doctor/ros2doctor/api/platform.py b/ros2doctor/ros2doctor/api/platform.py index 566a8aa74..3a90ce43c 100644 --- a/ros2doctor/ros2doctor/api/platform.py +++ b/ros2doctor/ros2doctor/api/platform.py @@ -38,7 +38,8 @@ def _check_platform_helper() -> Tuple[str, dict, dict]: distro_name = distro_name.lower() u = rosdistro.get_index_url() if not u: - doctor_warn()('ERROR: Unable to access ROSDISTRO_INDEX_URL or DEFAULT_INDEX_URL. ' + doctor_warn()( + 'ERROR: Unable to access ROSDISTRO_INDEX_URL or DEFAULT_INDEX_URL. ' 'Check network setting to make sure machine is connected to internet.') return i = rosdistro.get_index(u) @@ -71,12 +72,14 @@ def check(self): # check distro status if distro_info.get('distribution_status') == 'prerelease': - doctor_warn()(f'Distribution {distro_name} is not fully supported or tested. ' + doctor_warn()( + f'Distribution {distro_name} is not fully supported or tested. ' 'To get more consistent features, download a stable version at ' 'https://index.ros.org/doc/ros2/Installation/') result.add_warning() elif distro_info.get('distribution_status') == 'end-of-life': - doctor_warn()(f'Distribution {distro_name} is no longer supported or deprecated. ' + doctor_warn()( + f'Distribution {distro_name} is no longer supported or deprecated. ' 'To get the latest features, download the new versions at ' 'https://index.ros.org/doc/ros2/Installation/') result.add_warning() diff --git a/ros2doctor/ros2doctor/api/topic.py b/ros2doctor/ros2doctor/api/topic.py index c0de9ce83..b376df7fb 100644 --- a/ros2doctor/ros2doctor/api/topic.py +++ b/ros2doctor/ros2doctor/api/topic.py @@ -22,6 +22,7 @@ from ros2doctor.api import Result from ros2doctor.api.format import doctor_warn + def _get_topic_names() -> List: """Get all topic names using rclpy API.""" white_list = ['/parameter_events', '/rosout'] From 61657e31580bce1ab85330eeced4b918905d01ba Mon Sep 17 00:00:00 2001 From: claireyywang Date: Mon, 3 Feb 2020 17:13:07 -0800 Subject: [PATCH 6/7] specify stacklevel; add doctor_error Signed-off-by: claireyywang --- ros2doctor/ros2doctor/api/__init__.py | 14 +++++----- ros2doctor/ros2doctor/api/format.py | 40 +++++++++++++++++++++++---- ros2doctor/ros2doctor/api/network.py | 19 +++++++------ ros2doctor/ros2doctor/api/package.py | 25 +++++++++-------- ros2doctor/ros2doctor/api/platform.py | 15 +++++----- ros2doctor/ros2doctor/api/topic.py | 4 +-- 6 files changed, 75 insertions(+), 42 deletions(-) diff --git a/ros2doctor/ros2doctor/api/__init__.py b/ros2doctor/ros2doctor/api/__init__.py index de025d915..1ff2ebe0a 100644 --- a/ros2doctor/ros2doctor/api/__init__.py +++ b/ros2doctor/ros2doctor/api/__init__.py @@ -56,7 +56,7 @@ def __init__(self, name: str): self.name = name self.items = [] - def add_to_report(self, item_name: str, item_info: str): + def add_to_report(self, item_name: str, item_info: str) -> None: """Add report content to items list (list of string tuples).""" self.items.append((item_name, item_info)) @@ -92,11 +92,11 @@ def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]: try: check_class = check_entry_pt.load() except (ImportError, UnknownExtra): - doctor_warn()(f'Check entry point {check_entry_pt.name} fails to load.') + doctor_warn(f'Check entry point {check_entry_pt.name} fails to load.') try: check_instance = check_class() except Exception: - doctor_warn()(f'Unable to instantiate check object from {check_entry_pt.name}.') + doctor_warn(f'Unable to instantiate check object from {check_entry_pt.name}.') try: check_category = check_instance.category() result = check_instance.check() @@ -105,7 +105,7 @@ def run_checks(*, include_warnings=False) -> Tuple[Set[str], int, int]: fail_categories.add(check_category) total += 1 except Exception: - doctor_warn()(f'Fail to call {check_entry_pt.name} class functions.') + doctor_warn(f'Fail to call {check_entry_pt.name} class functions.') return fail_categories, fail, total @@ -120,11 +120,11 @@ def generate_reports(*, categories=None) -> List[Report]: try: report_class = report_entry_pt.load() except (ImportError, UnknownExtra): - doctor_warn()(f'Report entry point {report_entry_pt.name} fails to load.') + doctor_warn(f'Report entry point {report_entry_pt.name} fails to load.') try: report_instance = report_class() except Exception: - doctor_warn()(f'Unable to instantiate report object from {report_entry_pt.name}.') + doctor_warn(f'Unable to instantiate report object from {report_entry_pt.name}.') try: report_category = report_instance.category() report = report_instance.report() @@ -134,5 +134,5 @@ def generate_reports(*, categories=None) -> List[Report]: else: reports.append(report) except Exception: - doctor_warn()(f'Fail to call {report_entry_pt.name} class functions.') + doctor_warn(f'Fail to call {report_entry_pt.name} class functions.') return reports diff --git a/ros2doctor/ros2doctor/api/format.py b/ros2doctor/ros2doctor/api/format.py index f7b5ef718..f172e6bc4 100644 --- a/ros2doctor/ros2doctor/api/format.py +++ b/ros2doctor/ros2doctor/api/format.py @@ -46,13 +46,43 @@ def compute_padding(report_items: List[Tuple[str, str]]) -> int: return padding -def doctor_warn() -> Callable: + +def custom_warning_format(msg, cat, filename, linenum, file=None, line=None): + return '%s: %s: %s: %s\n' % (filename, linenum, cat.__name__, msg) + + +class CustomWarningFormat: + """Support custom warning format without modifying default format.""" + + def __enter__(self): + self._default_format = warnings.formatwarning + warnings.formatwarning = custom_warning_format + + def __exit__(self, t, v, trb): + """ + Define exit action for context manager. + :param t: type + :param v: value + :param trb: traceback + """ + warnings.formatwarning = self._default_format + + +def doctor_warn(msg: str) -> None: """ Print customized warning message with package and line info. :param msg: warning message to be printed """ - def custom_warning_format(message, category, filename, lineno, file=None, line=None): - return f'{filename}:{lineno}: {category.__name__}: {message}\n' - warnings.formatwarning = custom_warning_format - return warnings.warn + with CustomWarningFormat(): + warnings.warn(msg, stacklevel=2) + + +def doctor_error(msg: str) -> None: + """ + Print customized error message with package and line info. + + :param msg: error message to be printed + """ + with CustomWarningFormat(): + warnings.warn(f'ERROR: {msg}', stacklevel=2) \ No newline at end of file diff --git a/ros2doctor/ros2doctor/api/network.py b/ros2doctor/ros2doctor/api/network.py index c84a800fb..00f82d546 100644 --- a/ros2doctor/ros2doctor/api/network.py +++ b/ros2doctor/ros2doctor/api/network.py @@ -20,11 +20,12 @@ from ros2doctor.api import Report from ros2doctor.api import Result from ros2doctor.api.format import doctor_warn +from ros2doctor.api.format import doctor_error try: import ifcfg except ImportError: # check import error for windows and osx - doctor_warn()( + doctor_warn( 'Unable to import ifcfg. ' 'Use `python3 -m pip install ifcfg` to install needed package.') @@ -63,8 +64,8 @@ def check(self): try: ifcfg_ifaces = ifcfg.interfaces() except NameError: - doctor_warn()( - 'ERROR: `ifcfg` module is not imported. ' + doctor_error( + '`ifcfg` module is not imported. ' 'Unable to run network check.') result.add_error() return result @@ -73,20 +74,20 @@ def check(self): if not _is_unix_like_platform(): if not has_loopback and not has_non_loopback: # no flags found, otherwise one of them should be True. - doctor_warn()( - 'ERROR: No flags found. ' + doctor_error( + 'No flags found. ' 'Run `ipconfig` on Windows or ' 'install `ifconfig` on Unix to check network interfaces.') result.add_error() return result if not has_loopback: - doctor_warn()('ERROR: No loopback IP address is found.') + doctor_error('No loopback IP address is found.') result.add_error() if not has_non_loopback: - doctor_warn()('Only loopback IP address is found.') + doctor_warn('Only loopback IP address is found.') result.add_warning() if not has_multicast: - doctor_warn()('No multicast IP address is found.') + doctor_warn('No multicast IP address is found.') result.add_warning() return result @@ -103,7 +104,7 @@ def report(self): try: ifcfg_ifaces = ifcfg.interfaces() except NameError: - doctor_warn()('ERROR: ifcfg is not imported. Unable to generate network report.') + doctor_error('ifcfg is not imported. Unable to generate network report.') return Report('') network_report = Report('NETWORK CONFIGURATION') diff --git a/ros2doctor/ros2doctor/api/package.py b/ros2doctor/ros2doctor/api/package.py index a5857a060..ad775f304 100644 --- a/ros2doctor/ros2doctor/api/package.py +++ b/ros2doctor/ros2doctor/api/package.py @@ -24,6 +24,7 @@ from ros2doctor.api import Report from ros2doctor.api import Result from ros2doctor.api.format import doctor_warn +from ros2doctor.api.format import doctor_error import rosdistro @@ -36,24 +37,24 @@ def get_distro_package_versions() -> dict: """ distro_name = os.environ.get('ROS_DISTRO') if not distro_name: - doctor_warn()('ERROR: ROS_DISTRO is not set.') + doctor_error('ROS_DISTRO is not set.') return distro_name = distro_name.lower() url = rosdistro.get_index_url() if not url: - doctor_warn()( - 'ERROR: Unable to access ROSDISTRO_INDEX_URL or DEFAULT_INDEX_URL. ' + doctor_error( + 'Unable to access ROSDISTRO_INDEX_URL or DEFAULT_INDEX_URL. ' 'Check network setting to make sure machine is connected to internet.') return i = rosdistro.get_index(url) distro_info = rosdistro.get_distribution(i, distro_name) if not distro_info: - doctor_warn()(f'Distribution name {distro_name} is not found') + doctor_warn(f'Distribution name {distro_name} is not found') return try: repos_info = distro_info.get_data().get('repositories') except AttributeError: - doctor_warn()('No repository information found.') + doctor_warn('No repository information found.') return distro_package_vers = {} for _, info in repos_info.items(): @@ -105,29 +106,29 @@ def compare_versions(result: Result, local_packages: dict, distro_packages: dict local_ver = version.parse(local_ver_str).base_version required_ver = version.parse(required_ver_str).base_version if local_ver < required_ver: - doctor_warn()( + doctor_warn( f'{name} has been updated to a new version.' f' local: {local_ver} <' f' required: {required_ver}') result.add_warning() if missing_req: if len(missing_req) > 100: - doctor_warn()( + doctor_warn( 'Cannot find required versions of packages: ' + textwrap.shorten(missing_req, width=100) + ' Use `ros2 doctor --report` to see full list.') else: - doctor_warn()( + doctor_warn( 'Cannot find required versions of packages: ' + missing_req) if missing_local: if len(missing_local) > 100: - doctor_warn()( + doctor_warn( 'Cannot find local versions of packages: ' + textwrap.shorten(missing_local, width=100) + ' Use `ros2 doctor --report` to see full list.') else: - doctor_warn()( + doctor_warn( 'Cannot find local versions of packages: ' + missing_local) @@ -143,11 +144,11 @@ def check(self): result = Result() distro_package_vers = get_distro_package_versions() if not distro_package_vers: - doctor_warn()('ERROR: distro packages info is not found.') + doctor_error('distro packages info is not found.') result.add_error() local_package_vers = get_local_package_versions() if not local_package_vers: - doctor_warn()('ERROR: local package info is not found.') + doctor_error('local package info is not found.') result.add_error() if result.error != 0: return result diff --git a/ros2doctor/ros2doctor/api/platform.py b/ros2doctor/ros2doctor/api/platform.py index 3a90ce43c..ae4faa80b 100644 --- a/ros2doctor/ros2doctor/api/platform.py +++ b/ros2doctor/ros2doctor/api/platform.py @@ -21,6 +21,7 @@ from ros2doctor.api import Report from ros2doctor.api import Result from ros2doctor.api.format import doctor_warn +from ros2doctor.api.format import doctor_error import rosdistro @@ -33,19 +34,19 @@ def _check_platform_helper() -> Tuple[str, dict, dict]: """ distro_name = os.environ.get('ROS_DISTRO') if not distro_name: - doctor_warn()('ERROR: ROS_DISTRO is not set.') + doctor_error('ROS_DISTRO is not set.') return distro_name = distro_name.lower() u = rosdistro.get_index_url() if not u: - doctor_warn()( - 'ERROR: Unable to access ROSDISTRO_INDEX_URL or DEFAULT_INDEX_URL. ' + doctor_error( + 'Unable to access ROSDISTRO_INDEX_URL or DEFAULT_INDEX_URL. ' 'Check network setting to make sure machine is connected to internet.') return i = rosdistro.get_index(u) distro_info = i.distributions.get(distro_name) if not distro_info: - doctor_warn()(f'Distribution name {distro_name} is not found') + doctor_warn(f'Distribution name {distro_name} is not found') return try: distro_data = rosdistro.get_distribution(i, distro_name).get_data() @@ -65,20 +66,20 @@ def check(self): result = Result() distros = _check_platform_helper() if not distros: - doctor_warn()('ERROR: Missing rosdistro info. Unable to check platform.') + doctor_error('Missing rosdistro info. Unable to check platform.') result.add_error() return result distro_name, distro_info, _ = distros # check distro status if distro_info.get('distribution_status') == 'prerelease': - doctor_warn()( + doctor_warn( f'Distribution {distro_name} is not fully supported or tested. ' 'To get more consistent features, download a stable version at ' 'https://index.ros.org/doc/ros2/Installation/') result.add_warning() elif distro_info.get('distribution_status') == 'end-of-life': - doctor_warn()( + doctor_warn( f'Distribution {distro_name} is no longer supported or deprecated. ' 'To get the latest features, download the new versions at ' 'https://index.ros.org/doc/ros2/Installation/') diff --git a/ros2doctor/ros2doctor/api/topic.py b/ros2doctor/ros2doctor/api/topic.py index b376df7fb..b7f2f4870 100644 --- a/ros2doctor/ros2doctor/api/topic.py +++ b/ros2doctor/ros2doctor/api/topic.py @@ -50,10 +50,10 @@ def check(self): pub_count = node.count_publishers(topic) sub_count = node.count_subscribers(topic) if pub_count > sub_count: - doctor_warn()(f'Publisher without subscriber detected on {topic}.') + doctor_warn(f'Publisher without subscriber detected on {topic}.') result.add_warning() elif pub_count < sub_count: - doctor_warn()(f'Subscriber without publisher detected on {topic}.') + doctor_warn(f'Subscriber without publisher detected on {topic}.') result.add_warning() return result From e931b6b43f6038862dc31cef61588c2d029e2e49 Mon Sep 17 00:00:00 2001 From: claireyywang Date: Mon, 3 Feb 2020 17:28:16 -0800 Subject: [PATCH 7/7] fix code style Signed-off-by: claireyywang --- ros2doctor/ros2doctor/api/format.py | 5 ++--- ros2doctor/ros2doctor/api/network.py | 2 +- ros2doctor/ros2doctor/api/package.py | 2 +- ros2doctor/ros2doctor/api/platform.py | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/ros2doctor/ros2doctor/api/format.py b/ros2doctor/ros2doctor/api/format.py index f172e6bc4..16e332c8b 100644 --- a/ros2doctor/ros2doctor/api/format.py +++ b/ros2doctor/ros2doctor/api/format.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Callable from typing import List from typing import Tuple import warnings @@ -46,7 +45,6 @@ def compute_padding(report_items: List[Tuple[str, str]]) -> int: return padding - def custom_warning_format(msg, cat, filename, linenum, file=None, line=None): return '%s: %s: %s: %s\n' % (filename, linenum, cat.__name__, msg) @@ -61,6 +59,7 @@ def __enter__(self): def __exit__(self, t, v, trb): """ Define exit action for context manager. + :param t: type :param v: value :param trb: traceback @@ -85,4 +84,4 @@ def doctor_error(msg: str) -> None: :param msg: error message to be printed """ with CustomWarningFormat(): - warnings.warn(f'ERROR: {msg}', stacklevel=2) \ No newline at end of file + warnings.warn(f'ERROR: {msg}', stacklevel=2) diff --git a/ros2doctor/ros2doctor/api/network.py b/ros2doctor/ros2doctor/api/network.py index 00f82d546..0d76c55f0 100644 --- a/ros2doctor/ros2doctor/api/network.py +++ b/ros2doctor/ros2doctor/api/network.py @@ -19,8 +19,8 @@ from ros2doctor.api import DoctorReport from ros2doctor.api import Report from ros2doctor.api import Result -from ros2doctor.api.format import doctor_warn from ros2doctor.api.format import doctor_error +from ros2doctor.api.format import doctor_warn try: import ifcfg diff --git a/ros2doctor/ros2doctor/api/package.py b/ros2doctor/ros2doctor/api/package.py index ad775f304..fa892cdc6 100644 --- a/ros2doctor/ros2doctor/api/package.py +++ b/ros2doctor/ros2doctor/api/package.py @@ -23,8 +23,8 @@ from ros2doctor.api import DoctorReport from ros2doctor.api import Report from ros2doctor.api import Result -from ros2doctor.api.format import doctor_warn from ros2doctor.api.format import doctor_error +from ros2doctor.api.format import doctor_warn import rosdistro diff --git a/ros2doctor/ros2doctor/api/platform.py b/ros2doctor/ros2doctor/api/platform.py index ae4faa80b..84429d361 100644 --- a/ros2doctor/ros2doctor/api/platform.py +++ b/ros2doctor/ros2doctor/api/platform.py @@ -20,8 +20,8 @@ from ros2doctor.api import DoctorReport from ros2doctor.api import Report from ros2doctor.api import Result -from ros2doctor.api.format import doctor_warn from ros2doctor.api.format import doctor_error +from ros2doctor.api.format import doctor_warn import rosdistro