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

Sync notebook github links in HTML docs to the git commit used to build them #3080

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# Thus, any C-extensions that are needed to build the documentation will *not*
# be accessible, and the documentation will not build correctly.

import subprocess
import sys
import datetime

Expand Down Expand Up @@ -145,9 +146,23 @@
version = '.'.join(release.split('.')[:2])

extensions += ['sphinx.ext.extlinks', 'sphinx_design'] # noqa: F405
gh_tag = f'v{release}' if '.dev' not in release else 'main'
extlinks = {'gh-tree': (f'https://github.com/spacetelescope/jdaviz/tree/{gh_tag}/%s', '%s'),
'gh-notebook': (f'https://github.com/spacetelescope/jdaviz/blob/{gh_tag}/notebooks/%s.ipynb', '%s notebook')} # noqa: E501

# get the most recent git commit hash at build time:
commit_hash = subprocess.run(
# git call for the latest commit hash:
'git rev-parse HEAD'.split(),
capture_output=True
).stdout.decode().strip()

# inject the most recent commit hash into the github links used in `sample_notebooks.rst`:
extlinks = {
'gh-tree': (
f'https://github.com/spacetelescope/jdaviz/tree/{commit_hash}/%s', '%s'
),
'gh-notebook': (
f'https://github.com/spacetelescope/jdaviz/blob/{commit_hash}/notebooks/%s.ipynb', '%s notebook'
)
}

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

Expand Down
Loading