Skip to content

Commit

Permalink
A small change in viselements, one giant leap for step_viselements (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienLelaquais authored Sep 25, 2024
1 parent b42b641 commit e83f9f0
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions tools/_setup_generation/step_viselements.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,17 @@ def build_doc(property: str, desc, indent: int):
default_value = (
f'{desc["default_value"]}' if "default_value" in desc else ""
)
if m := re.match(r"^(<i>.*?</i>)$", default_value):
if m := re.match(r"^(<(\w+)>.*?</\2>)$", default_value):
default_value = f'"{m[1]}"'
elif m := re.match(r"^`(.*?)`$", default_value):
default_value = f"{m[1]}"
elif default_value == "scatter" or default_value == "lines+markers":
default_value = f'"{default_value}"'
if default_value:
try:
_ = eval(default_value)
except Exception:
raise SyntaxError(
f"Default value for property '{property}' of element '{element_type}' is "
f"not a valid Python expression ({default_value})"
)
if "lambda" not in default_value:
print(
f"WARNING: Default value for property '{property}' of element "
f"'{element_type}' is not a valid Python expression ({default_value})"
)
return (
f"{property}={default_value if default_value else 'None'}, ",
f"{indent*' '}{desc['name']} ({type}){dynamic}: {doc}\n",
Expand Down Expand Up @@ -533,21 +530,21 @@ def html_value(property: str, value: str, type: str) -> str:
new_documentation += f"{html_2}\n ```\n"
# Page Builder syntax "^$"
BP_IDX_PROP_RE = re.compile(r"^(.*?)\[([\w\d]+)\]$", re.M)
generate_page_builer_api = True
generate_page_builder_api = True
pb_properties = []
for n, v, t in properties:
if "[" in n:
if (idx_prop_match := BP_IDX_PROP_RE.match(n)) is None:
print(
f"WARNING - Property '{n}' in examples for {type} prevents Python code generation"
)
generate_page_builer_api = False
generate_page_builder_api = False
else:
pname = f"{idx_prop_match[1]}__{idx_prop_match[2]}"
pb_properties.append((pname, v, t))
else:
pb_properties.append((n, v, t))
if generate_page_builer_api:
if generate_page_builder_api:
new_documentation += '\n === "Python"\n\n'
new_documentation += " ```python\n"
new_documentation += (
Expand Down

0 comments on commit e83f9f0

Please sign in to comment.