|
15 | 15 |
|
16 | 16 |
|
17 | 17 | class FileEntry(NamedTuple): |
| 18 | + """Stores key information about a markdown/python file internal to mkdocs-python-genfiles""" |
18 | 19 | source_file_path: Path |
| 20 | + """Absolute path to python source file on disk""" |
19 | 21 | doc_file_path: Path |
| 22 | + """Absolute path to markdown file on disk""" |
20 | 23 | module_id: ModuleId |
| 24 | + """Abstract representation of a python module similar to it's dot-part string divided as a tuple |
| 25 | + |
| 26 | + Importantly, a package __init__ file for package foo.bar will be ``("foo", "bar", "__init__")``""" |
21 | 27 | file: File |
| 28 | + """Mkdocs File object for use by mkdocs only""" |
22 | 29 |
|
23 | 30 |
|
24 | 31 | class Source(NamedTuple): |
| 32 | + """Source of python files""" |
25 | 33 | base_path: Path |
| 34 | + """Root of the python files |
| 35 | + |
| 36 | + This is as python might see in PYTHONPATH""" |
26 | 37 | dir_path: Path |
| 38 | + """Directory to search |
| 39 | + |
| 40 | + May be the same as base_path but may also be a subdirectory of it, eg: to avoid unit tests.""" |
27 | 41 | ignore: List[str] |
| 42 | + """List of glob expressions for files and directories to ignore.""" |
28 | 43 |
|
29 | 44 |
|
30 | 45 | class FilesGenerator: |
@@ -78,20 +93,17 @@ def generate_page(self, source_base_path: Path, source_path: Path, page_template |
78 | 93 | module_name=self.module_name(module_id, full_name=False, printable=True), |
79 | 94 | printable_module_id=self.module_name(module_id, full_name=True, printable=True), |
80 | 95 | module_id=self.module_name(module_id, full_name=True, printable=False), |
81 | | - ) |
82 | | - ) |
83 | | - |
84 | | - entry = FileEntry( |
85 | | - source_file_path=source_path, |
86 | | - doc_file_path=target_path, |
87 | | - module_id=module_id, |
88 | | - file=File( |
89 | | - str(target_path.relative_to(self.base_path)), |
90 | | - src_dir=str(self.base_path), |
91 | | - dest_dir=self._dest_dir, |
92 | | - use_directory_urls=self._use_directory_urls, |
93 | | - ) |
94 | | - ) |
| 96 | + )) |
| 97 | + |
| 98 | + entry = FileEntry(source_file_path=source_path, |
| 99 | + doc_file_path=target_path, |
| 100 | + module_id=module_id, |
| 101 | + file=File( |
| 102 | + str(target_path.relative_to(self.base_path)), |
| 103 | + src_dir=str(self.base_path), |
| 104 | + dest_dir=self._dest_dir, |
| 105 | + use_directory_urls=self._use_directory_urls, |
| 106 | + )) |
95 | 107 | self.generated_pages[entry.doc_file_path.absolute()] = entry |
96 | 108 | return entry |
97 | 109 |
|
@@ -122,7 +134,7 @@ def file_path_for_module_id(self, module_id: ModuleId) -> Path: |
122 | 134 | :return: An absolute path |
123 | 135 | """ |
124 | 136 | if self._init_section_index and module_id[-1] == "__init__": |
125 | | - module_id = module_id[:-1] + ("README.md",) |
| 137 | + module_id = module_id[:-1] + ("README.md", ) |
126 | 138 | return Path(self.base_path, "_ref", *module_id).with_suffix(".md") |
127 | 139 |
|
128 | 140 | def module_name(self, module_id: ModuleId, full_name: bool, printable: bool) -> str: |
@@ -150,7 +162,6 @@ def get_module_id(module_path: Path, base_path: Path) -> ModuleId: |
150 | 162 | return module_path.relative_to(base_path).with_suffix("").parts |
151 | 163 |
|
152 | 164 |
|
153 | | - |
154 | 165 | def discover_python_files(source_dir: Path, ignore: List[str]) -> Iterable[Path]: |
155 | 166 | """ |
156 | 167 | Discover python files recursively from a directory |
|
0 commit comments