eolas-data 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ """Regenerate ``_dataset_names.py`` from the live API.
2
+
3
+ Run before each release:
4
+
5
+ python -m eolas_data._regen_names
6
+
7
+ Writes to the same file inside the package. Commit the result.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import datetime as _dt
12
+ import json as _json
13
+ import pathlib as _pathlib
14
+ import urllib.request as _req
15
+
16
+ API = "https://api.eolas.fyi/v1/datasets"
17
+
18
+
19
+ def regenerate() -> None:
20
+ with _req.urlopen(API, timeout=30) as r:
21
+ data = _json.load(r)
22
+ names = sorted({d["name"] for d in data})
23
+ today = _dt.date.today().isoformat()
24
+
25
+ out = _pathlib.Path(__file__).with_name("_dataset_names.py")
26
+ lines: list[str] = []
27
+ lines.append('"""')
28
+ lines.append('Type stubs for dataset names.')
29
+ lines.append('')
30
+ lines.append('Auto-generated from https://api.eolas.fyi/v1/datasets at release time.')
31
+ lines.append(f'Snapshot: {today} ({len(names)} datasets).')
32
+ lines.append('Regenerate before each release with `python -m eolas_data._regen_names`.')
33
+ lines.append('')
34
+ lines.append('At runtime this is just a string — `Literal[...]` only constrains static type')
35
+ lines.append("checkers like mypy/pyright, so passing a name not in this list still works,")
36
+ lines.append("it just doesn't autocomplete.")
37
+ lines.append('"""')
38
+ lines.append('from typing import Literal')
39
+ lines.append('')
40
+ lines.append(f'CATALOG_SNAPSHOT_DATE = "{today}"')
41
+ lines.append(f'CATALOG_SNAPSHOT_COUNT = {len(names)}')
42
+ lines.append('')
43
+ lines.append('DatasetName = Literal[')
44
+ for n in names:
45
+ lines.append(f' {n!r},')
46
+ lines.append(']')
47
+ lines.append('')
48
+ lines.append('ALL_NAMES: tuple[str, ...] = (')
49
+ for n in names:
50
+ lines.append(f' {n!r},')
51
+ lines.append(')')
52
+ out.write_text("\n".join(lines) + "\n")
53
+ print(f"wrote {len(names)} datasets to {out}")
54
+
55
+
56
+ if __name__ == "__main__":
57
+ regenerate()