Skip to content

Commit 1ce5908

Browse files
VeckoTheGeckonilodnapre-commit-ci[bot]
authored
Add open binder and download link pre-amble (remove zip tooling) (#2293) (#2316)
Co-authored-by: Danilo A. Silva <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent dae870e commit 1ce5908

File tree

3 files changed

+21
-39
lines changed

3 files changed

+21
-39
lines changed

docs/community/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ From there:
7474
- create a git branch, implement, commit, and push your changes
7575
- `create a pull request <https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork>`_ (PR) into ``main`` of the original repo making sure to link to the issue that you are working on. Not yet finished with your feature but still want feedback on how you're going? Then mark it as "draft" and ``@ping`` a maintainer. See our `maintainer notes <maintainer.md>`_ to see our PR review workflow.
7676

77-
If you made changes to the documentation, and want to render a local version, you can run the command ``sphinx-autobuild --ignore "*.zip" docs docs/_build`` to create a server to automatically rebuild the documentation when you make changes.
77+
If you made changes to the documentation, and want to render a local version, you can run the command ``sphinx-autobuild docs docs/_build`` to create a server to automatically rebuild the documentation when you make changes.
7878

7979
Code guidelines
8080
~~~~~~~~~~~~~~~

docs/conf.py

Lines changed: 19 additions & 37 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
@@ -50,8 +46,7 @@
5046

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

5651
# The encoding of source files.
5752
# source_encoding = 'utf-8-sig'
@@ -198,7 +193,7 @@
198193
"image_dark": "logo-horo_dia.svg",
199194
},
200195
"use_edit_page_button": True,
201-
"github_url": "https://github.com/OceanParcels/parcels",
196+
"github_url": "https://github.com/Parcels-code/parcels",
202197
"icon_links": [
203198
{
204199
"name": "Conda Forge",
@@ -210,40 +205,13 @@
210205
}
211206

212207
html_context = {
213-
"github_user": "OceanParcels",
208+
"github_user": "Parcels-code",
214209
"github_repo": "parcels",
215210
"github_version": "main",
216211
"doc_path": "docs",
217212
}
218213

219214

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-
247215
# based on pandas doc/source/conf.py
248216
def linkcode_resolve(domain, info):
249217
"""Determine the URL corresponding to Python object."""
@@ -296,11 +264,11 @@ def linkcode_resolve(domain, info):
296264

297265
if "-" in parcels.__version__:
298266
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}"
300268
)
301269
else:
302270
return (
303-
f"https://github.com/OceanParcels/parcels/blob/"
271+
f"https://github.com/Parcels-code/parcels/blob/"
304272
f"{parcels.__version__}/parcels/{fn}{linespec}"
305273
)
306274

@@ -382,6 +350,20 @@ def linkcode_resolve(domain, info):
382350
}
383351
# -- Options for LaTeX output ---------------------------------------------
384352

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

docs/documentation/index.rst

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

4-
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.
4+
Shown below are several documentation and tutorial Jupyter notebooks and scripts which go through various aspects of Parcels.
55

66
.. warning::
77
In v3.1.0 we updated kernels in the tutorials to use ``parcels.ParcelsRandom`` instead of ``from parcels import ParcelsRandom``. Due to our C-conversion code, using ``parcels.ParcelsRandom`` only works with v3.1.0+. When browsing/downloading the tutorials, it's important that you are using the documentation corresponding to the version of Parcels that you have installed. You can find which parcels version you have installed by doing ``import parcels`` followed by ``print(parcels.__version__)``. If you don't want to use the latest version of Parcels, you can browse prior versions of the documentation by using the version switcher in the bottom right of this page.

0 commit comments

Comments
 (0)