-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #348 from MikhailRyazanov/offline
Offline HTML (1st iteration)
- Loading branch information
Showing
13 changed files
with
417 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ sphinx: | |
# Also build downloadable PDF | ||
formats: | ||
- htmlzip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
Helper script to generate the doi.rst file with the Zenodo DOI corresponding | ||
to current PyAbel version (if possible, otherwise the default "latest" DOI). | ||
""" | ||
|
||
ver = 'v' + release | ||
doi_file = 'doi.rst' | ||
try: | ||
# check current file | ||
with open(doi_file, 'r') as f: | ||
if ' ' + ver + '\n' not in f.read(): | ||
raise Exception('DOI file needs updating.') | ||
print('DOI file is OK.') | ||
except Exception as e: | ||
print(e) | ||
print('Retrieving current DOI from Zenodo...') | ||
doi = '10.5281/zenodo.594858' # default (concept) DOI | ||
try: | ||
from urllib.request import urlopen | ||
import json | ||
# get info for all versions from Zenodo API | ||
# (TODO: can we just get the specific version?) | ||
data = json.load(urlopen('https://zenodo.org/api/records/' | ||
'?q=conceptrecid:594858' | ||
'&all_versions=True&sort=-version&size=9999')) | ||
# search for given version | ||
for rec in data['hits']['hits']: | ||
md = rec['metadata'] | ||
if md['version'] == ver: | ||
doi = md['doi'] | ||
break | ||
else: | ||
raise LookupError('Error: Version {} not found.'.format(ver)) | ||
print(' Found DOI {} for version {}.'.format(doi, ver)) | ||
except Exception as e: | ||
print(' {}\n Using concept DOI {}.'.format(e, doi)) | ||
ver = 'PyAbel' # don't use specific version | ||
# write file | ||
with open(doi_file, 'w') as f: | ||
f.write('''\ | ||
.. | ||
DOI for {ver} | ||
Don't edit this file, it's updated automatically by conf.py! | ||
.. |doi| replace:: {doi} | ||
.. |doi_link| replace:: `{doi} <https://doi.org/{doi}>`__ | ||
'''.format(ver=ver, doi=doi)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
Helper script for HTML builds: try to download MathJax and use its local copy | ||
(needed for rendering formulas in offline HTML documentation). | ||
""" | ||
|
||
if any('html' in arg for arg in sys.argv): # any argument has substring 'html' | ||
# URL (most complete standalone script, ~2 MB) | ||
mj_url = 'https://github.com/mathjax/MathJax/raw/master/es5/tex-svg-full.js' | ||
# local file name | ||
mj_file = 'mathjax.js' | ||
# relative file path in source tree | ||
mj_path = 'static/' + mj_file | ||
|
||
if not os.path.exists(mj_path): | ||
print('Downloading MathJax...') | ||
try: | ||
from urllib.request import urlretrieve | ||
urlretrieve(mj_url, mj_path) | ||
except Exception as e: | ||
print(e) | ||
|
||
if os.path.exists(mj_path): | ||
print('Using local MathJax script.') | ||
mathjax_path = mj_file # configure sphinx.ext.mathjax | ||
# Sphinx fails to enable MathJax automatically for "single HTML" build | ||
if 'singlehtml' in sys.argv: | ||
print(' (force inclusion)') | ||
html_js_files += [mj_file] # so add it manually | ||
else: | ||
print('Local MathJax not found, using default CDN script.') |
Binary file not shown.
Oops, something went wrong.