Skip to content

writer

Julia writer.

Julia

Bases: ProjectMetadataWriter

Julia config file handler parsed from Project.toml.

Source code in src/somesy/julia/writer.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class Julia(ProjectMetadataWriter):
    """Julia config file handler parsed from Project.toml."""

    def __init__(self, path: Path):
        """Julia config file handler parsed from Project.toml.

        See [somesy.core.writer.ProjectMetadataWriter.__init__][].
        """
        super().__init__(path, create_if_not_exists=False)

    def _load(self) -> None:
        """Load Project.toml file."""
        with open(self.path) as f:
            self._data = tomlkit.load(f)

    def _validate(self) -> None:
        """Validate poetry config using pydantic class.

        In order to preserve toml comments and structure, tomlkit library is used.
        Pydantic class only used for validation.
        """
        config = dict(self._get_property([]))
        logger.debug(
            f"Validating config using {JuliaConfig.__name__}: {pretty_repr(config)}"
        )
        JuliaConfig(**config)

    def save(self, path: Optional[Path] = None) -> None:
        """Save the julia file."""
        path = path or self.path
        with open(path, "w") as f:
            tomlkit.dump(self._data, f)

    @staticmethod
    def _from_person(person: Person):
        """Convert project metadata person object to a name+email string."""
        return person.to_name_email_string()

    @staticmethod
    def _to_person(person_obj) -> Optional[Person]:
        """Parse name+email string to a Person."""
        try:
            return Person.from_name_email_string(person_obj)
        except (ValueError, AttributeError):
            logger.warning(f"Cannot convert {person_obj} to Person object.")
            return None

    def sync(self, metadata: ProjectMetadata) -> None:
        """Sync output file with other metadata files."""
        # overridden to not sync fields that are not present in the Project.toml file
        self.name = metadata.name
        self.version = metadata.version

        self._sync_authors(metadata)

__init__

__init__(path: Path)

Julia config file handler parsed from Project.toml.

See somesy.core.writer.ProjectMetadataWriter.init.

Source code in src/somesy/julia/writer.py
21
22
23
24
25
26
def __init__(self, path: Path):
    """Julia config file handler parsed from Project.toml.

    See [somesy.core.writer.ProjectMetadataWriter.__init__][].
    """
    super().__init__(path, create_if_not_exists=False)

save

save(path: Optional[Path] = None) -> None

Save the julia file.

Source code in src/somesy/julia/writer.py
45
46
47
48
49
def save(self, path: Optional[Path] = None) -> None:
    """Save the julia file."""
    path = path or self.path
    with open(path, "w") as f:
        tomlkit.dump(self._data, f)

sync

sync(metadata: ProjectMetadata) -> None

Sync output file with other metadata files.

Source code in src/somesy/julia/writer.py
65
66
67
68
69
70
71
def sync(self, metadata: ProjectMetadata) -> None:
    """Sync output file with other metadata files."""
    # overridden to not sync fields that are not present in the Project.toml file
    self.name = metadata.name
    self.version = metadata.version

    self._sync_authors(metadata)