|
14 | 14 | import datetime |
15 | 15 | import inspect |
16 | 16 | import os |
17 | | -import re |
18 | | -import shutil |
19 | 17 | import sys |
20 | | -import tempfile |
21 | 18 | import warnings |
22 | | -from pathlib import Path |
23 | 19 |
|
24 | 20 | # If extensions (or modules to document with autodoc) are in another directory, |
25 | 21 | # add these directories to sys.path here. If the directory is relative to the |
|
51 | 47 |
|
52 | 48 | # The suffix(es) of source filenames. |
53 | 49 | # You can specify multiple suffix as a list of string: |
54 | | -# source_suffix = ['.rst', '.md'] |
55 | | -source_suffix = ".rst" |
| 50 | +source_suffix = [".rst", ".md"] |
56 | 51 |
|
57 | 52 | # The encoding of source files. |
58 | 53 | # source_encoding = 'utf-8-sig' |
|
219 | 214 | } |
220 | 215 |
|
221 | 216 |
|
222 | | -# Copy code examples to download directory |
223 | | -downloads_folder = Path("_downloads") |
224 | | -downloads_folder.mkdir(exist_ok=True) |
225 | | - |
226 | | - |
227 | | -def make_filename_safe(filename: str, safe_char: str = "_") -> str: |
228 | | - """Make a filename safe for saving to disk.""" |
229 | | - # Replace any characters that are not allowed in a filename with the safe character |
230 | | - safe_filename = re.sub(r'[\\/:*?"<>|]', safe_char, filename) |
231 | | - return safe_filename |
232 | | - |
233 | | - |
234 | | -with tempfile.TemporaryDirectory() as temp_dir: |
235 | | - temp_dir = Path(temp_dir) |
236 | | - |
237 | | - # Copy examples folder to temp directory (with a folder name matching parcels version) |
238 | | - examples_folder = temp_dir / make_filename_safe(f"parcels_tutorials ({version})") |
239 | | - shutil.copytree("examples", examples_folder) |
240 | | - |
241 | | - # Zip contents of temp directory and save to _downloads folder |
242 | | - shutil.make_archive( |
243 | | - "_downloads/parcels_tutorials", |
244 | | - "zip", |
245 | | - temp_dir, |
246 | | - ) |
247 | | - |
248 | | - |
249 | 217 | # based on pandas doc/source/conf.py |
250 | 218 | def linkcode_resolve(domain, info): |
251 | 219 | """Determine the URL corresponding to Python object.""" |
@@ -384,6 +352,20 @@ def linkcode_resolve(domain, info): |
384 | 352 | nbsphinx_execute = "never" |
385 | 353 | # -- Options for LaTeX output --------------------------------------------- |
386 | 354 |
|
| 355 | +BRANCH = ( |
| 356 | + os.environ.get("READTHEDOCS_GIT_IDENTIFIER") # ReadTheDocs |
| 357 | + or "main" # fallback |
| 358 | +) |
| 359 | + |
| 360 | +nbsphinx_prolog = f""" |
| 361 | +.. raw:: html |
| 362 | +
|
| 363 | + Run this notebook in the cloud <a href="https://mybinder.org/v2/gh/OceanParcels/Parcels/{BRANCH}?urlpath=lab/tree/docs/{{{{ env.doc2path(env.docname, base=None) }}}}" target="_blank"><img alt="Binder badge" src="https://mybinder.org/badge_logo.svg"></a> |
| 364 | + , or view it <a href="https://github.com/OceanParcels/Parcels/blob/{BRANCH}/docs/{{{{ env.doc2path(env.docname, base=None) }}}}" target="_blank">on GitHub</a>. Notebook version corresponds with {BRANCH}. |
| 365 | +
|
| 366 | + <p style="margin-bottom: 30px"></p> |
| 367 | +""" |
| 368 | + |
387 | 369 | latex_elements = { |
388 | 370 | # The paper size ('letterpaper' or 'a4paper'). |
389 | 371 | # 'papersize': 'letterpaper', |
|
0 commit comments