Skip to content

Commit 5fbdce0

Browse files
committed
simpler file match
1 parent f96a7db commit 5fbdce0

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

deployment/installtutorials.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pathlib import Path
1010
import tempfile
1111
from subprocess import CalledProcessError, check_call
12+
import glob
1213
import shutil
1314
import requests
1415

@@ -52,24 +53,14 @@ def process_repo(repo, destination_directory):
5253
return
5354

5455
repo = Path(tmp)
55-
# tutorial filename should match repo name
56-
tutorial = repo_name.split("/")[1].replace("tutorial--", "")
57-
try:
58-
shutil.copy(f"{repo}/{tutorial}.html", destination_directory)
59-
print(f"Found tutorial {tutorial}.html")
60-
except FileNotFoundError:
61-
# this must be a book.
62-
# filenames of tutorials (chapters in the book) should be of the format 1_Name.html
63-
# (see https://github.com/astropy-learn/dev-guide/blob/main/README.md)
64-
chapters = [
65-
f
66-
for f in os.listdir(repo)
67-
if f[0].isdigit() and "_" in f[:3] and f.endswith(".html")
68-
]
69-
print(f"Found chapters {chapters}")
70-
for t in chapters:
71-
shutil.copy(f"{repo}/{t}", destination_directory)
72-
# also include the book index (first page)
56+
tutorials = glob.glob(f"{repo}/*.ipynb")
57+
print(f"Found tutorial(s) {tutorials}")
58+
shutil.copy(f"{repo}/*.ipynb", destination_directory)
59+
for t in tutorials:
60+
# copy rendered html version of tutorials
61+
shutil.copy(f"{os.path.splitext(t)[0]}.html", destination_directory)
62+
if len(tutorials) > 1:
63+
print("More than 1 tutorial found; treating this as a book")
7364
shutil.copy(f"{repo}/index.html", destination_directory)
7465

7566

0 commit comments

Comments
 (0)