Skip to content

Commit d1154cb

Browse files
committed
fix license mapping and synchronization
1 parent e610897 commit d1154cb

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/somesy/pyproject/writer.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from rich.pretty import pretty_repr
1010
from tomlkit import load
1111

12-
from somesy.core.models import Person
12+
from somesy.core.models import Person,ProjectMetadata
1313
from somesy.core.writer import ProjectMetadataWriter
1414

1515
from .models import PoetryConfig, SetuptoolsConfig
@@ -122,6 +122,7 @@ def __init__(self, path: Path):
122122
mappings = {
123123
"homepage": ["urls", "homepage"],
124124
"repository": ["urls", "repository"],
125+
"license": ["license", "text"],
125126
}
126127
super().__init__(
127128
path, section=section, direct_mappings=mappings, model_cls=SetuptoolsConfig
@@ -145,6 +146,17 @@ def _to_person(person_obj) -> Person:
145146
"email": person_obj["email"].strip(),
146147
}
147148
)
149+
150+
151+
def sync(self, metadata: ProjectMetadata) -> None:
152+
"""Sync metadata with pyproject.toml file and fix license field."""
153+
super().sync(metadata)
154+
155+
# if license field has both text and file, remove file
156+
if self._get_property(["license", "file"]) is not None and self._get_property(["license", "text"]) is not None:
157+
# delete license file property
158+
self._data["project"]["license"].pop("file")
159+
logger.debug("Removed license file from pyproject.toml")
148160

149161

150162
# ----

0 commit comments

Comments
 (0)