|
| 1 | +# Configuration file for the Sphinx documentation builder. |
| 2 | +# |
| 3 | +# For the full list of built-in configuration values, see the documentation: |
| 4 | +# https://www.sphinx-doc.org/en/master/usage/configuration.html |
| 5 | + |
| 6 | +# -- Project information ----------------------------------------------------- |
| 7 | +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information |
| 8 | + |
| 9 | +import datetime |
| 10 | +import inspect |
| 11 | +import os |
| 12 | +import sys |
| 13 | +import warnings |
| 14 | + |
| 15 | +project = 'PlasticParcels' |
| 16 | +copyright = f'{datetime.datetime.now().year}, The OceanParcels Team' |
| 17 | +author = 'The OceanParcels Team' |
| 18 | + |
| 19 | +# -- General configuration --------------------------------------------------- |
| 20 | +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration |
| 21 | + |
| 22 | +extensions = [] |
| 23 | + |
| 24 | +templates_path = ['_templates'] |
| 25 | +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +# -- Options for HTML output ------------------------------------------------- |
| 30 | +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output |
| 31 | + |
| 32 | +html_theme = 'pydata_sphinx_theme' |
| 33 | +html_static_path = ['_static'] |
| 34 | + |
| 35 | +html_theme_options = { |
| 36 | + "logo": { |
| 37 | + "image_light": "plasticparcelslogo.png", |
| 38 | + "image_dark": "plasticparcelslogo-inverted.png", # TODO create this |
| 39 | + }, |
| 40 | + # "use_edit_page_button": True, |
| 41 | + "github_url": "https://github.com/OceanParcels/plasticparcels", |
| 42 | + "icon_links": [ |
| 43 | + { |
| 44 | + "name": "Conda Forge", |
| 45 | + "url": "https://anaconda.org/conda-forge/plasticparcels", # required |
| 46 | + "icon": "fa-solid fa-box", |
| 47 | + "type": "fontawesome", |
| 48 | + } |
| 49 | + ] |
| 50 | +} |
| 51 | + |
| 52 | +extensions = [ |
| 53 | + 'sphinx.ext.autodoc', |
| 54 | + 'sphinx.ext.todo', |
| 55 | + "sphinx.ext.linkcode", |
| 56 | + "sphinx.ext.mathjax", |
| 57 | + "sphinx.ext.napoleon", |
| 58 | + "myst_parser", |
| 59 | + "nbsphinx", |
| 60 | + "numpydoc", |
| 61 | +] |
| 62 | + |
| 63 | +myst_enable_extensions = ["dollarmath", "amsmath"] |
| 64 | + |
| 65 | +# based on pandas doc/source/conf.py |
| 66 | +def linkcode_resolve(domain, info): |
| 67 | + """Determine the URL corresponding to Python object.""" |
| 68 | + if domain != "py": |
| 69 | + return None |
| 70 | + |
| 71 | + modname = info["module"] |
| 72 | + fullname = info["fullname"] |
| 73 | + |
| 74 | + submod = sys.modules.get(modname) |
| 75 | + if submod is None: |
| 76 | + return None |
| 77 | + |
| 78 | + obj = submod |
| 79 | + for part in fullname.split("."): |
| 80 | + try: |
| 81 | + with warnings.catch_warnings(): |
| 82 | + # Accessing deprecated objects will generate noisy warnings |
| 83 | + warnings.simplefilter("ignore", FutureWarning) |
| 84 | + obj = getattr(obj, part) |
| 85 | + except AttributeError: |
| 86 | + return None |
| 87 | + |
| 88 | + try: |
| 89 | + fn = inspect.getsourcefile(inspect.unwrap(obj)) |
| 90 | + except TypeError: |
| 91 | + try: # property |
| 92 | + fn = inspect.getsourcefile(inspect.unwrap(obj.fget)) |
| 93 | + except (AttributeError, TypeError): |
| 94 | + fn = None |
| 95 | + if not fn: |
| 96 | + return None |
| 97 | + |
| 98 | + try: |
| 99 | + source, lineno = inspect.getsourcelines(obj) |
| 100 | + except TypeError: |
| 101 | + try: # property |
| 102 | + source, lineno = inspect.getsourcelines(obj.fget) |
| 103 | + except (AttributeError, TypeError): |
| 104 | + lineno = None |
| 105 | + except OSError: |
| 106 | + lineno = None |
| 107 | + |
| 108 | + if lineno: |
| 109 | + linespec = f"#L{lineno}-L{lineno + len(source) - 1}" |
| 110 | + else: |
| 111 | + linespec = "" |
| 112 | + |
| 113 | + fn = os.path.relpath(fn, start=os.path.dirname(parcels.__file__)) |
| 114 | + |
| 115 | + if "-" in parcels.__version__: |
| 116 | + return f"https://github.com/OceanParcels/plasticparcels/blob/master/parcels/{fn}{linespec}" |
| 117 | + else: |
| 118 | + return ( |
| 119 | + f"https://github.com/OceanParcels/plasticparcels/blob/" |
| 120 | + f"{parcels.__version__}/parcels/{fn}{linespec}" |
| 121 | + ) |
0 commit comments