From 403382ba0c001de2e7fc1405c889b9f4d7fad9f4 Mon Sep 17 00:00:00 2001 From: Etienne Filhol Date: Wed, 2 Dec 2026 03:08:22 +0100 Subject: [PATCH 1/2] fix(catalogue): name a dataset's own source on its page --- app/nullius/catalogue/sources.py | 29 ++++++++++++++++++++--------- app/tests/test_catalogue_sources.py | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/nullius/catalogue/sources.py b/app/nullius/catalogue/sources.py index 1e8dd5ba8..874158123 100644 --- a/app/nullius/catalogue/sources.py +++ b/app/nullius/catalogue/sources.py @@ -2,9 +2,9 @@ A benchmark that runs with Harbor and the Nullius standard reads its data two ways: Harbor from its registry or hub, the standard from the upstream it pins -(a repository at a commit, or a file at a revision) or from the Hugging Face -dataset its driver downloads (``data-source.json``: ``repository`` and -``revision``). Each row names the source, the pin and who fetches it and the files a definition +(a repository at a commit, a file at a revision, or a file at an address of +its own) or from the Hugging Face dataset or GitHub repository its driver +fetches (``data-source.json``: ``repository`` and ``revision``). Each row names the source, the pin and who fetches it and the files a definition checks by their sha256. Nothing here reads the network: it reads the catalogue entry and the definitions beside it. """ @@ -18,6 +18,7 @@ _GITHUB = re.compile(r"^https://github\.com/([^/]+/[^/]+?)(?:\.git)?/?$") _HF = re.compile(r"^https://huggingface\.co/datasets/([^/]+/[^/]+)/resolve/([^/]+)/") _HF_REPO = re.compile(r"^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$") +_URL = re.compile(r"^https?://([^/\s]+)/\S*$") _REVISION = re.compile(r"^[^/\s]+$") @@ -52,7 +53,8 @@ def _files(defined: List[dict]) -> List[dict]: def _data_source(here, key: str = "") -> Optional[tuple]: - """The Hugging Face dataset a driver downloads itself, ``data-source.json`` + """The Hugging Face dataset a driver downloads itself, or the GitHub + repository it fetches its data from (a URL), ``data-source.json`` beside its definition: (repository, revision), or None. A dataset's own entry there (``datasets.``) may name its repository and revision, for a driver that reads several.""" @@ -66,19 +68,28 @@ def _data_source(here, key: str = "") -> Optional[tuple]: repo, rev = own.get("repository", src.get("repository")), own.get("revision", src.get("revision")) except (OSError, ValueError, TypeError, AttributeError): return None - ok = isinstance(repo, str) and _HF_REPO.match(repo) and isinstance(rev, str) and _REVISION.match(rev) + ok = isinstance(repo, str) and (_HF_REPO.match(repo) or _GITHUB.match(repo)) and isinstance(rev, str) and _REVISION.match(rev) return (repo, rev) if ok else None def _own(upstream: dict, defined: List[dict], who: str, source: Optional[tuple] = None) -> dict: - """A row for a harness that reads the upstream itself: from Hugging Face when - its driver names a dataset there (``source``) or every file it names is - there, else from the repository it clones.""" + """A row for a harness that reads the upstream itself: from the GitHub + repository its driver fetches the data from (``source``); from Hugging Face + when its driver names a dataset there or every file it names is there; from + the address of the files it names by a URL elsewhere; else from the + repository it clones.""" hf = [_HF.match(d.get("url") or "") for d in defined] - if source or (defined and all(hf)): + urls = [_URL.match(d.get("url") or "") for d in defined] + if source and _GITHUB.match(source[0]): + row = dict(_repo({"repository": source[0], "tested": source[1]}), + by=f"{who} fetches the repository at this commit on the first run and keeps it") + elif source or (defined and all(hf)): name, rev = source or (hf[0].group(1), hf[0].group(2)) row = {"from": "Hugging Face", "name": name, "href": f"https://huggingface.co/datasets/{name}/tree/{rev}", "pin": rev[:7], "by": f"{who} downloads it on the first run and keeps it"} + elif defined and all(urls): + row = {"from": "Download", "name": urls[0].group(1), "href": urls[0].group(0), "pin": "", + "by": f"{who} downloads it on the first run and keeps it"} else: row = dict(_repo(upstream), by=f"{who} fetches the repository at this commit on the first run and keeps it") row["files"] = _files(defined) diff --git a/app/tests/test_catalogue_sources.py b/app/tests/test_catalogue_sources.py index f7ea2304c..0f1957039 100644 --- a/app/tests/test_catalogue_sources.py +++ b/app/tests/test_catalogue_sources.py @@ -48,6 +48,26 @@ def test_a_dataset_the_driver_downloads_from_hugging_face_names_it_not_the_upstr self.assertEqual((row["from"], row["name"], row["pin"]), ("Hugging Face", "org/data", "0123456")) self.assertEqual(row["href"], f"https://huggingface.co/datasets/org/data/tree/{COMMIT}") + def test_a_dataset_the_driver_fetches_from_another_github_repository_names_it_not_the_upstream(self): + d = catalog.Dataset(key="main", title="Main") + with tempfile.TemporaryDirectory() as here: + std = {"_here": here, "upstream": {"repository": "https://github.com/org/harness", "tested": COMMIT}, + "datasets": [{"id": "main", "units": 3}]} + with open(os.path.join(here, "data-source.json"), "w") as f: + json.dump({"repository": "https://github.com/org/tasks", "revision": "f" * 40}, f) + (row,) = sources.of(d, ["standard"], std) + self.assertEqual((row["from"], row["name"], row["pin"]), ("GitHub", "org/tasks", "fffffff")) + self.assertEqual(row["href"], "https://github.com/org/tasks/tree/" + "f" * 40) + + def test_a_file_at_an_address_outside_hugging_face_names_that_address_not_the_upstream(self): + d = catalog.Dataset(key="main", title="Main") + url = "https://files.example.org/evals/test_set.csv" + std = {"upstream": {"repository": "https://github.com/org/evals", "tested": COMMIT}, + "datasets": [{"id": "main", "url": url, "sha256": "c" * 64, "bytes": 2_000_000}]} + (row,) = sources.of(d, ["standard"], std) + self.assertEqual((row["from"], row["name"], row["href"], row["pin"]), ("Download", "files.example.org", url, "")) + self.assertEqual(row["files"], [{"name": "test_set.csv", "size": "2 MB", "checked": True}]) + def test_a_driver_that_downloads_from_two_repositories_names_each_datasets_own(self): lite, full = catalog.Dataset(key="qa-lite", title="Lite"), catalog.Dataset(key="qa-full", title="Full") other = "f" * 40 From 0413066dc38600c78be81292f560889b8528f866 Mon Sep 17 00:00:00 2001 From: Etienne Filhol Date: Wed, 2 Dec 2026 04:49:16 +0100 Subject: [PATCH 2/2] fix(catalogue): name a download's host only when all its files share it --- app/nullius/catalogue/sources.py | 4 ++-- app/tests/test_catalogue_sources.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/nullius/catalogue/sources.py b/app/nullius/catalogue/sources.py index 874158123..42782d0cf 100644 --- a/app/nullius/catalogue/sources.py +++ b/app/nullius/catalogue/sources.py @@ -76,7 +76,7 @@ def _own(upstream: dict, defined: List[dict], who: str, source: Optional[tuple] """A row for a harness that reads the upstream itself: from the GitHub repository its driver fetches the data from (``source``); from Hugging Face when its driver names a dataset there or every file it names is there; from - the address of the files it names by a URL elsewhere; else from the + the one host of the files it names by a URL elsewhere; else from the repository it clones.""" hf = [_HF.match(d.get("url") or "") for d in defined] urls = [_URL.match(d.get("url") or "") for d in defined] @@ -87,7 +87,7 @@ def _own(upstream: dict, defined: List[dict], who: str, source: Optional[tuple] name, rev = source or (hf[0].group(1), hf[0].group(2)) row = {"from": "Hugging Face", "name": name, "href": f"https://huggingface.co/datasets/{name}/tree/{rev}", "pin": rev[:7], "by": f"{who} downloads it on the first run and keeps it"} - elif defined and all(urls): + elif defined and all(urls) and len({u.group(1) for u in urls}) == 1: row = {"from": "Download", "name": urls[0].group(1), "href": urls[0].group(0), "pin": "", "by": f"{who} downloads it on the first run and keeps it"} else: diff --git a/app/tests/test_catalogue_sources.py b/app/tests/test_catalogue_sources.py index 0f1957039..83dee02e7 100644 --- a/app/tests/test_catalogue_sources.py +++ b/app/tests/test_catalogue_sources.py @@ -67,6 +67,9 @@ def test_a_file_at_an_address_outside_hugging_face_names_that_address_not_the_up (row,) = sources.of(d, ["standard"], std) self.assertEqual((row["from"], row["name"], row["href"], row["pin"]), ("Download", "files.example.org", url, "")) self.assertEqual(row["files"], [{"name": "test_set.csv", "size": "2 MB", "checked": True}]) + # files on two hosts have no one address to name: the upstream's row, as before + std["datasets"].append({"id": "main", "url": "https://other.example.net/more.csv", "sha256": "d" * 64}) + self.assertEqual(sources.of(d, ["standard"], std)[0]["from"], "GitHub") def test_a_driver_that_downloads_from_two_repositories_names_each_datasets_own(self): lite, full = catalog.Dataset(key="qa-lite", title="Lite"), catalog.Dataset(key="qa-full", title="Full")