Generate a Python class file (.py) given a class string. Parameters ---------- typename props description namespace prop_reorder_exceptions Returns -------
(
typename,
props,
description,
namespace,
prop_reorder_exceptions=None,
max_props=None,
custom_typing_module="dash_prop_typing",
)
| 231 | |
| 232 | |
| 233 | def generate_class_file( |
| 234 | typename, |
| 235 | props, |
| 236 | description, |
| 237 | namespace, |
| 238 | prop_reorder_exceptions=None, |
| 239 | max_props=None, |
| 240 | custom_typing_module="dash_prop_typing", |
| 241 | ): |
| 242 | """Generate a Python class file (.py) given a class string. |
| 243 | Parameters |
| 244 | ---------- |
| 245 | typename |
| 246 | props |
| 247 | description |
| 248 | namespace |
| 249 | prop_reorder_exceptions |
| 250 | Returns |
| 251 | ------- |
| 252 | """ |
| 253 | |
| 254 | class_string = generate_class_string( |
| 255 | typename, |
| 256 | props, |
| 257 | description, |
| 258 | namespace, |
| 259 | prop_reorder_exceptions, |
| 260 | max_props, |
| 261 | custom_typing_module, |
| 262 | ) |
| 263 | |
| 264 | custom_imp = get_custom_imports(custom_typing_module) |
| 265 | custom_imp = custom_imp.get(typename) or custom_imp.get("*") |
| 266 | |
| 267 | if custom_imp: |
| 268 | imports = import_string.format( |
| 269 | custom_imports="\n" + "\n".join(custom_imp) + "\n\n" |
| 270 | ) |
| 271 | else: |
| 272 | imports = import_string.format(custom_imports="") |
| 273 | |
| 274 | file_name = f"{typename:s}.py" |
| 275 | |
| 276 | file_path = os.path.join(namespace, file_name) |
| 277 | with open(file_path, "w", encoding="utf-8") as f: |
| 278 | f.write(imports) |
| 279 | f.write(class_string) |
| 280 | |
| 281 | print(f"Generated {file_name}") |
| 282 | |
| 283 | |
| 284 | def generate_imports(project_shortname, components): |
nothing calls this directly
no test coverage detected
searching dependent graphs…