Skip to content

Commit 4862c57

Browse files
committed
finderresults integration
1 parent 0e625ce commit 4862c57

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/pyscript/_generator.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33

44
import jinja2
55

6-
from ._node_parser import find_imports, Environment
6+
from ._node_parser import find_imports, FinderResult
77

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+
)
911

1012

1113
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
1315
) -> None:
1416
"""Write a Python script string to an HTML file template."""
1517
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
1820
else:
1921
modules = paths = ()
2022
with output_path.open("w") as fp:
@@ -23,9 +25,16 @@ def string_to_html(
2325
)
2426

2527

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+
"""
2835
output_path = output_path or input_path.with_suffix(".html")
29-
environment = find_imports(input_path)
36+
import_results = find_imports(input_path)
3037
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

Comments
 (0)