Skip to content

Commit

Permalink
Merge pull request #16 from webknjaz/patch-1
Browse files Browse the repository at this point in the history
Rewire generating Sphinx's settings to early `config-inited` event
  • Loading branch information
jaraco authored Apr 17, 2024
2 parents 5eedfe3 + 1f4985e commit b9def06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
20 changes: 10 additions & 10 deletions jaraco/packaging/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

def setup(app):
app.add_config_value('package_url', '', '')
app.connect('builder-inited', load_config_from_setup)
app.connect('builder-inited', configure_substitutions)
app.connect('config-inited', load_config_from_setup)
app.connect('config-inited', configure_substitutions)
app.connect('html-page-context', add_package_url)
app.add_directive("sidebar-links", SidebarLinksDirective)
return dict(version=metadata.version('jaraco.packaging'), parallel_read_safe=True)
Expand Down Expand Up @@ -107,17 +107,17 @@ def _load_metadata_from_wheel():
return dist.metadata


def load_config_from_setup(app):
def load_config_from_setup(app, config):
"""
Replace values in app.config from package metadata
"""
# for now, assume project root is one level up
root = os.path.join(app.confdir, '..')
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 = hunt_down_url(meta)
app.config.author = app.config.copyright = extract_author(meta)
config.project = meta['Name']
config.version = config.release = meta['Version']
config.package_url = hunt_down_url(meta)
config.author = config.copyright = extract_author(meta)


def hunt_down_url(meta):
Expand All @@ -139,9 +139,9 @@ def extract_author(meta):
return meta['Author'] or re.search(r'"(.+)"', meta['Author-email']).group(1)


def configure_substitutions(app):
epilogs = app.config.rst_epilog, f'.. |project| replace:: {app.config.project}'
app.config.rst_epilog = '\n'.join(filter(None, epilogs))
def configure_substitutions(app, config):
epilogs = config.rst_epilog, f'.. |project| replace:: {config.project}'
config.rst_epilog = '\n'.join(filter(None, epilogs))


def add_package_url(app, pagename, templatename, context, doctree):
Expand Down
1 change: 1 addition & 0 deletions newsfragments/16.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Configure Sphinx earlier in 'config-inited', allowing other etxensions to rely on the produced values.

0 comments on commit b9def06

Please sign in to comment.