Skip to content

Commit

Permalink
Add support for other metadata fields since pyproject.toml shuffles t…
Browse files Browse the repository at this point in the history
…hings around.

Closes #17.
  • Loading branch information
jaraco committed Apr 17, 2024
1 parent 25a0b02 commit 0c66eaf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
24 changes: 22 additions & 2 deletions jaraco/packaging/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

import os
import re
import warnings
from importlib import metadata
from typing import ClassVar
Expand Down Expand Up @@ -115,8 +116,27 @@ def load_config_from_setup(app):
meta = _load_metadata_from_wheel() or load(root)
app.config.project = meta['Name']
app.config.version = app.config.release = meta['Version']
app.config.package_url = meta['Home-page']
app.config.author = app.config.copyright = meta['Author']
app.config.package_url = hunt_down_url(meta)
app.config.author = app.config.copyright = extract_author(meta)


def hunt_down_url(meta):
"""
Given project metadata, figure out what the package URL is.
"""
return meta['Home-page'] or get_best(meta.get_all('Project-URL'))


def get_best(project_urls):
lookup = dict(url.split(', ') for url in project_urls)
return lookup.get('Source') or lookup.get('Homepage')


def extract_author(meta):
"""
Given project metadata, figure out who the author is.
"""
return meta['Author'] or re.search(r'"(.+)"', meta['Author-email']).group(1)


def configure_substitutions(app):
Expand Down
1 change: 1 addition & 0 deletions newsfragments/17.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for other metadata fields since pyproject.toml shuffles things around.

0 comments on commit 0c66eaf

Please sign in to comment.