Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3832.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not write null values into the generated `pyproject.toml` when importing a flit project that omits `author-email`/`maintainer-email` or sets only one of `include` and `exclude` in `[tool.flit.sdist]`.
14 changes: 9 additions & 5 deletions src/pdm/formats/flit.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ def check_fingerprint(project: Project | None, filename: PathLike) -> bool:


def _get_author(metadata: dict[str, Any], type_: str = "author") -> list[str]:
name = metadata.pop(type_)
author = {"name": metadata.pop(type_)}
email = metadata.pop(f"{type_}-email", None)
return cast(list[str], array_of_inline_tables([{"name": name, "email": email}]))
if email is not None:
author["email"] = email
return cast(list[str], array_of_inline_tables([author]))


def get_docstring_and_version_via_ast(
Expand Down Expand Up @@ -137,9 +139,11 @@ def entry_points(self, value: dict[str, dict[str, str]]) -> dict[str, dict[str,

@convert_from("sdist")
def includes(self, value: dict[str, list[str]]) -> None:
self.settings.setdefault("build", {}).update(
{"excludes": value.get("exclude"), "includes": value.get("include")}
)
build = self.settings.setdefault("build", {})
if "exclude" in value:
build["excludes"] = value["exclude"]
if "include" in value:
build["includes"] = value["include"]
raise Unset()


Expand Down
32 changes: 32 additions & 0 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,38 @@ def test_convert_flit(project):
assert build["excludes"] == ["doc/*.html"]


def test_convert_flit_author_and_maintainer_without_email(project, tmp_path):
pyproject_file = tmp_path / "pyproject.toml"
pyproject_file.write_text(
'[tool.flit.metadata]\nmodule = "flit"\nauthor = "Thomas Kluyver"\nmaintainer = "Frost Ming"\n',
encoding="utf-8",
)
result, _ = flit.convert(project, pyproject_file, None)

assert result["authors"] == [{"name": "Thomas Kluyver"}]
assert result["maintainers"] == [{"name": "Frost Ming"}]


@pytest.mark.parametrize(
"sdist_table,expected_build",
[
('include = ["doc/"]', {"includes": ["doc/"]}),
('exclude = ["doc/*.html"]', {"excludes": ["doc/*.html"]}),
],
)
def test_convert_flit_sdist_with_one_of_include_and_exclude(project, tmp_path, sdist_table, expected_build):
pyproject_file = tmp_path / "pyproject.toml"
pyproject_file.write_text(
'[tool.flit.metadata]\nmodule = "flit"\nauthor = "Thomas Kluyver"\n'
'author-email = "thomas@kluyver.me.uk"\n\n'
f"[tool.flit.sdist]\n{sdist_table}\n",
encoding="utf-8",
)
_, settings = flit.convert(project, pyproject_file, None)

assert settings["build"] == expected_build


def test_convert_error_preserve_metadata(project):
pyproject_file = FIXTURES / "poetry-error.toml"
try:
Expand Down
Loading