|
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 |
|
50 | 46 |
|
51 | 47 | # The suffix(es) of source filenames. |
52 | 48 | # You can specify multiple suffix as a list of string: |
53 | | -# source_suffix = ['.rst', '.md'] |
54 | | -source_suffix = ".rst" |
| 49 | +source_suffix = [".rst", ".md"] |
55 | 50 |
|
56 | 51 | # The encoding of source files. |
57 | 52 | # source_encoding = 'utf-8-sig' |
|
198 | 193 | "image_dark": "logo-horo_dia.svg", |
199 | 194 | }, |
200 | 195 | "use_edit_page_button": True, |
201 | | - "github_url": "https://github.com/OceanParcels/parcels", |
| 196 | + "github_url": "https://github.com/Parcels-code/parcels", |
202 | 197 | "icon_links": [ |
203 | 198 | { |
204 | 199 | "name": "Conda Forge", |
|
210 | 205 | } |
211 | 206 |
|
212 | 207 | html_context = { |
213 | | - "github_user": "OceanParcels", |
| 208 | + "github_user": "Parcels-code", |
214 | 209 | "github_repo": "parcels", |
215 | 210 | "github_version": "main", |
216 | 211 | "doc_path": "docs", |
217 | 212 | } |
218 | 213 |
|
219 | 214 |
|
220 | | -# Copy code examples to download directory |
221 | | -downloads_folder = Path("_downloads") |
222 | | -downloads_folder.mkdir(exist_ok=True) |
223 | | - |
224 | | - |
225 | | -def make_filename_safe(filename: str, safe_char: str = "_") -> str: |
226 | | - """Make a filename safe for saving to disk.""" |
227 | | - # Replace any characters that are not allowed in a filename with the safe character |
228 | | - safe_filename = re.sub(r'[\\/:*?"<>|]', safe_char, filename) |
229 | | - return safe_filename |
230 | | - |
231 | | - |
232 | | -with tempfile.TemporaryDirectory() as temp_dir: |
233 | | - temp_dir = Path(temp_dir) |
234 | | - |
235 | | - # Copy examples folder to temp directory (with a folder name matching parcels version) |
236 | | - examples_folder = temp_dir / make_filename_safe(f"parcels_tutorials ({version})") |
237 | | - shutil.copytree("examples", examples_folder) |
238 | | - |
239 | | - # Zip contents of temp directory and save to _downloads folder |
240 | | - shutil.make_archive( |
241 | | - "_downloads/parcels_tutorials", |
242 | | - "zip", |
243 | | - temp_dir, |
244 | | - ) |
245 | | - |
246 | | - |
247 | 215 | # based on pandas doc/source/conf.py |
248 | 216 | def linkcode_resolve(domain, info): |
249 | 217 | """Determine the URL corresponding to Python object.""" |
@@ -296,11 +264,11 @@ def linkcode_resolve(domain, info): |
296 | 264 |
|
297 | 265 | if "-" in parcels.__version__: |
298 | 266 | return ( |
299 | | - f"https://github.com/OceanParcels/parcels/blob/main/parcels/{fn}{linespec}" |
| 267 | + f"https://github.com/Parcels-code/parcels/blob/main/parcels/{fn}{linespec}" |
300 | 268 | ) |
301 | 269 | else: |
302 | 270 | return ( |
303 | | - f"https://github.com/OceanParcels/parcels/blob/" |
| 271 | + f"https://github.com/Parcels-code/parcels/blob/" |
304 | 272 | f"{parcels.__version__}/parcels/{fn}{linespec}" |
305 | 273 | ) |
306 | 274 |
|
@@ -382,6 +350,20 @@ def linkcode_resolve(domain, info): |
382 | 350 | } |
383 | 351 | # -- Options for LaTeX output --------------------------------------------- |
384 | 352 |
|
| 353 | +BRANCH = ( |
| 354 | + os.environ.get("READTHEDOCS_GIT_IDENTIFIER") # ReadTheDocs |
| 355 | + or "main" # fallback |
| 356 | +) |
| 357 | + |
| 358 | +nbsphinx_prolog = f""" |
| 359 | +.. raw:: html |
| 360 | +
|
| 361 | + Run this notebook in the cloud <a href="https://mybinder.org/v2/gh/Parcels-code/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> |
| 362 | + , or view it <a href="https://github.com/Parcels-code/Parcels/blob/{BRANCH}/docs/{{{{ env.doc2path(env.docname, base=None) }}}}" target="_blank">on GitHub</a>. Notebook version corresponds with {BRANCH}. |
| 363 | +
|
| 364 | + <p style="margin-bottom: 30px"></p> |
| 365 | +""" |
| 366 | + |
385 | 367 | latex_elements = { |
386 | 368 | # The paper size ('letterpaper' or 'a4paper'). |
387 | 369 | # 'papersize': 'letterpaper', |
|
0 commit comments