From d24ecec9c22fee178fe4121aabdd8c3e743e8411 Mon Sep 17 00:00:00 2001 From: ric-evans Date: Fri, 31 May 2024 11:26:07 -0400 Subject: [PATCH] fix `authors` --- pyproject_toml_builder.py | 52 ++++++++++++++++------------ tests/test_pyproject_toml_builder.py | 6 ++-- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/pyproject_toml_builder.py b/pyproject_toml_builder.py index 42f3005..3ffa1b8 100644 --- a/pyproject_toml_builder.py +++ b/pyproject_toml_builder.py @@ -114,25 +114,28 @@ class GHAInput: author: str = "" author_email: str = "" - # def __post_init__(self) -> None: - # if self.pypi_name: - # if not self.keywords or not self.author or not self.author_email: - # raise Exception( - # "'keywords', 'author', and 'author_email' must be provided when " - # "'pypi_name' is `True`" - # ) - # for major, attr_name in [ - # (self.python_min[0], "python_min"), - # (self.python_max[0], "python_max"), - # ]: - # if major < 3: - # raise Exception( - # f"Python-release automation ('{attr_name}') does not work for python <3." - # ) - # elif major >= 4: - # raise Exception( - # f"Python-release automation ('{attr_name}') does not work for python 4+." - # ) + def __post_init__(self) -> None: + # pypi-related metadata + if self.pypi_name: + if not self.keywords or not self.author or not self.author_email: + raise Exception( + "'keywords', 'author', and 'author_email' must be provided when " + "'pypi_name' is `True`" + ) + + # validate python min/max + for major, attr_name in [ + (self.python_min[0], "python_min"), + (self.python_max[0], "python_max"), + ]: + if major < 3: + raise Exception( + f"Python-release automation ('{attr_name}') does not work for python <3." + ) + elif major >= 4: + raise Exception( + f"Python-release automation ('{attr_name}') does not work for python 4+." + ) def get_requires_python(self) -> str: """Get a `[project]/python_requires` string from `self.python_range`. @@ -412,10 +415,13 @@ def _build_out_sections( if not gha_input.pypi_name: toml_dict["project"]["name"] = "_".join(ffile.packages).replace("_", "-") # add the following if they were given: - if gha_input.author: - toml_dict["project"]["author"] = gha_input.author - if gha_input.author_email: - toml_dict["project"]["author_email"] = gha_input.author_email + if gha_input.author and gha_input.author_email: + toml_dict["project"]["authors"] = [ + { + "name": gha_input.author, + "email": gha_input.author_email, + } + ] if gha_input.keywords: toml_dict["project"]["keywords"] = gha_input.keywords # if we DO want PyPI, then include everything: diff --git a/tests/test_pyproject_toml_builder.py b/tests/test_pyproject_toml_builder.py index 69b54bb..3ab1ffc 100644 --- a/tests/test_pyproject_toml_builder.py +++ b/tests/test_pyproject_toml_builder.py @@ -91,8 +91,7 @@ VANILLA_PROJECT_KEYVALS = { **VANILLA_SECTIONS_IN["project"], "url": "https://github.com/foobarbaz-org/foobarbaz-repo", - "author": AUTHOR, - "author_email": AUTHOR_EMAIL, + "authors": [{"name": AUTHOR, "email": AUTHOR_EMAIL}], "description": "Ceci n’est pas une pipe", "readme": "README.md", "license": {"file": "LICENSE"}, @@ -641,8 +640,7 @@ def test_34_package_dirs__multi_autoname__no_pypi( "project": { "name": "mock-package-another-one", **NO_PYPI_VANILLA_PROJECT_KEYVALS, # the true minimum is more vanilla than vanilla - "author": AUTHOR, - "author_email": AUTHOR_EMAIL, + "authors": [{"name": AUTHOR, "email": AUTHOR_EMAIL}], "keywords": [ "python", "REST",