Skip to content

Commit

Permalink
DOC: Link to code and version automation feature is implemented.
Browse files Browse the repository at this point in the history
Link to code implementation depends on https://github.com/OceanParcels/parcels/blob/cac7ed05e8b250b3c6d5830d08e9d070e3217242/parcels/_version.py#L4

Docs version in conf.py now uses parcels.__version__
  • Loading branch information
VeckoTheGecko committed Feb 28, 2023
1 parent d7c8916 commit 398ba3b
Showing 1 changed file with 67 additions and 4 deletions.
71 changes: 67 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import inspect
import os
import sys
import warnings

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand All @@ -31,7 +33,7 @@
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.viewcode',
"sphinx.ext.linkcode",
]

# Add any paths that contain templates here, relative to this directory.
Expand All @@ -58,9 +60,11 @@
# built documents.
#
# The short X.Y version.
version = '2.4.0'
import parcels

version = parcels.__version__
# The full version, including alpha/beta/rc tags.
release = '2.4.0'
release = version

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -162,6 +166,65 @@
"doc_path": "docs",
}

# based on pandas doc/source/conf.py
def linkcode_resolve(domain, info):
"""Determine the URL corresponding to Python object."""
if domain != "py":
return None

modname = info["module"]
fullname = info["fullname"]

submod = sys.modules.get(modname)
if submod is None:
return None

obj = submod
for part in fullname.split("."):
try:
with warnings.catch_warnings():
# Accessing deprecated objects will generate noisy warnings
warnings.simplefilter("ignore", FutureWarning)
obj = getattr(obj, part)
except AttributeError:
return None

try:
fn = inspect.getsourcefile(inspect.unwrap(obj))
except TypeError:
try: # property
fn = inspect.getsourcefile(inspect.unwrap(obj.fget))
except (AttributeError, TypeError):
fn = None
if not fn:
return None

try:
source, lineno = inspect.getsourcelines(obj)
except TypeError:
try: # property
source, lineno = inspect.getsourcelines(obj.fget)
except (AttributeError, TypeError):
lineno = None
except OSError:
lineno = None

if lineno:
linespec = f"#L{lineno}-L{lineno + len(source) - 1}"
else:
linespec = ""

fn = os.path.relpath(fn, start=os.path.dirname(parcels.__file__))

if "-" in parcels.__version__:
return f"https://github.com/OceanParcels/parcels/blob/master/parcels/{fn}{linespec}"
else:
return (
f"https://github.com/OceanParcels/parcels/blob/"
f"{parcels.__version__}/parcels/{fn}{linespec}"
)


# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
Expand Down

0 comments on commit 398ba3b

Please sign in to comment.