@@ -234,69 +234,6 @@ def _spawn_remote_version_refresh(source_url: str) -> None:
234234 log .debug (f"Could not start background version check: { e } " )
235235
236236
237- # The version check never fetches on the hot path (update-notifier pattern):
238- # it only reads the cached remote version, and refreshes the cache in a
239- # detached background process so that no run ever blocks on the network.
240- REMOTE_VERSION_CACHE = Path (NFCORE_CACHE_DIR , "latest_version.json" )
241- REMOTE_VERSION_CACHE_EXPIRY = 60 * 60 * 24 # refresh at most once a day
242- REMOTE_VERSION_REFRESH_BACKOFF = 60 * 10 # wait at least this long between refresh attempts
243-
244- # Self-contained refresh script, so the background process doesn't have to
245- # import nf_core (or requests) just to run one HTTP GET
246- REMOTE_VERSION_REFRESH_SCRIPT = """
247- import json, os, re, sys, time, urllib.request
248- text = urllib.request.urlopen(sys.argv[1], timeout=10).read().decode()
249- tmp_path = sys.argv[2] + ".tmp"
250- with open(tmp_path, "w") as fh:
251- json.dump({"version": re.sub(r"[^0-9.]", "", text), "timestamp": time.time()}, fh)
252- os.replace(tmp_path, sys.argv[2])
253- """
254-
255-
256- def _load_version_cache () -> dict :
257- try :
258- with open (REMOTE_VERSION_CACHE ) as fh :
259- cached = json .load (fh )
260- if isinstance (cached , dict ):
261- return cached
262- except (OSError , ValueError ):
263- pass
264- return {}
265-
266-
267- def _load_cached_remote_version () -> str | None :
268- cached = _load_version_cache ()
269- try :
270- if time .time () - cached ["timestamp" ] < REMOTE_VERSION_CACHE_EXPIRY :
271- Version (cached ["version" ]) # guard against a corrupted cache
272- return cached ["version" ]
273- except (KeyError , TypeError , InvalidVersion ):
274- pass
275- return None
276-
277-
278- def _spawn_remote_version_refresh (source_url : str ) -> None :
279- """Kick off a detached background process to refresh the remote version cache."""
280- try :
281- cached = _load_version_cache ()
282- if time .time () - float (cached .get ("attempted_at" ) or 0 ) < REMOTE_VERSION_REFRESH_BACKOFF :
283- return
284- # Record the attempt up front, so failed refreshes back off instead of respawning every run
285- cached ["attempted_at" ] = time .time ()
286- setup_nfcore_cachedir ()
287- with open (REMOTE_VERSION_CACHE , "w" ) as fh :
288- json .dump (cached , fh )
289- subprocess .Popen (
290- [sys .executable , "-m" , "nf_core.version_updater" , source_url , str (REMOTE_VERSION_CACHE )],
291- stdin = subprocess .DEVNULL ,
292- stdout = subprocess .DEVNULL ,
293- stderr = subprocess .DEVNULL ,
294- start_new_session = True ,
295- )
296- except (OSError , ValueError , TypeError , subprocess .SubprocessError ) as e :
297- log .debug (f"Could not start background version check: { e } " )
298-
299-
300237def check_if_outdated (
301238 current_version = None ,
302239 remote_version = None ,
0 commit comments