|
14 | 14 | # import sys |
15 | 15 | # sys.path.insert(0, os.path.abspath('.')) |
16 | 16 |
|
17 | | -# Print Python environment info for easier debugging on ReadTheDocs |
18 | | - |
| 17 | +import inspect |
| 18 | +import operator |
| 19 | +import os |
19 | 20 | import sys |
20 | 21 | import subprocess |
| 22 | + |
21 | 23 | import xarray_beam # verify this works |
22 | 24 |
|
| 25 | +# Print Python environment info for easier debugging on ReadTheDocs |
23 | 26 | print("python exec:", sys.executable) |
24 | 27 | print("sys.path:", sys.path) |
25 | 28 | print("pip environment:") |
|
42 | 45 | extensions = [ |
43 | 46 | 'sphinx.ext.autodoc', |
44 | 47 | 'sphinx.ext.autosummary', |
| 48 | + 'sphinx.ext.linkcode', |
45 | 49 | 'sphinx.ext.napoleon', |
46 | 50 | 'myst_nb', |
47 | 51 | ] |
|
63 | 67 | # The theme to use for HTML and HTML Help pages. See the documentation for |
64 | 68 | # a list of builtin themes. |
65 | 69 | # |
66 | | -html_theme = 'sphinx_rtd_theme' |
| 70 | +html_theme = 'furo' # https://pradyunsg.me/furo/quickstart/ |
| 71 | + |
| 72 | +html_theme_options = { |
| 73 | + 'source_repository': 'https://github.com/google/xarray-beam/', |
| 74 | + 'source_branch': 'main', |
| 75 | + 'source_directory': 'docs/', |
| 76 | + 'sidebar_hide_name': False, |
| 77 | +} |
67 | 78 |
|
68 | 79 | # Add any paths that contain custom static files (such as style sheets) here, |
69 | 80 | # relative to this directory. They are copied after the builtin static files, |
|
81 | 92 |
|
82 | 93 | # https://stackoverflow.com/a/66295922/809705 |
83 | 94 | autodoc_typehints = "description" |
| 95 | + |
| 96 | + |
| 97 | +# Customize code links via sphinx.ext.linkcode |
| 98 | +# Borrowed from JAX: https://github.com/google/jax/pull/20961 |
| 99 | + |
| 100 | + |
| 101 | +def linkcode_resolve(domain, info): |
| 102 | + if domain != 'py': |
| 103 | + return None |
| 104 | + if not info['module']: |
| 105 | + return None |
| 106 | + if not info['fullname']: |
| 107 | + return None |
| 108 | + try: |
| 109 | + mod = sys.modules.get(info['module']) |
| 110 | + obj = operator.attrgetter(info['fullname'])(mod) |
| 111 | + if isinstance(obj, property): |
| 112 | + obj = obj.fget |
| 113 | + while hasattr(obj, '__wrapped__'): # decorated functions |
| 114 | + obj = obj.__wrapped__ |
| 115 | + filename = inspect.getsourcefile(obj) |
| 116 | + source, linenum = inspect.getsourcelines(obj) |
| 117 | + print(f'found source code for: {info}') |
| 118 | + except Exception as e: |
| 119 | + print(f'did not find source code for: {info}: {e}') |
| 120 | + return None |
| 121 | + filename = os.path.relpath( |
| 122 | + filename, start=os.path.dirname(xarray_beam.__file__) |
| 123 | + ) |
| 124 | + lines = f'#L{linenum}-L{linenum + len(source)}' if linenum else '' |
| 125 | + return f'https://github.com/google/xarray-beam/blob/main/xarray_beam/{filename}{lines}' |
0 commit comments