Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix links to source code in documentation pages #1444

Merged
merged 30 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fdef7d3
Use tag in links to source code in Sphinx pages
santisoler May 1, 2024
d8dadae
Hardcode latest version to see if it works well
santisoler May 1, 2024
2271473
Include checkout step that also sync tags
santisoler May 2, 2024
c3f0d5c
Include checkout step in testing jobs
santisoler May 2, 2024
93e0d0e
Add steps that list tags and print simpeg version
santisoler May 2, 2024
2955d8c
Try to increase the checkout depth to solve the issue
santisoler May 3, 2024
530be7e
Completely disable shallow depth
santisoler May 3, 2024
5693b0a
Merge branch 'main' into docs-source-tag
santisoler May 3, 2024
3e27f01
List installed packages
santisoler May 3, 2024
fab36c7
Add leading v in the github_version
santisoler May 3, 2024
e435f91
Improve if statement
santisoler May 3, 2024
cbdfc66
Fix wrong import of SimPEG
santisoler May 3, 2024
624c554
Update matrix.yml
jcapriot May 3, 2024
c2d3842
Update matrix.yml
jcapriot May 3, 2024
3931e85
Update linkcode_resolve function to point to the right tag
santisoler May 3, 2024
2f8d583
Merge branch 'docs-source-tag' of github.com:simpeg/simpeg into docs-…
santisoler May 3, 2024
fab6bdb
Remove hardcoded tag
santisoler May 3, 2024
300740e
Remove printing git tags in Azure
santisoler May 3, 2024
329ca4f
Merge branch 'main' into docs-source-tag
santisoler May 9, 2024
c60dce6
Merge branch 'main' into docs-source-tag
santisoler May 10, 2024
e23480b
Merge branch 'main' into docs-source-tag
santisoler May 15, 2024
e76b172
Merge branch 'main' into docs-source-tag
jcapriot May 15, 2024
58a6d94
Disable pytest capturing stdout and stderr
santisoler May 16, 2024
dc09078
Merge branch 'main' into docs-source-tag
santisoler Jun 5, 2024
b02673e
Revert "Disable pytest capturing stdout and stderr"
santisoler Jun 5, 2024
cc106d0
Merge branch 'main' into docs-source-tag
santisoler Jun 5, 2024
cd81f7b
Merge branch 'main' into docs-source-tag
santisoler Jun 5, 2024
6012f27
Go back to use `py_vers` when creating environment
santisoler Jun 6, 2024
201d96c
Merge branch 'main' into docs-source-tag
santisoler Jun 6, 2024
3f0f2c1
Add missing $
santisoler Jun 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .azure-pipelines/matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ jobs:
vmImage: ${{ os }}
timeoutInMinutes: 120
steps:

# Checkout simpeg repo, including tags.
# We need to sync tags and disable shallow depth in order to get the
# SimPEG version while building the docs.
- checkout: self
fetchDepth: 0
fetchTags: true
displayName: Checkout repository (including tags)

- script: |
wget -O Mambaforge.sh "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh"
bash Mambaforge.sh -b -p "${HOME}/conda"
Expand All @@ -31,10 +40,14 @@ jobs:
- script: |
source "${HOME}/conda/etc/profile.d/conda.sh"
source "${HOME}/conda/etc/profile.d/mamba.sh"
echo " - python="${{ py_vers }} >> environment_test.yml
mamba env create -f environment_test.yml
cp environment_test.yml environment_test_with_pyversion.yml
echo " - python="{{ py_vers }} >> environment_test_with_pyversion.yml
santisoler marked this conversation as resolved.
Show resolved Hide resolved
mamba env create -f environment_test_with_pyversion.yml
rm environment_test_with_pyversion.yml
conda activate simpeg-test
pip install pytest-azurepipelines
echo "\nList installed packages"
conda list
displayName: Create Anaconda testing environment

- script: |
Expand All @@ -43,6 +56,12 @@ jobs:
pip install -e .
displayName: Build package

- script: |
source "${HOME}/conda/etc/profile.d/conda.sh"
conda activate simpeg-test
python -c "import simpeg; print(simpeg.__version__)"
displayName: Check SimPEG version

- script: |
source "${HOME}/conda/etc/profile.d/conda.sh"
conda activate simpeg-test
Expand Down
8 changes: 7 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ stages:
rm environment_test_with_pyversion.yml
conda activate simpeg-test
pip install pytest-azurepipelines
echo "\nList installed packages"
conda list
displayName: Create Anaconda testing environment

- script: |
Expand Down Expand Up @@ -212,6 +214,8 @@ stages:
rm environment_test_with_pyversion.yml
conda activate simpeg-test
pip install pytest-azurepipelines
echo "\nList installed packages"
conda list
displayName: Create Anaconda testing environment

- bash: |
Expand Down Expand Up @@ -328,6 +332,8 @@ stages:
rm environment_test_with_pyversion.yml
conda activate simpeg-test
pip install pytest-azurepipelines
echo "\nList installed packages"
conda list
displayName: Create Anaconda testing environment

- bash: |
Expand Down Expand Up @@ -384,4 +390,4 @@ stages:
echo -e "\nFinished uploading generated files."
displayName: Push documentation to simpeg-doctest
env:
GH_TOKEN: $(gh.token)
GH_TOKEN: $(gh.token)
43 changes: 25 additions & 18 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"sphinx.ext.mathjax",
"sphinx_gallery.gen_gallery",
"sphinx.ext.todo",
"sphinx.ext.linkcode",
"matplotlib.sphinxext.plot_directive",
]

Expand Down Expand Up @@ -136,17 +135,24 @@
# edit_on_github_branch = "main/docs"
# check_meta = False

# source code links

# -----------------
# Source code links
# -----------------
# Function inspired in matplotlib's configuration

link_github = True
# You can build old with link_github = False

if link_github:
import inspect
from os.path import relpath, dirname
from packaging.version import parse

extensions.append("sphinx.ext.linkcode")

def linkcode_resolve(domain, info):
"""
Determine the URL corresponding to Python object
"""
if domain != "py":
return None

Expand All @@ -161,44 +167,45 @@ def linkcode_resolve(domain, info):
for part in fullname.split("."):
try:
obj = getattr(obj, part)
except Exception:
except AttributeError:
return None

try:
unwrap = inspect.unwrap
except AttributeError:
pass
else:
obj = unwrap(obj)

if inspect.isfunction(obj):
obj = inspect.unwrap(obj)
try:
fn = inspect.getsourcefile(obj)
except Exception:
except TypeError:
fn = None
if not fn or fn.endswith("__init__.py"):
try:
fn = inspect.getsourcefile(sys.modules[obj.__module__])
except (TypeError, AttributeError, KeyError):
fn = None
if not fn:
return None

try:
source, lineno = inspect.getsourcelines(obj)
except Exception:
except (OSError, TypeError):
lineno = None

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

try:
fn = relpath(fn, start=dirname(simpeg.__file__))
fn = os.path.relpath(fn, start=os.path.dirname(simpeg.__file__))
except ValueError:
return None

return f"https://github.com/simpeg/simpeg/blob/main/simpeg/{fn}{linespec}"
simpeg_version = parse(simpeg.__version__)
tag = "main" if simpeg_version.is_devrelease else f"v{simpeg_version.public}"
return f"https://github.com/simpeg/simpeg/blob/{tag}/simpeg/{fn}{linespec}"

else:
extensions.append("sphinx.ext.viewcode")


# Make numpydoc to generate plots for example sections
numpydoc_use_plots = True
plot_pre_code = """
Expand Down
Loading