SourceFile
A Python source file component that represents a Python file in the source directory.
It provides a scope for the file, which is a PythonModuleScope
that contains
all the symbols defined in the file, such as functions, classes, and variables.
import { SourceFile } from "@alloy-js/python";
<SourceFile header={Children} headerComment="string" path="string"> {children}</SourceFile>
import { SourceFile } from "@alloy-js/python/stc";
SourceFile({ header: Children, headerComment: string, path: string,}).children(children)
children | optionalChildren Content to add to the file, such as function definitions, class definitions, and variable declarations. |
header | optionalChildren Header comment to add to the file, which will be rendered at the top of the file. |
headerComment | optionalstring Comment to add to the header, which will be rendered as a comment in the file. |
path | string The path to the file relative to the source directory. |
Example
Section titled “Example”<SourceFile path="test.py"> <FunctionDeclaration name="test" /></SourceFile>
renders to
def test(): pass