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 cross reference #3273

Merged
merged 29 commits into from Dec 12, 2023
Merged

Conversation

ericpre
Copy link
Member

@ericpre ericpre commented Nov 24, 2023

This PR fixes many links to the API references. Enable sphinx "nitpicky" to check that there is no broken reference.
With the API changes, it is important that the reference are working, as it helps identifying if something is missing from the API references, beside being convenient to navigate.

Progress of the PR

  • Fix sphinx cross references to API reference,
    - [x] use numpydoc
    - [x] enable sphinx "nitpicky" to check any broken reference.
  • update docstring (if appropriate),
  • update user guide (if appropriate),
  • Remove mutable argument used as default value,
  • Set some model component attributes as property
  • add an changelog entry in the upcoming_changes folder (see upcoming_changes/README.rst),
  • Check formatting changelog entry in the readthedocs doc build of this PR (link in github checks)
  • [n/a] add tests,
  • ready for review.

@hakonanes
Copy link
Contributor

Great work, it is really a huge task to get Sphinx and friends to automatically document the complete API nicely (including just what you want).

I was wondering. Have you built the API by just listing the modules in a top index.rst and letting Sphinx decide which API members are listed using the __all__ lists in module/__init__.py and Sphinx templating? Such as done in kikuchipy (index.rst, overwritten templates)? Of course, HyperSpy's API is larger...

Also, have you tried controlling which members are listed by autodoc by overwriting the autodoc-skip-member function? I have a PR open in orix where I try to exclude all members defined outside orix: https://github.com/pyxem/orix/blob/ae619f40304bf0faf3cc535f32fc1a6362f4c736/doc/conf.py#L345-L364.

@ericpre
Copy link
Member Author

ericpre commented Nov 24, 2023

I did look at what you mentioned, and I found it that it doesn't play well with how hyperspy is currently structured. This is more simple after the split but still came to the conclusion that defining what API modules goes where explicitly is more straightforward and simple rather than using templates that needs to be adapted to hyperspy's need to generate the API automatically. The fact that the documentation is succinct and that it is difficult (and slow) to troubleshoot when something doesn't work, did put me off quite a bit.
At the end of the day, it is not that much to define explicitly and the maintenance will be straightforward, so I didn't think it was beneficial. I find the current API reference (v1.7) very impractical and confusing and I hardly use it... The issue is not what is included but how it is structured.

@hakonanes
Copy link
Contributor

I see, thank you for clarifying. I'm quite sure I'll learn some nice tricks from this PR: feel free to ping me for a review.

maintenance will be straightforward

Having a curated API reference, as you introduce here, rather than one automatically generated (as in kikuchipy/orix) can be straightforward to maintain, if the API doesn't change too quickly, and one remembers to add new members (classes, methods, functions, etc.). We had a curated API for orix, but it quickly became outdated as a constant stream of new features weren't continuously added... Just something to be aware of.

@ericpre
Copy link
Member Author

ericpre commented Nov 24, 2023

The important point of this PR is that the doc build will fail if a cross reference is broken. This is important, because when a new API is added, it is documented and it comes cross references to the relevant API - usually we do this fairly well. This should catch anything new and missing from the API reference.

I would expect that it is rare (when restructuring a module, for example) that we need to update the API reference manually, because:

  • new method of existing class are added automatically with autoclass/automodule
  • new classes are very rare and they are covered by automodule (except for some cases)

Copy link

codecov bot commented Nov 25, 2023

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (224dca7) 80.86% compared to head (f017fac) 80.84%.
Report is 39 commits behind head on RELEASE_next_major.

Files Patch % Lines
hyperspy/model.py 83.33% 5 Missing and 1 partial ⚠️
hyperspy/learn/mva.py 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                  Coverage Diff                   @@
##           RELEASE_next_major    #3273      +/-   ##
======================================================
- Coverage               80.86%   80.84%   -0.02%     
======================================================
  Files                     140      140              
  Lines                   20399    20475      +76     
  Branches                 4825     4838      +13     
======================================================
+ Hits                    16495    16553      +58     
- Misses                   2829     2859      +30     
+ Partials                 1075     1063      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hakonanes
Copy link
Contributor

I agree that as long as contents of modules (functions and classes with attributes and methods) are listed automatically the maintenance burden should be reasonable.

@ericpre
Copy link
Member Author

ericpre commented Nov 29, 2023

@hakonanes, @jlaehne, do you want to review this PR?

@hakonanes
Copy link
Contributor

I'm sorry, but I don't have time until Monday...

Copy link
Contributor

@hakonanes hakonanes left a comment

Choose a reason for hiding this comment

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

Stupendous amount of work this must have been, I'm impressed!

I've gone through 131/142 files here on GitHub. I've just briefly checked the API reference in the docs built from this PR. Plan to look through the remaining files tomorrow or Sunday.

No need to commit my suggested changes, feel free to do the changes yourself.

"module",
}

# if Version(numpydoc.__version__) >= Version("1.6.0rc0"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this be useful later on? I see version 1.6 of numpydoc was released in August (here).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it could be, to check the formatting of the docstring, but I think that this is not a priority. I don't know how much editing is required in the current state but better in a separate PR.

doc/reference/base_classes/signal/index.rst Show resolved Hide resolved
doc/reference/metadata.rst Outdated Show resolved Hide resolved
doc/user_guide/io.rst Outdated Show resolved Hide resolved
doc/user_guide/model/fitting_model.rst Outdated Show resolved Hide resolved
hyperspy/learn/ornmf.py Show resolved Hide resolved
hyperspy/learn/rpca.py Outdated Show resolved Hide resolved
hyperspy/learn/svd_pca.py Outdated Show resolved Hide resolved
hyperspy/misc/math_tools.py Outdated Show resolved Hide resolved
upcoming_changes/3273.bugfix.rst Outdated Show resolved Hide resolved
@ericpre
Copy link
Member Author

ericpre commented Dec 7, 2023

@hakonanes, please let me know when you finish your review.

@hakonanes
Copy link
Contributor

I'll finish tomorrow evening, sorry for the delay.

Copy link
Contributor

@hakonanes hakonanes left a comment

Choose a reason for hiding this comment

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

Here're the rest of my comments. Again, good work!

hyperspy/component.py Outdated Show resolved Hide resolved
hyperspy/learn/mva.py Show resolved Hide resolved
hyperspy/learn/mva.py Outdated Show resolved Hide resolved
hyperspy/learn/mva.py Outdated Show resolved Hide resolved
hyperspy/learn/mva.py Show resolved Hide resolved
hyperspy/model.py Show resolved Hide resolved
hyperspy/model.py Outdated Show resolved Hide resolved
hyperspy/models/model1d.py Outdated Show resolved Hide resolved
hyperspy/models/model2d.py Outdated Show resolved Hide resolved
hyperspy/roi.py Show resolved Hide resolved
Copy link
Member Author

@ericpre ericpre left a comment

Choose a reason for hiding this comment

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

Thank you @hakonanes, I fixed the typos and the links.

@jlaehne, do you want to review this PR?

hyperspy/learn/mva.py Show resolved Hide resolved
"module",
}

# if Version(numpydoc.__version__) >= Version("1.6.0rc0"):
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it could be, to check the formatting of the docstring, but I think that this is not a priority. I don't know how much editing is required in the current state but better in a separate PR.

hyperspy/model.py Show resolved Hide resolved
hyperspy/models/model1d.py Outdated Show resolved Hide resolved
hyperspy/model.py Show resolved Hide resolved
@jlaehne
Copy link
Contributor

jlaehne commented Dec 11, 2023

I'll try to browse over it these days, but I don't think I'll manage an as detailed review as @hakonanes

@jlaehne jlaehne mentioned this pull request Dec 11, 2023
9 tasks
doc/user_guide/io.rst Outdated Show resolved Hide resolved
doc/user_guide/io.rst Outdated Show resolved Hide resolved
doc/user_guide/model/indexing_model.rst Outdated Show resolved Hide resolved
hyperspy/_signals/complex_signal2d.py Outdated Show resolved Hide resolved
hyperspy/_signals/signal1d.py Outdated Show resolved Hide resolved
hyperspy/learn/ornmf.py Outdated Show resolved Hide resolved
hyperspy/learn/ornmf.py Outdated Show resolved Hide resolved
hyperspy/learn/rpca.py Show resolved Hide resolved
hyperspy/learn/rpca.py Show resolved Hide resolved
hyperspy/model.py Outdated Show resolved Hide resolved
@jlaehne jlaehne merged commit 2ec4ba8 into hyperspy:RELEASE_next_major Dec 12, 2023
23 of 24 checks passed
@ericpre ericpre deleted the docstring_improvement branch December 14, 2023 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants