66
77import json
88import logging
9+ import sys
910import requests
1011import datetime
1112from pathlib import Path
1213from typing import Dict , Any , Optional
1314
1415
16+ def _print_registry_status (msg : str ) -> None :
17+ if sys .stderr .isatty ():
18+ print (f"\033 [2m{ msg } \033 [0m" , end = "\r " , file = sys .stderr , flush = True )
19+
20+
21+ def _clear_registry_status () -> None :
22+ if sys .stderr .isatty ():
23+ print (" " * 60 , end = "\r " , file = sys .stderr , flush = True )
24+
25+
1526class RegistryRetriever :
1627 """Manages the retrieval and caching of the Hatch package registry.
1728
@@ -37,7 +48,6 @@ def __init__(
3748 local_registry_cache_path (Path, optional): Path to local registry file. Defaults to None.
3849 """
3950 self .logger = logging .getLogger ("hatch.registry_retriever" )
40- self .logger .setLevel (logging .INFO )
4151
4252 self .cache_ttl = cache_ttl
4353 self .simulation_mode = simulation_mode
@@ -59,7 +69,7 @@ def __init__(
5969
6070 # Use file:// URL format for local files
6171 self .registry_url = f"file://{ str (self .registry_cache_path .absolute ())} "
62- self .logger .info (
72+ self .logger .debug (
6373 f"Operating in simulation mode with registry at: { self .registry_cache_path } "
6474 )
6575 else :
@@ -69,7 +79,7 @@ def __init__(
6979
7080 # We'll set the initial URL to today, but might fall back to yesterday
7181 self .registry_url = f"https://github.com/CrackingShells/Hatch-Registry/releases/download/{ self .today_str } /hatch_packages_registry.json"
72- self .logger .info (
82+ self .logger .debug (
7383 f"Operating in online mode with registry at: { self .registry_url } "
7484 )
7585
@@ -180,7 +190,7 @@ def _fetch_remote_registry(self) -> Dict[str, Any]:
180190 """
181191 if self .simulation_mode :
182192 try :
183- self .logger .info (f"Fetching registry from { self .registry_url } " )
193+ self .logger .debug (f"Fetching registry from { self .registry_url } " )
184194 with open (self .registry_cache_path , "r" ) as f :
185195 return json .load (f )
186196 except Exception as e :
@@ -193,7 +203,7 @@ def _fetch_remote_registry(self) -> Dict[str, Any]:
193203 self .registry_url = f"https://github.com/CrackingShells/Hatch-Registry/releases/download/{ date } /hatch_packages_registry.json"
194204 self .is_delayed = False # Reset delayed flag for today's registry
195205 else :
196- self .logger .info (
206+ self .logger .warning (
197207 f"Today's registry ({ date } ) not found, falling back to yesterday's"
198208 )
199209 # Fall back to yesterday's registry
@@ -211,7 +221,7 @@ def _fetch_remote_registry(self) -> Dict[str, Any]:
211221 self .is_delayed = True # Set delayed flag for yesterday's registry
212222
213223 try :
214- self .logger .info (f"Fetching registry from { self .registry_url } " )
224+ self .logger .debug (f"Fetching registry from { self .registry_url } " )
215225 response = requests .get (self .registry_url , timeout = 30 )
216226 response .raise_for_status ()
217227 return response .json ()
@@ -298,8 +308,9 @@ def get_registry(self, force_refresh: bool = False) -> Dict[str, Any]:
298308 # In simulation mode, we must have a local registry file
299309 registry_data = self ._read_local_cache ()
300310 else :
301- # In online mode, fetch from remote URL
311+ _print_registry_status ( " Refreshing registry cache..." )
302312 registry_data = self ._fetch_remote_registry ()
313+ _clear_registry_status ()
303314
304315 # Update local cache
305316 # Note that in case of simulation mode AND default cache path,
0 commit comments