Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
holmboe opened this issue Dec 5, 2024 · 0 comments
Open

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

holmboe opened this issue Dec 5, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@holmboe
Copy link

holmboe commented Dec 5, 2024

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.

@holmboe holmboe added the bug Something isn't working label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants