Skip to content

Commit eab8072

Browse files
committed
update to support poetry v2
1 parent 4722dc3 commit eab8072

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

src/somesy/pyproject/writer.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,19 @@ def __init__(
104104
self,
105105
path: Path,
106106
pass_validation: Optional[bool] = False,
107+
version: Optional[int] = 1,
107108
):
108109
"""Poetry config file handler parsed from pyproject.toml.
109110
110111
See [somesy.core.writer.ProjectMetadataWriter.__init__][].
111112
"""
113+
if version == 1:
114+
section = ["tool", "poetry"]
115+
else:
116+
section = ["project"]
112117
super().__init__(
113118
path,
114-
section=["tool", "poetry"],
119+
section=section,
115120
model_cls=PoetryConfig,
116121
pass_validation=pass_validation,
117122
)
@@ -230,14 +235,24 @@ def __init__(self, path: Path, pass_validation: Optional[bool] = False):
230235
data = load(f)
231236

232237
# inspect file to pick suitable project metadata writer
233-
if "project" in data:
238+
is_poetry = "tool" in data and "poetry" in data["tool"]
239+
has_project = "project" in data
240+
241+
if is_poetry:
242+
if has_project:
243+
logger.verbose(
244+
"Found Poetry 2.x metadata with project section in pyproject.toml"
245+
)
246+
else:
247+
logger.verbose("Found Poetry 1.x metadata in pyproject.toml")
248+
self.__wrapped__ = Poetry(
249+
path, pass_validation=pass_validation, version=2 if has_project else 1
250+
)
251+
elif has_project and not is_poetry:
234252
logger.verbose("Found setuptools-based metadata in pyproject.toml")
235253
self.__wrapped__ = SetupTools(path, pass_validation=pass_validation)
236-
elif "tool" in data and "poetry" in data["tool"]:
237-
logger.verbose("Found poetry-based metadata in pyproject.toml")
238-
self.__wrapped__ = Poetry(path, pass_validation=pass_validation)
239254
else:
240-
msg = "The pyproject.toml file is ambiguous, either add a [project] or [tool.poetry] section"
255+
msg = "The pyproject.toml file is ambiguous. For Poetry projects, ensure [tool.poetry] section exists. For setuptools, ensure [project] section exists without [tool.poetry]"
241256
raise ValueError(msg)
242257

243258
super().__init__(self.__wrapped__)

0 commit comments

Comments
 (0)