jaraco / jaraco.packaging

MIT License
4 stars 4 forks source link

After porting to pyproject.toml, rst.linker fails with error in Sphinx #17

Closed jaraco closed 2 months ago

jaraco commented 2 months ago

In https://github.com/jaraco/tempora/actions/runs/8714844379/job/23905742259, the docs build is failing and it implicates rst.linker. Passing -v to the sphinx build provides more context:

docs: commands[0] /Users/jaraco/code/jaraco/tempora/docs> python -m sphinx -W --keep-going . /Users/jaraco/code/jaraco/tempora/build/html -v
Running Sphinx v7.3.3
loading pickled environment... done

Traceback (most recent call last):
  File "/Users/jaraco/code/jaraco/tempora/.tox/docs/lib/python3.12/site-packages/sphinx/events.py", line 97, in emit
    results.append(listener.handler(self.app, *args))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/jaraco/tempora/.tox/docs/lib/python3.12/site-packages/rst/linker.py", line 211, in make_links
    replacer = Replacer.from_definition(defn, config_dict(app.config))
                                              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/jaraco/tempora/.tox/docs/lib/python3.12/site-packages/rst/linker.py", line 203, in config_dict
    return dict((key, getattr(config, key)) for key in config.values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/jaraco/tempora/.tox/docs/lib/python3.12/site-packages/rst/linker.py", line 203, in <genexpr>
    return dict((key, getattr(config, key)) for key in config.values)
                      ^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/jaraco/tempora/.tox/docs/lib/python3.12/site-packages/sphinx/config.py", line 412, in __getattr__
    return default(self)
           ^^^^^^^^^^^^^
  File "/Users/jaraco/code/jaraco/tempora/.tox/docs/lib/python3.12/site-packages/sphinx/builders/latex/__init__.py", line 517, in default_latex_documents
    author = texescape.escape(config.author, config.latex_engine)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/jaraco/tempora/.tox/docs/lib/python3.12/site-packages/sphinx/util/texescape.py", line 110, in escape
    return s.translate(_tex_escape_map)
           ^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'translate'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/jaraco/code/jaraco/tempora/.tox/docs/lib/python3.12/site-packages/sphinx/cmd/build.py", line 332, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jaraco/code/jaraco/tempora/.tox/docs/lib/python3.12/site-packages/sphinx/application.py", line 268, in __init__
    self._init_builder()
  File "/Users/jaraco/code/jaraco/tempora/.tox/docs/lib/python3.12/site-packages/sphinx/application.py", line 339, in _init_builder
    self.events.emit('builder-inited')
  File "/Users/jaraco/code/jaraco/tempora/.tox/docs/lib/python3.12/site-packages/sphinx/events.py", line 108, in emit
    raise ExtensionError(
sphinx.errors.ExtensionError: Handler <function make_links at 0x104fa7ba0> for event 'builder-inited' threw an exception (exception: 'NoneType' object has no attribute 'translate')

Extension error (rst.linker):
Handler <function make_links at 0x104fa7ba0> for event 'builder-inited' threw an exception (exception: 'NoneType' object has no attribute 'translate')
docs: exit 2 (1.84 seconds) /Users/jaraco/code/jaraco/tempora/docs> python -m sphinx -W --keep-going . /Users/jaraco/code/jaraco/tempora/build/html -v pid=77376
  docs: FAIL code 2 (2.84=setup[1.01]+cmd[1.84] seconds)
  evaluation failed :( (2.88 seconds)
jaraco commented 2 months ago

The key that's causing the issue is latex_documents.

jaraco commented 2 months ago

Creating an empty setup.cfg doesn't help.

jaraco commented 2 months ago

Creating a setup.cfg with this content fixes the issue:

[metadata]
name = tempora
author = Jason R. Coombs
url = https://github.com/jaraco/tempora

Removing one of those keys but leaving others produces different obscure errors, suggesting the issue might actually be in jaraco.packaging.

jaraco commented 2 months ago

Indeed, removing jaraco.packaging and the things that rely on it also bypasses the issue, so the issue must be there.

jaraco commented 2 months ago

It seems that app.config.package_url and app.config.author (and copyright) are getting set to None.

jaraco commented 2 months ago

Aha. So switching from setup.cfg to pyproject.toml has changed the metadata.

 tempora 822773b @ pip-run build -- -c "from build import util; print(util.project_wheel_metadata('.'))" | head
Metadata-Version: 2.1
Name: tempora
Version: 5.5.2.dev11+g822773b
Summary: Objects and routines pertaining to date and time (tempora)
Home-page: https://github.com/jaraco/tempora
Author: Jason R. Coombs
Author-email: jaraco@jaraco.com
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
 tempora 822773b @ git checkout main
Previous HEAD position was 822773b Merge https://github.com/jaraco/skeleton
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
 tempora main @ pip-run build -- -c "from build import util; print(util.project_wheel_metadata('.'))" | head
Metadata-Version: 2.1
Name: tempora
Version: 5.5.2.dev12+ge2e8ef9
Summary: Objects and routines pertaining to date and time (tempora)
Author-email: "Jason R. Coombs" <jaraco@jaraco.com>
Project-URL: Homepage, https://github.com/jaraco/tempora
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
jaraco commented 2 months ago

Man, core metadata is a mess. There's no obvious place to find the author's name nor the project URL. If I want to get a URL suitable for setting "package_url", I can't, because every URL is keyed on free-text that any package author could supply (or not).

jaraco commented 2 months ago

Half of the problem is described at https://github.com/pypa/packaging-problems/issues/606. It hints that Setuptools might auto-convert some URLs, but that's apparently not the case.

The work in https://github.com/python/cpython/issues/108580 would help here to have some re-usable ways to parse author/maintainer fields.