Skip to content

Commit cc39ed3

Browse files
committed
continued implementing XML wrapper
1 parent e546379 commit cc39ed3

3 files changed

Lines changed: 280 additions & 58 deletions

File tree

src/somesy/core/writer.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ def _get_property(
123123

124124
if remove:
125125
seq.pop()
126-
logger.debug("remove in")
127-
logger.debug(seq[-1])
128126
del seq[-1][key_path[-1]] # remove leaf value
129127
# clean up the tree
130128
for key, dct in reversed(list(zip(key_path[:-1], seq[:-1]))):
@@ -339,6 +337,17 @@ def maintainers(self, maintainers: List[Person]) -> None:
339337
maintainers = [self._from_person(c) for c in maintainers]
340338
self._set_property(self._get_key("maintainers"), maintainers)
341339

340+
@property
341+
def contributors(self):
342+
"""Return the contributors of the project."""
343+
return self._get_property(self._get_key("contributors"))
344+
345+
@contributors.setter
346+
def contributors(self, contributors: List[Person]) -> None:
347+
"""Set the contributors of the project."""
348+
contributors = [self._from_person(c) for c in contributors]
349+
self._set_property(self._get_key("contributors"), contributors)
350+
342351
@property
343352
def keywords(self) -> Optional[List[str]]:
344353
"""Return the keywords of the project."""

src/somesy/pom_xml/writer.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ def __init__(
2929
3030
See [somesy.core.writer.ProjectMetadataWriter.__init__][].
3131
"""
32-
mappings: FieldKeyMapping = None
33-
# {
34-
# "name": ["title"],
35-
# "description": ["abstract"],
36-
# "homepage": ["url"],
37-
# "repository": ["repository-code"],
38-
# "documentation": IgnoreKey(),
39-
# "maintainers": ["contact"],
40-
# }
32+
mappings: FieldKeyMapping = {
33+
"year": ["inceptionYear"],
34+
"license": ["licenses", "license"],
35+
"homepage": ["url"],
36+
"project_slug": ["artifactId"],
37+
"authors": ["developers", "developer"],
38+
"contributors": ["contributors", "contributor"],
39+
}
4140
super().__init__(
4241
path, create_if_not_exists=create_if_not_exists, direct_mappings=mappings
4342
)
4443

4544
def _init_new_file(self):
4645
"""Initialize new pom.xml file."""
4746
pom = XMLProxy(ET.Element("project", POM_ROOT_ATRS))
47+
pom["properties"] = {"info.versionScheme": "semver-spec"}
4848
pom.write(self.path, default_namespace=POM_URL)
4949

5050
def _load(self):
@@ -63,9 +63,24 @@ def save(self, path: Optional[Path] = None) -> None:
6363
@staticmethod
6464
def _from_person(person: Person):
6565
"""Convert project metadata person object to cff dict for person format."""
66-
raise NotImplementedError
66+
ret = {}
67+
person_id = person.orcid or person.to_name_email_string()
68+
ret["id"] = person_id
69+
ret["name"] = person.name
70+
ret["email"] = person.email
71+
if person.orcid:
72+
ret["url"] = person.orcid
73+
if person.contribution_types:
74+
ret["roles"] = dict(role=person.contribution_types)
75+
return ret
6776

6877
@staticmethod
6978
def _to_person(person_obj) -> Person:
7079
"""Parse CFF Person to a somesy Person."""
80+
return Person(
81+
name=person_obj["name"],
82+
email=person_obj["email"],
83+
orcid=person_obj["orcid"],
84+
contribution_types=person_obj["roles"]["role"],
85+
)
7186
raise NotImplementedError

0 commit comments

Comments
 (0)