|
5 | 5 | import string
|
6 | 6 | import markdown
|
7 | 7 | from bs4 import BeautifulSoup
|
| 8 | +from typing import Dict, List, AnyStr, Union |
8 | 9 |
|
9 |
| -def get_grouped_sections(root: str = "course_contents") -> dict[str, list]: |
| 10 | +def get_grouped_sections(root: str = "course_contents") -> Dict[AnyStr, List]: |
10 | 11 | sections = get_all_sections_with_content(root)
|
11 | 12 | grouped_sections = {}
|
12 | 13 | for section in sections:
|
@@ -34,13 +35,13 @@ def get_all_sections_with_content(root: str = "course_contents"):
|
34 | 35 | yield {"index": section_index, "lectures": non_hidden_lectures}
|
35 | 36 |
|
36 | 37 |
|
37 |
| -def get_section_lectures(folder: pathlib.Path | str) -> list[str]: |
| 38 | +def get_section_lectures(folder: Union[pathlib.Path, AnyStr]) -> List[str]: |
38 | 39 | """Return a list of pathlib.Path objects for all lectsures in a section folder"""
|
39 | 40 | lecture_path = pathlib.Path(folder) / "lectures"
|
40 | 41 | return sorted([folder for folder in lecture_path.glob("*/README.md")])
|
41 | 42 |
|
42 | 43 |
|
43 |
| -def get_lecture_content(lecture_path: pathlib.Path, root_path: str | pathlib.Path = "course_contents") -> dict[str, str]: |
| 44 | +def get_lecture_content(lecture_path: pathlib.Path, root_path: Union[pathlib.Path, AnyStr] = "course_contents") -> Dict[str, str]: |
44 | 45 | """Return a dictionary of lecture content.
|
45 | 46 | Return a dictionary with the following keys:
|
46 | 47 | - title, the h1 from the markdown file
|
@@ -68,7 +69,7 @@ def get_lecture_content(lecture_path: pathlib.Path, root_path: str | pathlib.Pat
|
68 | 69 | }
|
69 | 70 |
|
70 | 71 |
|
71 |
| -def get_grouped_build_sections(root: str = "build") -> dict[str, list]: |
| 72 | +def get_grouped_build_sections(root: str = "build") -> Dict[str, list]: |
72 | 73 | sections = build_and_get_yaml_contents(root)
|
73 | 74 | grouped_sections = {}
|
74 | 75 | for section in sections:
|
@@ -108,7 +109,7 @@ def build_and_get_yaml_contents(build_path: str = "build"):
|
108 | 109 | yield section
|
109 | 110 |
|
110 | 111 |
|
111 |
| -def copy_lectures_to_build_path(section: dict, new_section_name: str, build_path: str = "build"): |
| 112 | +def copy_lectures_to_build_path(section: Dict, new_section_name: str, build_path: str = "build"): |
112 | 113 | for lecture in section["lectures"]:
|
113 | 114 | lecture_name = "_".join(lecture["full_path"].parent.name.split("_")[1:])
|
114 | 115 | pathlib.Path(build_path, new_section_name, lecture_name).mkdir(parents=True, exist_ok=True)
|
|
0 commit comments