Skip to content

Commit d94afdf

Browse files
committed
Integration of parsing results and new Warning msg
Warning message is now generated (in yellow) when the converted Python module contains unsupported packages or local modules (as in packages)
1 parent 4862c57 commit d94afdf

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/pyscript/cli.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ def __init__(self, msg: str, *args: Any, **kwargs: Any):
6363
super().__init__(*args, **kwargs)
6464

6565

66+
class Warning(typer.Exit):
67+
def __init__(self, msg: str, *args: Any, **kwargs: Any):
68+
console.print(msg, style="yellow")
69+
super().__init__(*args, **kwargs)
70+
71+
6672
@app.command()
6773
def wrap(
6874
input_file: Optional[Path] = _input_file_argument,
@@ -94,7 +100,18 @@ def wrap(
94100
raise Abort("Must provide an output file or use `--show` option")
95101

96102
if input_file is not None:
97-
file_to_html(input_file, title, output)
103+
parsing_res = file_to_html(input_file, title, output)
104+
if parsing_res is not None:
105+
msg_template = "WARNING: The input file contains some imports which are not currently supported PyScript.\nTherefore the code might not work, or require some changes.{packages}{locals}"
106+
msg = msg_template.format(
107+
packages=f"\n{str(parsing_res.unsupported_packages)}"
108+
if parsing_res.unsupported_packages
109+
else "",
110+
locals=f"\n{str(parsing_res.unsupported_paths)}"
111+
if parsing_res.unsupported_paths
112+
else "",
113+
)
114+
raise Warning(msg=msg)
98115

99116
if command:
100117
string_to_html(command, title, output)

0 commit comments

Comments
 (0)