MCPcopy Index your code
hub / github.com/plotly/plotly.py / write_source_py

Function write_source_py

codegen/utils.py:20–46  ·  view source on GitHub ↗

Format Python source code and write to a file, creating parent directories as needed. Parameters ---------- py_source : str String containing valid Python source code. If string is empty, no file will be written. filepath : str Full path to the file

(py_source, filepath, leading_newlines=0)

Source from the content-addressed store, hash-verified

18# Source code utilities
19# =====================
20def write_source_py(py_source, filepath, leading_newlines=0):
21 """
22 Format Python source code and write to a file, creating parent
23 directories as needed.
24
25 Parameters
26 ----------
27 py_source : str
28 String containing valid Python source code. If string is empty,
29 no file will be written.
30 filepath : str
31 Full path to the file to be written
32 Returns
33 -------
34 None
35 """
36 if py_source:
37 # Make dir if needed
38 filedir = opath.dirname(filepath)
39 # The exist_ok kwarg is only supported with Python 3, but that's ok since
40 # codegen is only supported with Python 3 anyway
41 os.makedirs(filedir, exist_ok=True)
42
43 # Write file
44 py_source = "\n" * leading_newlines + py_source
45 with open(filepath, "at") as f:
46 f.write(py_source)
47
48
49def build_from_imports_py(rel_modules=(), rel_classes=(), init_extra=""):

Callers 4

write_figure_classesFunction · 0.90
write_datatype_pyFunction · 0.90
write_init_pyFunction · 0.85

Calls 1

writeMethod · 0.45

Tested by

no test coverage detected