File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88_source_library = {}
99_source_library .update (ess .sources )
1010
11-
12- _source_registry = pooch .create (
13- path = pooch .os_cache ("tof" ),
14- base_url = "https://github.com/scipp/tof-sources/raw/refs/heads/main/1/" ,
15- retry_if_failed = 2 ,
16- registry = {f ["path" ]: f ["hash" ] for f in _source_library .values ()},
17- )
11+ _BASE_URLS = [
12+ "https://public.esss.dk/groups/scipp/tof/1/" , # primary: DMSC server
13+ "https://github.com/scipp/tof-sources/raw/refs/heads/main/1/" , # fallback: GitHub
14+ ]
15+
16+ # One registry per mirror URL
17+ _registries = [
18+ pooch .create (
19+ path = pooch .os_cache ("tof" ),
20+ base_url = base_url ,
21+ retry_if_failed = 2 ,
22+ registry = {f ["path" ]: f ["hash" ] for f in _source_library .values ()},
23+ )
24+ for base_url in _BASE_URLS
25+ ]
1826
1927
2028def get_source_path (name : str ) -> str :
21- return _source_registry .fetch (_source_library [name ]["path" ])
29+ path = _source_library [name ]["path" ]
30+ last_exc = None
31+ for registry in _registries :
32+ try :
33+ return registry .fetch (path )
34+ except Exception as exc :
35+ last_exc = exc
36+ raise RuntimeError (
37+ f"Failed to download '{ path } ' from all mirrors: { _BASE_URLS } "
38+ ) from last_exc
2239
2340
2441__all__ = ["ess" , "get_source_path" ]
Original file line number Diff line number Diff line change 1+ # SPDX-License-Identifier: BSD-3-Clause
2+ # Copyright (c) 2026 Scipp contributors (https://github.com/scipp)
3+
4+ from pathlib import Path
5+
6+ import pooch
7+
8+ from tof .facilities import _BASE_URLS , _source_library
9+
10+
11+ def test_source_library_files_identical_on_public_and_github (tmp_path : Path ) -> None :
12+ registry = {f ["path" ]: f ["hash" ] for f in _source_library .values ()}
13+
14+ public = pooch .create (
15+ path = tmp_path / "cache_public" , base_url = _BASE_URLS [0 ], registry = registry
16+ )
17+
18+ gh = pooch .create (
19+ path = tmp_path / "cache_github" , base_url = _BASE_URLS [1 ], registry = registry
20+ )
21+
22+ for entry in _source_library .values ():
23+ rel = entry ["path" ]
24+
25+ # Verify that hashes are the same in both registries.
26+ assert public .registry [rel ] == gh .registry [rel ]
27+
28+ p_gh = Path (gh .fetch (rel ))
29+ p_public = Path (public .fetch (rel ))
30+
31+ assert p_gh .name == p_public .name
You can’t perform that action at this time.
0 commit comments