Skip to content

Commit

Permalink
Include NEWS from doc/release.rst and link issues/PRs
Browse files Browse the repository at this point in the history
Remove doc/release.rst's duplicate copy of the release notes, instead
including NEWS via a reStructuredText include directive. This means
that NEWS needs to be valid reStructuredText, but it mostly already is.

Install a Sphinx 7.2.5+ include-read hook that expands plain `PR #NNN`
and `#NNN` references in the NEWS file into role syntax that the extlinks
extension can expand into links to pysam issues/PRs at the GitHub repo.
  • Loading branch information
jmarshall committed Sep 21, 2023
1 parent f74371e commit 37b2cf0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 879 deletions.
8 changes: 2 additions & 6 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
An online version of the installation instructions can be found here:
http://pysam.readthedocs.io/en/latest/release.html

=============
Release notes
=============
.. An online version of the release history can be found here:
.. http://pysam.readthedocs.io/en/latest/release.html

Release 0.21.0
==============
Expand Down
24 changes: 23 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os, setuptools
import sys, os, re, setuptools

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand All @@ -29,6 +29,7 @@
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.extlinks',
'sphinx.ext.todo',
'sphinx.ext.ifconfig',
'sphinx.ext.intersphinx',
Expand Down Expand Up @@ -120,6 +121,27 @@
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []

# -- Rewrite "PR #NNN" and "#NNN" in NEWS as URL links -------------------------

extlinks = {
'issue': ('https://github.com/pysam-developers/pysam/issues/%s', '#%s'),
'pull': ('https://github.com/pysam-developers/pysam/pull/%s', 'PR #%s'),
}

def expand_github_references(text):
text = re.sub(r'PR\s*#(\d+)', r':pull:`\1`', text)
text = re.sub(r'#(\d+)', r':issue:`\1`', text)
return text

def include_read(app, relative_path, parent_docname, source):
if relative_path.name == 'NEWS':
source[0] = expand_github_references(source[0])

def setup(app):
try:
app.connect('include-read', include_read)
except:
pass # Sphinx is too old to link issues/PRs

# -- Options for HTML output ---------------------------------------------------

Expand Down
Loading

0 comments on commit 37b2cf0

Please sign in to comment.