Bases: ProjectMetadataWriter
Fortran config file handler parsed from fpm.toml.
Source code in src/somesy/fortran/writer.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135 | class Fortran(ProjectMetadataWriter):
"""Fortran config file handler parsed from fpm.toml."""
def __init__(
self,
path: Path,
pass_validation: bool | None = False,
):
"""Fortran config file handler parsed from fpm.toml.
See [somesy.core.writer.ProjectMetadataWriter.__init__][].
"""
mappings: FieldKeyMapping = {
"authors": ["author"],
"maintainers": ["maintainer"],
"documentation": IgnoreKey(),
}
super().__init__(
path,
create_if_not_exists=False,
direct_mappings=mappings,
pass_validation=pass_validation,
)
@property
def authors(self):
"""Return the only author of the fpm.toml file as list."""
author = self._get_property(self._get_key("authors"))
return [author] if author else []
@authors.setter
def authors(self, authors: list[Person | Entity]) -> None:
"""Set the authors of the project."""
self._set_property(self._get_key("authors"), self._from_person(authors[0]))
@property
def maintainers(self):
"""Return the only author of the fpm.toml file as list."""
maintainers = self._get_property(self._get_key("maintainers"))
if maintainers:
return [self._get_property(self._get_key("maintainers"))]
return []
@maintainers.setter
def maintainers(self, maintainers: list[Person | Entity]) -> None:
"""Set the maintainers of the project."""
maintainer = self._from_person(maintainers[0])
self._set_property(self._get_key("maintainers"), maintainer)
def _load(self) -> None:
"""Load fpm.toml file."""
with open(self.path, encoding="utf-8") 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.
"""
if self.pass_validation:
return
config = dict(self._get_property([]))
logger.debug(
f"Validating config using {FortranConfig.__name__}: {pretty_repr(config)}"
)
FortranConfig(**config)
def save(self, path: Path | None = None) -> None:
"""Save the fpm file."""
path = path or self.path
format_toml_data(self._data)
with open(path, "w", encoding="utf-8") as f:
tomlkit.dump(self._data, f)
@staticmethod
def _from_person(person: Person | Entity):
"""Convert project metadata person/entity object to poetry string for person format "full name <email>."""
return person.to_name_email_string()
@staticmethod
def _to_person(person_obj: str) -> Person | Entity | None:
"""Convert from free string to person or entity object."""
return parse_name_email(person_obj)
def sync(self, metadata: ProjectMetadata) -> None:
"""Sync output file with other metadata files."""
if metadata.name is not None:
self.name = metadata.name
if metadata.description is not None:
self.description = metadata.description
if metadata.version:
self.version = metadata.version
if metadata.keywords:
self.keywords = metadata.keywords
if metadata.authors():
self.authors = metadata.authors()
maintainers = metadata.maintainers()
# set if not empty
if maintainers:
# only one maintainer is allowed
self.maintainers = maintainers
if licenses := metadata.license:
self.license = license_expression(licenses)
if metadata.homepage:
self.homepage = str(metadata.homepage)
|
authors
property
writable
Return the only author of the fpm.toml file as list.
maintainers
property
writable
Return the only author of the fpm.toml file as list.
__init__
__init__(path: Path, pass_validation: bool | None = False)
Fortran config file handler parsed from fpm.toml.
See somesy.core.writer.ProjectMetadataWriter.init.
Source code in src/somesy/fortran/writer.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 | def __init__(
self,
path: Path,
pass_validation: bool | None = False,
):
"""Fortran config file handler parsed from fpm.toml.
See [somesy.core.writer.ProjectMetadataWriter.__init__][].
"""
mappings: FieldKeyMapping = {
"authors": ["author"],
"maintainers": ["maintainer"],
"documentation": IgnoreKey(),
}
super().__init__(
path,
create_if_not_exists=False,
direct_mappings=mappings,
pass_validation=pass_validation,
)
|
save
save(path: Path | None = None) -> None
Save the fpm file.
Source code in src/somesy/fortran/writer.py
| def save(self, path: Path | None = None) -> None:
"""Save the fpm file."""
path = path or self.path
format_toml_data(self._data)
with open(path, "w", encoding="utf-8") as f:
tomlkit.dump(self._data, f)
|
sync
sync(metadata: ProjectMetadata) -> None
Sync output file with other metadata files.
Source code in src/somesy/fortran/writer.py
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135 | def sync(self, metadata: ProjectMetadata) -> None:
"""Sync output file with other metadata files."""
if metadata.name is not None:
self.name = metadata.name
if metadata.description is not None:
self.description = metadata.description
if metadata.version:
self.version = metadata.version
if metadata.keywords:
self.keywords = metadata.keywords
if metadata.authors():
self.authors = metadata.authors()
maintainers = metadata.maintainers()
# set if not empty
if maintainers:
# only one maintainer is allowed
self.maintainers = maintainers
if licenses := metadata.license:
self.license = license_expression(licenses)
if metadata.homepage:
self.homepage = str(metadata.homepage)
|