Skip to content

Commit 5bb6afa

Browse files
authored
Merge pull request #30 from srlearn/load-recommendations
✨ Dataset loading recommendations
2 parents f0d58e7 + 33e075d commit 5bb6afa

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

docs/build_docs.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,26 @@
2727
TOKEN = environ["GH_TOKEN"]
2828
AUTHORIZATION = {"Authorization": f"token {TOKEN}"}
2929

30+
DATA_LOAD_RECOMMENDATION = """
3031
31-
def build_dataset_descriptions():
32+
=== "Python"
33+
34+
``` python
35+
from relational_datasets import load
36+
train, test = load("{dataset_name}", "{version}")
37+
```
38+
39+
=== "Julia"
40+
41+
``` julia
42+
using RelationalDatasets
43+
train, test = load("{dataset_name}", "{version}")
44+
```
45+
46+
"""
47+
48+
49+
def build_dataset_descriptions(latest_version: str):
3250

3351
req = Request(
3452
"https://api.github.com/repos/srlearn/datasets/releases/latest",
@@ -47,11 +65,19 @@ def build_dataset_descriptions():
4765
)
4866

4967
with urlopen(req) as url:
50-
with open(f"dataset_descriptions/{name}.md", "w") as fh:
51-
fh.write(url.read().decode("utf-8"))
68+
description = url.read().decode("utf-8").splitlines()
69+
70+
# Insert dataset loading instructions at the third position in the list.
71+
description.insert(
72+
2, DATA_LOAD_RECOMMENDATION.format(dataset_name=name, version=latest_version)
73+
)
5274

75+
with open(f"dataset_descriptions/{name}.md", "w") as fh:
76+
for line in description:
77+
fh.write(line + "\n")
5378

54-
def build_downloads_page():
79+
80+
def build_downloads_page() -> str:
5581

5682
req = Request(
5783
"https://api.github.com/repos/srlearn/datasets/git/refs/tags",
@@ -108,7 +134,10 @@ def build_downloads_page():
108134
with open("downloads.md", "w") as fh:
109135
fh.write(markdown_string)
110136

137+
# The first entry of `all_versions` should be the most recent one.
138+
return all_versions[0]
139+
111140

112141
if __name__ == "__main__":
113-
build_downloads_page()
114-
build_dataset_descriptions()
142+
latest_version = build_downloads_page()
143+
build_dataset_descriptions(latest_version)

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ markdown_extensions:
3030
permalink: true
3131
- admonition
3232
- pymdownx.superfences
33+
- pymdownx.tabbed:
34+
alternate_style: true
3335
- pymdownx.snippets
3436
- pymdownx.tasklist
3537

0 commit comments

Comments
 (0)