Skip to content

Commit 5417d44

Browse files
fix: replace print() with logger.warning() in extensions catalog warnings
Print statements to stderr are not appropriate for library code that may be consumed by tools or tests. Replaced with logger.warning() for proper log management. Removed unused local sys imports.
1 parent f8b3d60 commit 5417d44

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

src/specify_cli/extensions/__init__.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import errno
1313
import hashlib
1414
import json
15+
import logging
1516
import os
1617
import re
1718
import shutil
@@ -45,6 +46,8 @@
4546
from ..catalogs import CatalogStackBase
4647
from ..shared_infra import verify_archive_sha256
4748

49+
logger = logging.getLogger(__name__)
50+
4851
_FALLBACK_CORE_COMMAND_NAMES = frozenset(
4952
{
5053
"analyze",
@@ -3508,18 +3511,15 @@ def get_active_catalogs(self) -> List[CatalogEntry]:
35083511
Raises:
35093512
ValidationError: If a catalog URL is invalid
35103513
"""
3511-
import sys
3512-
35133514
# 1. SPECKIT_CATALOG_URL env var replaces all defaults for backward compat
35143515
if env_value := os.environ.get("SPECKIT_CATALOG_URL"):
35153516
catalog_url = env_value.strip()
35163517
self._validate_catalog_url(catalog_url)
35173518
if catalog_url != self.DEFAULT_CATALOG_URL:
35183519
if not getattr(self, "_non_default_catalog_warning_shown", False):
3519-
print(
3520-
"Warning: Using non-default extension catalog. "
3520+
logger.warning(
3521+
"Using non-default extension catalog. "
35213522
"Only use catalogs from sources you trust.",
3522-
file=sys.stderr,
35233523
)
35243524
self._non_default_catalog_warning_shown = True
35253525
return [
@@ -3743,8 +3743,6 @@ def _get_merged_extensions(
37433743
Raises:
37443744
ExtensionError: If all catalogs fail to fetch
37453745
"""
3746-
import sys
3747-
37483746
active_catalogs = self.get_active_catalogs()
37493747
merged: Dict[str, Dict[str, Any]] = {}
37503748
any_success = False
@@ -3754,9 +3752,8 @@ def _get_merged_extensions(
37543752
catalog_data = self._fetch_single_catalog(catalog_entry, force_refresh)
37553753
any_success = True
37563754
except ExtensionError as e:
3757-
print(
3758-
f"Warning: Could not fetch catalog '{catalog_entry.name}': {e}",
3759-
file=sys.stderr,
3755+
logger.warning(
3756+
"Could not fetch catalog '%s': %s", catalog_entry.name, e,
37603757
)
37613758
continue
37623759

0 commit comments

Comments
 (0)