3
3
4
4
import jinja2
5
5
6
- from ._node_parser import find_imports , Environment
6
+ from ._node_parser import find_imports , FinderResult
7
7
8
- _env = jinja2 .Environment (loader = jinja2 .PackageLoader ("pyscript" ), trim_blocks = True , lstrip_blocks = True )
8
+ _env = jinja2 .Environment (
9
+ loader = jinja2 .PackageLoader ("pyscript" ), trim_blocks = True , lstrip_blocks = True
10
+ )
9
11
10
12
11
13
def string_to_html (
12
- input_str : str , title : str , output_path : Path , env : Environment = None
14
+ input_str : str , title : str , output_path : Path , pyenv : FinderResult = None
13
15
) -> None :
14
16
"""Write a Python script string to an HTML file template."""
15
17
template = _env .get_template ("basic.html" )
16
- if env is not None :
17
- modules , paths = env .packages , env .paths
18
+ if pyenv is not None :
19
+ modules , paths = pyenv .packages , pyenv .paths
18
20
else :
19
21
modules = paths = ()
20
22
with output_path .open ("w" ) as fp :
@@ -23,9 +25,16 @@ def string_to_html(
23
25
)
24
26
25
27
26
- def file_to_html (input_path : Path , title : str , output_path : Optional [Path ]) -> None :
27
- """Write a Python script string to an HTML file template."""
28
+ def file_to_html (
29
+ input_path : Path , title : str , output_path : Optional [Path ]
30
+ ) -> Optional [FinderResult ]:
31
+ """Write a Python script string to an HTML file template.
32
+
33
+ Warnings will be returned when scanning for environment, if any.
34
+ """
28
35
output_path = output_path or input_path .with_suffix (".html" )
29
- environment = find_imports (input_path )
36
+ import_results = find_imports (input_path )
30
37
with input_path .open ("r" ) as fp :
31
- string_to_html (fp .read (), title , output_path , env = environment )
38
+ string_to_html (fp .read (), title , output_path , pyenv = import_results )
39
+ if import_results .has_warnings :
40
+ return import_results
0 commit comments