17
17
import logging
18
18
import shutil
19
19
from pathlib import Path
20
- from typing import Dict , Optional , Tuple , Union
20
+ from typing import Dict , List , Optional , Tuple , Union
21
21
22
22
from tqdm import tqdm
23
23
@@ -81,7 +81,8 @@ def image_work_dir(self) -> Path:
81
81
def set_input_files (self ,
82
82
in_file : Path ,
83
83
include_dir : Optional [Path ] = None ,
84
- image_dir : Optional [Path ] = None ) -> None :
84
+ image_dir : Optional [Path ] = None ,
85
+ python_dir : Optional [Path ] = None ) -> None :
85
86
"""Set the input files to collect.
86
87
87
88
Args:
@@ -91,6 +92,9 @@ def set_input_files(self,
91
92
image_dir: Directory containing iamges to include from AsciiDoc files. If `None` and
92
93
directory named `images` is present next to the `in_file`, that
93
94
directory is used for images. Otherwise, no images are copied.
95
+ python_dir: Directory containing Python code to include in the documentation. This
96
+ directory will be added to the Python path for the input file and any
97
+ document in the include_dir.
94
98
"""
95
99
pkg = Package (Package .INPUT_PACKAGE_NAME )
96
100
pkg .adoc_src_dir = include_dir
@@ -106,6 +110,11 @@ def set_input_files(self,
106
110
pkg .copy_adoc_src_dir = False
107
111
pkg .adoc_src_dir = in_file .parent
108
112
113
+ if python_dir :
114
+ pkg .python_dir = python_dir
115
+ else :
116
+ pkg .python_dir = pkg .adoc_src_dir
117
+
109
118
self .packages [Package .INPUT_PACKAGE_NAME ] = pkg
110
119
111
120
def collect (self ,
@@ -298,6 +307,14 @@ def make_document(self,
298
307
299
308
return doc
300
309
310
+ def python_paths (self ) -> List [Path ]:
311
+ """Get the paths containing python code to be included in the generated documents.
312
+
313
+ Returns:
314
+ A list of python paths. Can be empty.
315
+ """
316
+ return [pkg .python_dir for pkg in self .packages .values () if pkg .python_dir ]
317
+
301
318
def _warning_or_error (self , error : Exception ):
302
319
if self .warnings_are_errors :
303
320
raise error
0 commit comments