Skip to content

Commit

Permalink
fix: add pakcage without peotry config [tool.poetry.build] script wou…
Browse files Browse the repository at this point in the history
…ld raise keyError (#1938)
  • Loading branch information
frostming authored May 19, 2023
1 parent bf8f6ee commit df0013f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions news/1935.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix format conversion error from Poetry when `tool.poetry.build` doesn't exist.
21 changes: 13 additions & 8 deletions src/pdm/formats/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,21 @@ def dev_dependencies(self, value: dict) -> None:

@convert_from()
def includes(self, source: dict[str, list[str] | str]) -> list[str]:
result: list[str] = []
includes: list[str] = []
source_includes: list[str] = []
for item in source.pop("packages", []):
assert isinstance(item, dict)
include = item["include"]
if item.get("from"):
include = f"{item.get('from')}/{include}"
result.append(include)
result.extend(source.pop("include", []))
self.settings.setdefault("build", {})["includes"] = result
includes.append(include)
for item in source.pop("include", []):
if not isinstance(item, dict):
includes.append(item)
else:
dest = source_includes if "sdist" in item.get("format", "") else includes
dest.append(item["path"])
self.settings.setdefault("build", {})["includes"] = includes
raise Unset()

@convert_from("exclude")
Expand All @@ -168,12 +174,11 @@ def excludes(self, value: list[str]) -> None:

@convert_from("build")
def build(self, value: str | dict) -> None:
run_setuptools = True
value = {}
if isinstance(value, dict):
if "generate-setup-file" in value:
run_setuptools = cast(bool, value["generate-setup-file"])
value = value["script"]
self.settings.setdefault("build", {}).update({"setup-script": value, "run-setuptools": run_setuptools})
value["run-setuptools"] = cast(bool, value["generate-setup-file"])
self.settings.setdefault("build", {}).update(value)
raise Unset()

@convert_from("source")
Expand Down

0 comments on commit df0013f

Please sign in to comment.