Skip to content

Commit 7c1177a

Browse files
nilodnaVeckoTheGeckopre-commit-ci[bot]
authored
Add open binder and download link pre-amble (remove zip tooling) (#2293)
Co-authored-by: Nick Hodgskin <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e97035e commit 7c1177a

File tree

4 files changed

+18
-36
lines changed

4 files changed

+18
-36
lines changed

docs/conf.py

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@
1414
import datetime
1515
import inspect
1616
import os
17-
import re
18-
import shutil
1917
import sys
20-
import tempfile
2118
import warnings
22-
from pathlib import Path
2319

2420
# If extensions (or modules to document with autodoc) are in another directory,
2521
# add these directories to sys.path here. If the directory is relative to the
@@ -51,8 +47,7 @@
5147

5248
# The suffix(es) of source filenames.
5349
# You can specify multiple suffix as a list of string:
54-
# source_suffix = ['.rst', '.md']
55-
source_suffix = ".rst"
50+
source_suffix = [".rst", ".md"]
5651

5752
# The encoding of source files.
5853
# source_encoding = 'utf-8-sig'
@@ -219,33 +214,6 @@
219214
}
220215

221216

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-
249217
# based on pandas doc/source/conf.py
250218
def linkcode_resolve(domain, info):
251219
"""Determine the URL corresponding to Python object."""
@@ -384,6 +352,20 @@ def linkcode_resolve(domain, info):
384352
nbsphinx_execute = "never"
385353
# -- Options for LaTeX output ---------------------------------------------
386354

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+
387369
latex_elements = {
388370
# The paper size ('letterpaper' or 'a4paper').
389371
# 'papersize': 'letterpaper',

docs/documentation/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Documentation and Tutorials
22

3-
Parcels has several documentation and tutorial Jupyter notebooks and scripts which go through various aspects of Parcels. Static versions of the notebooks are available below via the gallery in the site, with the interactive notebooks being available either completely online at the following [Binder link](https://mybinder.org/v2/gh/OceanParcels/parcels/main?labpath=docs%2Fexamples%2Fparcels_tutorial.ipynb). Following the gallery of notebooks is a list of scripts which provide additional examples to users. You can work with the example notebooks and scripts locally by downloading {download}`parcels_tutorials.zip </_downloads/parcels_tutorials.zip>` and running with your own Parcels installation.
3+
Shown below are several documentation and tutorial Jupyter notebooks and scripts which go through various aspects of Parcels.
44

55
```{nbgallery}
66
:caption: Overview

docs/v4/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Install an alpha version of Parcels v4
22

3-
During development of Parcels v4, we are uploading versions of the package to an [index on prefix.dev](https://prefix.dev/channels/parcels/packages/parcels). This allows users to easily install an unreleased version without having to do a [development install](../installation.rst)! Give it a spin!
3+
During development of Parcels v4, we are uploading versions of the package to an [index on prefix.dev](https://prefix.dev/channels/parcels/packages/parcels). This allows users to easily install an unreleased version without having to do a [development install](../installation.md)! Give it a spin!
44

55
```{warning}
66
Before installing an alpha version of Parcels, we *highly* recommend creating a new environment so that doesn't affect package versions in your current environment (which you may be using for your research).

pixi.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ sphinxcontrib-mermaid = "*"
7676

7777
[feature.docs.tasks]
7878
docs = "sphinx-build docs docs/_build"
79-
docs-watch = 'sphinx-autobuild --ignore "*.zip" docs docs/_build'
79+
docs-watch = 'sphinx-autobuild docs docs/_build'
8080
docs-linkcheck = "sphinx-build -b linkcheck docs/ docs/_build/linkcheck"
8181

8282
[feature.pre-commit.dependencies]

0 commit comments

Comments
 (0)