|
9 | 9 | from pathlib import Path
|
10 | 10 | import tempfile
|
11 | 11 | from subprocess import CalledProcessError, check_call
|
| 12 | +import glob |
12 | 13 | import shutil
|
13 | 14 | import requests
|
14 | 15 |
|
@@ -52,24 +53,14 @@ def process_repo(repo, destination_directory):
|
52 | 53 | return
|
53 | 54 |
|
54 | 55 | 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") |
73 | 64 | shutil.copy(f"{repo}/index.html", destination_directory)
|
74 | 65 |
|
75 | 66 |
|
|
0 commit comments