FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

sphinx-codeautolink improvements by scottyhq · Pull Request #281 · xarray-contrib/xarray-tutorial · GitHub

sphinx-codeautolink improvements - #281

Draft
scottyhq wants to merge 3 commits into
xarray-contrib:mainfrom
scottyhq:autolink
Draft

sphinx-codeautolink improvements#281
scottyhq wants to merge 3 commits into
xarray-contrib:mainfrom
scottyhq:autolink

Conversation

scottyhq commented Jul 1, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

Based on discussion in #82

  • adds underlines to linked code docs
  • does some mapping to xarray api

Lots of warnings! Would need to add lots of manual mappings for completeness... and even then it doesn't pick up things like da.resample and da.isel below because it doesn't realize that da is a DataAarray:

da = xr.tutorial.load_dataset("air_temperature", engine="netcdf4").air
monthly = da.resample(time="ME").mean()
data = da.isel(time=0)

Even so, I think the underline and hover color are nice additions

github-actions Bot commented Jul 1, 2024
edited
Loading

Copy link
Copy Markdown

🎊 PR Preview 2e3e0f5 has been successfully built and deployed to https://xarray-contrib-xarray-tutorial-preview-pr-281.surge.sh

🕐 Build time: 0.01s

🤖 By surge-preview

Copy link
Copy Markdown

Check out this pull request on 

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Comment thread _config.yml
Comment on lines +81 to +87
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",

scottyhq Jul 1, 2024
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

scottyhq Jul 1, 2024
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you try adding it to xarrays init.py?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread _static/style.css
Comment on lines +5 to +15
.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;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I concur!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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?

},
"outputs": [],
"source": [
"da: xr.DataArray = xr.tutorial.load_dataset(\"air_temperature\", engine=\"netcdf4\").air\n",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Need a type hint on da in order for subsequent methods to be picked up (da.resample). Also, if chaining methods only the first is picked up da.isel(time=0).plot() links to isel but not plot

scottyhq Jul 1, 2024
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Opened discussion for clarification on this felix-hilden/sphinx-codeautolink#146.

Edit: method chaining links would need some work felix-hilden/sphinx-codeautolink#147

scottyhq marked this pull request as draft May 29, 2025 14:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL