Skip to content

File

FileWriter

Bases: WriterBase

Source code in src/writer/file.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class FileWriter(WriterBase):
    def __init__(self, out_path: str | Path, exclude: str, indent: None | int = None):
        """
        :param out_path:
        :param exclude: String of a dict of fields to exclude
        :param indent:
        """
        super().__init__()
        self.out_path = Path(out_path)
        self.exclude = json.loads(exclude)
        self.indent = indent

    def write(self, project: Project):
        project_dict = project.model_dump_json(exclude=self.exclude, indent=self.indent)

        out_file = self.out_path.joinpath(f'{project.name}.json')

        with open(out_file, 'wt') as outf:
            outf.write(project_dict)

    def write_bulk(self, projects: List[Project]):
        for project in projects:
            self.write(project)

__init__(out_path, exclude, indent=None)

Parameters:

Name Type Description Default
out_path str | Path
required
exclude str

String of a dict of fields to exclude

required
indent None | int
None
Source code in src/writer/file.py
10
11
12
13
14
15
16
17
18
19
def __init__(self, out_path: str | Path, exclude: str, indent: None | int = None):
    """
    :param out_path:
    :param exclude: String of a dict of fields to exclude
    :param indent:
    """
    super().__init__()
    self.out_path = Path(out_path)
    self.exclude = json.loads(exclude)
    self.indent = indent