MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / generated_wrapper

Function generated_wrapper

methods.py:1563–1591  ·  view source on GitHub ↗

Wrapper class to automatically handle copyright headers and header guards for generated scripts. Meant to be invoked via `with` statement similar to creating a file. - `path`: The path of the file to be created. - `guard`: Optional bool to determine if `#pragma once` should be

(
    path: str,
    guard: Optional[bool] = None,
)

Source from the content-addressed store, hash-verified

1561
1562@contextlib.contextmanager
1563def generated_wrapper(
1564 path: str,
1565 guard: Optional[bool] = None,
1566) -> Generator[TextIOBase, None, None]:
1567 """
1568 Wrapper class to automatically handle copyright headers and header guards
1569 for generated scripts. Meant to be invoked via `with` statement similar to
1570 creating a file.
1571
1572 - `path`: The path of the file to be created.
1573 - `guard`: Optional bool to determine if `#pragma once` should be added. If
1574 unassigned, the value is determined by file extension.
1575 """
1576
1577 with open(path, "wt", encoding="utf-8", newline="\n") as file:
1578 if not path.endswith(".out"): # For test output, we only care about the content.
1579 file.write(generate_copyright_header(path))
1580 file.write("\n/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n\n")
1581
1582 if guard is None:
1583 guard = path.endswith((".h", ".hh", ".hpp", ".hxx", ".inc"))
1584 if guard:
1585 file.write("#pragma once\n\n")
1586
1587 with StringIO(newline="\n") as str_io:
1588 yield str_io
1589 file.write(str_io.getvalue().strip() or "/* NO CONTENT */")
1590
1591 file.write("\n")
1592
1593
1594def get_buffer(path: str) -> bytes:

Callers 3

build_rd_headerFunction · 0.90
build_raw_headerFunction · 0.90
build_gles3_headerFunction · 0.90

Calls 3

stripMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected