Skip to content

Commit 33e075d

Browse files
committed
📝 Add recommended Python/Julia loading
1 parent 2f3f2c0 commit 33e075d

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-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)

0 commit comments

Comments
 (0)