Skip to content

Commit

Permalink
fix authors
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-evans committed May 31, 2024
1 parent 052d8f4 commit d24ecec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
52 changes: 29 additions & 23 deletions pyproject_toml_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions tests/test_pyproject_toml_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit d24ecec

Please sign in to comment.