Skip to content

Allow 'author' or 'authors' be optionally empty per PEP 621 #58

@holmboe

Description

@holmboe

Description

When the authors field is not set at all, or when setting the authors field to an empty string I get errors.

PEP 621 states (emphasis mine):

These fields accept an array of tables with 2 keys: name and email. Both values must be strings. The name value MUST be a valid email name (i.e. whatever can be put as a name, before an email, in RFC 822 and not contain commas. The email value MUST be a valid email address. Both keys are optional.

Steps to Reproduce

There are a few scenarios where the key "name" from PEP621 is not honored to be optional. I am building with "make latexpdf".

First scenario

Set pyproject.toml to (both author and authors are commented out):

[project]
name = "Mighty Document"
version = ""
description = ""
#author = ""

#[[project.authors]]
#name = ""

The error message is:

Traceback (most recent call last):
  File "/home/nn/.local/pipx/venvs/sphinx/lib/python3.11/site-packages/sphinx/config.py", line 529, in eval_config_file
    exec(code, namespace)  # NoQA: S102
    ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nn/code/gitlab.com/dynamist/dynamist-mighty-document/conf.py", line 35, in <module>
    config = SphinxConfig("pyproject.toml", globalns=globals())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nn/.local/pipx/venvs/sphinx/lib/python3.11/site-packages/sphinx_pyproject/__init__.py", line 162, in __init__
    raise BadConfigError(
dom_toml.parser.BadConfigError: Either 'authors/maintainers' was not declared in the 'project' table or it was marked as 'dynamic', which is unsupported by 'sphinx-pyproject'.

Second scenario

Set pyproject.toml to ('authors' is defined but empty):

[project]
name = "Mighty Document"
version = ""
description = ""

[[project.authors]]
name = ""

The error message is:

Traceback (most recent call last):
  File "/home/nn/.local/pipx/venvs/sphinx/lib/python3.11/site-packages/sphinx/config.py", line 529, in eval_config_file
    exec(code, namespace)  # NoQA: S102
    ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nn/code/gitlab.com/dynamist/dynamist-mighty-document/conf.py", line 35, in <module>
    config = SphinxConfig("pyproject.toml", globalns=globals())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nn/.local/pipx/venvs/sphinx/lib/python3.11/site-packages/sphinx_pyproject/__init__.py", line 149, in __init__
    pep621_config = parser_cls().parse(namespace)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nn/.local/pipx/venvs/sphinx/lib/python3.11/site-packages/sphinx_pyproject/__init__.py", line 313, in parse
    return super().parse(config)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nn/.local/pipx/venvs/sphinx/lib/python3.11/site-packages/dom_toml/parser.py", line 233, in parse
    parsed_config[key] = getattr(self, f"parse_{key.replace('-', '_')}")(config)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nn/.local/pipx/venvs/sphinx/lib/python3.11/site-packages/sphinx_pyproject/__init__.py", line 279, in parse_author
    raise BadConfigError(f"The 'project.authors' key cannot be empty.")
dom_toml.parser.BadConfigError: The 'project.authors' key cannot be empty.

Third scenario

Set pyproject.toml to ('author' is defined but empty):

[project]
name = "Mighty Document"
version = ""
description = ""
author = ""

The error message is:

Traceback (most recent call last):
  File "/home/nn/.local/pipx/venvs/sphinx/lib/python3.11/site-packages/sphinx/config.py", line 529, in eval_config_file
    exec(code, namespace)  # NoQA: S102
    ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nn/code/gitlab.com/dynamist/dynamist-mighty-document/conf.py", line 35, in <module>
    config = SphinxConfig("pyproject.toml", globalns=globals())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nn/.local/pipx/venvs/sphinx/lib/python3.11/site-packages/sphinx_pyproject/__init__.py", line 149, in __init__
    pep621_config = parser_cls().parse(namespace)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nn/.local/pipx/venvs/sphinx/lib/python3.11/site-packages/sphinx_pyproject/__init__.py", line 313, in parse
    return super().parse(config)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nn/.local/pipx/venvs/sphinx/lib/python3.11/site-packages/dom_toml/parser.py", line 233, in parse
    parsed_config[key] = getattr(self, f"parse_{key.replace('-', '_')}")(config)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nn/.local/pipx/venvs/sphinx/lib/python3.11/site-packages/sphinx_pyproject/__init__.py", line 279, in parse_author
    raise BadConfigError(f"The 'project.authors' key cannot be empty.")
dom_toml.parser.BadConfigError: The 'project.authors' key cannot be empty.

Actual result:

Se error messages above.

Expected result:

Undefined or empty "authors" fields should be accepted.

Reproduces how often:

Easily reproduced. Every time.

Version

  • Operating System: Ubuntu
  • Python: Python 3.11
  • Sphinx 8.1.3
  • sphinx-pyproject: 0.3.0

All Sphinx related tools and libraries are self-contained in a pipx environment.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingstale

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions