diff --git a/setup.py b/setup.py index 1bb0f97..59510c3 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,6 @@ FILE = Path(__file__).resolve() PARENT = FILE.parent # root directory README = (PARENT / 'README.md').read_text(encoding='utf-8') REQUIREMENTS = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements((PARENT / 'requirements.txt').read_text())] -PKG_REQUIREMENTS = ['sentry_sdk'] # pip-only requirements def get_version(): @@ -37,7 +36,7 @@ setup( author_email='hello@ultralytics.com', packages=find_packages(), # required include_package_data=True, - install_requires=REQUIREMENTS + PKG_REQUIREMENTS, + install_requires=REQUIREMENTS, extras_require={ 'dev': [ 'check-manifest', diff --git a/ultralytics/yolo/utils/__init__.py b/ultralytics/yolo/utils/__init__.py index e2e32b6..77f7e20 100644 --- a/ultralytics/yolo/utils/__init__.py +++ b/ultralytics/yolo/utils/__init__.py @@ -164,7 +164,7 @@ class IterableSimpleNamespace(SimpleNamespace): return getattr(self, key, default) -def plt_settings(rcparams={'font.size': 11}, backend='Agg'): +def plt_settings(rcparams=None, backend='Agg'): """ Decorator to temporarily set rc parameters and the backend for a plotting function. @@ -180,6 +180,9 @@ def plt_settings(rcparams={'font.size': 11}, backend='Agg'): callable: Decorated function with temporarily set rc parameters and backend. """ + if rcparams is None: + rcparams = {'font.size': 11} + def decorator(func): """Decorator to apply temporary rc parameters and backend to a function.""" @@ -242,7 +245,7 @@ if WINDOWS: # emoji-safe logging LOGGER.addFilter(EmojiFilter()) -def yaml_save(file='data.yaml', data={}): +def yaml_save(file='data.yaml', data=None): """ Save YAML data to a file. @@ -253,6 +256,8 @@ def yaml_save(file='data.yaml', data={}): Returns: None: Data is saved to the specified file. """ + if data is None: + data = {} file = Path(file) if not file.parent.exists(): # Create parent directories if they don't exist @@ -603,10 +608,11 @@ def threaded(func): def set_sentry(): """ - Initialize the Sentry SDK for error tracking and reporting. Enabled when sync=True in settings and - disabled when sync=False. Run 'yolo settings' to see and update settings YAML file. + Initialize the Sentry SDK for error tracking and reporting. Only used if sentry_sdk package is installed and + sync=True in settings. Run 'yolo settings' to see and update settings YAML file. - Conditions required to send errors: + Conditions required to send errors (ALL conditions must be met or no errors will be reported): + - sentry_sdk package is installed - sync=True in YOLO settings - pytest is not running - running in a pip package installation @@ -653,7 +659,12 @@ def set_sentry(): is_pip_package() and \ not is_git_dir(): - import sentry_sdk # noqa + # If sentry_sdk package is not installed then return and do not use Sentry + try: + import sentry_sdk # noqa + except ImportError: + return + sentry_sdk.init( dsn='https://5ff1556b71594bfea135ff0203a0d290@o4504521589325824.ingest.sentry.io/4504521592406016', debug=False, diff --git a/ultralytics/yolo/utils/checks.py b/ultralytics/yolo/utils/checks.py index 78cb52c..2767560 100644 --- a/ultralytics/yolo/utils/checks.py +++ b/ultralytics/yolo/utils/checks.py @@ -232,16 +232,22 @@ def check_requirements(requirements=ROOT.parent / 'requirements.txt', exclude=() s += f'"{r}" ' n += 1 - if s and install and AUTOINSTALL: # check environment variable - LOGGER.info(f"{prefix} Ultralytics requirement{'s' * (n > 1)} {s}not found, attempting AutoUpdate...") - try: - assert is_online(), 'AutoUpdate skipped (offline)' - LOGGER.info(subprocess.check_output(f'pip install --no-cache {s} {cmds}', shell=True).decode()) - s = f"{prefix} {n} package{'s' * (n > 1)} updated per {file or requirements}\n" \ - f"{prefix} ⚠️ {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}\n" - LOGGER.info(s) - except Exception as e: - LOGGER.warning(f'{prefix} ❌ {e}') + if s: + if install and AUTOINSTALL: # check environment variable + LOGGER.info(f"{prefix} Ultralytics requirement{'s' * (n > 1)} {s}not found, attempting AutoUpdate...") + try: + assert is_online(), 'AutoUpdate skipped (offline)' + LOGGER.info(subprocess.check_output(f'pip install --no-cache {s} {cmds}', shell=True).decode()) + s = f"{prefix} {n} package{'s' * (n > 1)} updated per {file or requirements}\n" \ + f"{prefix} ⚠️ {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}\n" + LOGGER.info(s) + except Exception as e: + LOGGER.warning(f'{prefix} ❌ {e}') + return False + else: + return False + + return True def check_suffix(file='yolov8n.pt', suffix='.pt', msg=''):