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

sphinx-codeautolink improvements #281

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 2 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ jobs:
# NOTE: login shell activates conda environment
shell: bash -el {0}
run: |
jupyter-book build ./ --warningiserror --keep-going

- name: Dump Build Logs
if: always()
run: |
if (test -a _build/html/reports/*log); then cat _build/html/reports/*log ; fi
jupyter-book clean ./
jupyter-book build ./

- name: Save Build Folder
if: always()
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ jobs:
- name: Build JupyterBook
if: github.event.action != 'closed'
run: |
jupyter-book build ./ --warningiserror --keep-going

- name: Dump Build Logs
if: github.event.action != 'closed'
run: |
if (test -a _build/html/reports/*log); then cat _build/html/reports/*log ; fi
jupyter-book clean ./
jupyter-book build ./

- name: Upload artifact
if: github.event.action != 'closed'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/qaqc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ jobs:
timeout-minutes: 5
if: always()
run: |
jupyter-book clean ./
jupyter-book build ./ --builder linkcheck
22 changes: 22 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ sphinx:
# application/vnd.holoviews_load.v0+json, application/vnd.holoviews_exec.v0+json
suppress_warnings: ["mystnb.unknown_mime_type", "misc.highlighting_failure"]
codeautolink_concat_default: True
codeautolink_warn_on_missing_inventory: True
codeautolink_warn_on_failed_resolve: True
codeautolink_inventory_map: {
# unfortunately mapping the top level doesn't work, need all methods
#"xarray.core.dataarray.DataArray": "xarray.DataArray",
"xarray.core.accessor_dt.DatetimeAccessor": "xarray.DataArray.dt",
"xarray.core.dataarray.DataArray.coarsen": "xarray.DataArray.coarsen",
"xarray.core.dataarray.DataArray.groupby": "xarray.DataArray.groupby",
"xarray.core.dataarray.DataArray.groupby_bins": "xarray.DataArray.groupby_bins",
Comment on lines +81 to +87
Copy link
Contributor Author

@scottyhq scottyhq Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felix-hilden, I realize this issue (felix-hilden/sphinx-codeautolink#131 (comment) ) has been closed for a while, but curious based on your comment if it does seems straightforward to implement a simplification of ("xarray.core.dataarray.DataArray": "xarray.DataArray") to avoid having to enumerate every method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would setting __module__ fix this? (pydata/xarray#4279)

Copy link
Contributor Author

@scottyhq scottyhq Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the above issue, if I add

import xarray 
xarray.DataArray.__module__ = "xarray"

to conf.py before building I'm getting Handler <bound method SphinxCodeAutoLink.create_references of <sphinx_codeautolink.extension.SphinxCodeAutoLink object at 0x145730710>> for event 'env-updated' threw an exception (exception: maximum recursion depth exceeded) ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try adding it to xarrays init.py?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Yeah I'm not at all opposed to having the feature that was discussed in the issue, I've just been out of the game for a while focusing on other things and I have personally no need for that. But I'm very open to contributions 👌

Personally I've opted for changing module attributes like so and it's worked well for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it does look like chaning either conf.py or xarray/__init__.py works, I think the recursion error was coming from some issue with my local settings/cache...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind of a pain to modify conf.py via jupyter book (jupyter-book/jupyter-book#858,
jupyter-book/jupyter-book#1673 (comment)) but that is probably the way to go...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it upstream? I think we'd like this in Xarray too.

"xarray.core.dataarray.DataArray.isel": "xarray.DataArray.isel",
#"xarray.core.dataarray.DataArray.plot": "xarray.DataArray.plot",
"xarray.plot.accessor.DataArrayPlotAccessor": "xarray.DataArray.plot",
"xarray.core.dataarray.DataArray.redindex": "xarray.DataArray.reindex",
"xarray.core.dataarray.DataArray.reduce": "xarray.DataArray.reduce",
"xarray.core.dataarray.DataArray.resample": "xarray.DataArray.resample",
"xarray.core.dataarray.DataArray.rolling": "xarray.DataArray.rolling",
"xarray.core.dataarray.DataArray.sel": "xarray.DataArray.sel",
"xarray.core.dataarray.DataArray.weighted": "xarray.DataArray.weighted",
#"Same for dataset :(
"xarray.core.dataset.Dataset.groupby": "xarray.Dataset.groupby",
"xarray.core.dataset.Dataset.isel": "xarray.Dataset.sel",
}
notfound_context:
body: "<h1>Whoops! 404 Page Not Found</h1>\n\n<p>Sorry, this page doesn't exist. Many sections of this book have been updated recently.</p><p> Try the search box 🔎 to find what you're looking for!</p>"
notfound_urls_prefix: /
Expand Down
12 changes: 12 additions & 0 deletions _static/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
.bd-header-announcement {
background-color: var(--pst-color-info-bg);
}

.sphinx-codeautolink-a:link {
border-bottom-color: lightgray;
border-bottom-style: dotted;
border-bottom-width: 1px;
}

.sphinx-codeautolink-a:hover {
border-bottom-color: rgb(255, 139, 139);
border-bottom-style: dotted;
border-bottom-width: 1px;
}
Comment on lines +5 to +15
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcherian @zmoon I think a subtle dotted underline is nice, personally I think the thick underlines (https://scikit-image.org/docs/stable/auto_examples/segmentation/plot_regionprops.html) are a bit distracting and distinct from the jupyterlab experience, but open to other opinions!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little darker would be nicer to me. It's also convention that solid lines are clickable links, so perhaps just a thin darker line?

Loading