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

DOC: Numpy docstrings migration #1341

Merged
merged 19 commits into from Apr 2, 2023

Conversation

VeckoTheGecko
Copy link
Contributor

@VeckoTheGecko VeckoTheGecko commented Mar 26, 2023

This PR focusses on the following features (in order of implementation):

  • Initial conversion of rst docstrings to numpydoc format (with the help of pyment)
  • numpydoc docstring validators to ensure docstring quality
    • Install numpydoc docstring validators as part of the Sphinx build process
    • Ensure docstrings are compliant with chosen validators
    • Tying in docstring validation with CI/CD
  • Add types to docstring parameters (particularly focussing on popular modules).

PR contributes to #1324, where you can read more on this featureset.

Draft PR for visibility (and to trigger RTD builds).

(given the size of these diffs, let me know if you want me to break into multiple PRs)

When using `this tutorial <https://link1.com>`_ and `this tutorial <https://link2.com>`_ in two spots, theres a colision due to creating the "this tutorial" reference. Using a double underscore makes it an anonymous link resolving the issue
Only adding napolean for now to visualise docstrings. Will add numpydocs to validate later one the docstrings are in a better state.
Also remove invalid syntax in field.py
Worked on following modules:
parcels.interaction
parcels.interaction.neighborsearch
parcels.compilation
parcels.rng
parcels.tools.statuscodes
parcels.tools.converters
parcels.tools.loggers
parcels.plotting
parcels.scripts.plottrajectoriesfile
parcels.scripts.get_examples
@VeckoTheGecko
Copy link
Contributor Author

Done with initial conversion of docstrings to numpy format. Now moving onto docstring validation.

RTD handling docs means that old build path wasn't necessary. Updating to _build (scripts are still useful for local debugging)
@VeckoTheGecko
Copy link
Contributor Author

Numpydoc validators have been included in the build process (basically linting through docstrings, looking for things like "is the argument in the docstring the same as the one in the function call", ensuring the docstring is rendered correctly).

The full list of possible validation checks are outlined in the error codes. Some of the codes are incompatible with the codebase (either outright, or due to the state of many docstrings). Implementing all these codes is a very very low priority, but the small subset of codes at the moment are a good starting point (and additional codes can be included easily down the line if desired).

@VeckoTheGecko
Copy link
Contributor Author

Just confirming @erikvansebille , is this option checked in the Advanced Settings section of the RTD parcels project panel?
image

@erikvansebille
Copy link
Member

Just confirming @erikvansebille , is this option checked in the Advanced Settings section of the RTD parcels project panel?

Yep, that checkbox is on (see below), but the default branch is not set. Should I do that?

Screenshot 2023-03-27 at 19 12 38

@VeckoTheGecko
Copy link
Contributor Author

VeckoTheGecko commented Mar 28, 2023

Following on from this (10 year old) conversation, it doesn't look like builds are triggered from PRs originating from branches on forks. No matter though. My RTD build for this branch is available here. We'll review properly when merging new_docs -> master.

the default branch is not set. Should I do that?

No need 😄

These methods do not take a `field` parameter.
add_constant_field does not take parameter "units"
@erikvansebille
Copy link
Member

Thanks for digging into this

My RTD build for this branch is available here. We'll review properly when merging new_docs -> master.

That link seems to point to the RTD Issue? Can you update to the correct link?

@VeckoTheGecko
Copy link
Contributor Author

VeckoTheGecko commented Mar 28, 2023

Oops, yes, just updated

@VeckoTheGecko
Copy link
Contributor Author

VeckoTheGecko commented Mar 28, 2023

Used the regex \s:$ to search across the codebase for parameters with missing types. Added many types, will leave the rest to be gradually done over a longer timeframe.

PR ready for feedback/merge 😄 (or we can review it all at once when we merge new_docs to master)

@VeckoTheGecko VeckoTheGecko marked this pull request as ready for review March 28, 2023 06:47
Comment on lines +513 to +519
+-----------------------------+-----------------------------+-----------------------------+
| | V[k,j+1,i+1] | |
+-----------------------------+-----------------------------+-----------------------------+
|U[k,j+1,i] |W[k:k+2,j+1,i+1],T[k,j+1,i+1]|U[k,j+1,i+1] |
+-----------------------------+-----------------------------+-----------------------------+
| | V[k,j,i+1] + |
+-----------------------------+-----------------------------+-----------------------------+
Copy link
Member

Choose a reason for hiding this comment

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

@erikvansebille
Copy link
Member

Great work, @VeckoTheGecko; this new doc-formatting is much more pleasing to the eye indeed. We're not nearly at the same level of bumpy, but at least we're moving in the right direction. ;-)

A few outstanding general points, before we merge:

  • The title in your https://veckoparcels.readthedocs.io/en/docstrings/ version mentions v2.3.0; will that be the latest after we merge?
  • The copyright statement on the page bottom could/should be updated to 2023?
  • Should we add these commits (especially the really large ones) to the .git-blame-ignore-revs file too?

@VeckoTheGecko
Copy link
Contributor Author

VeckoTheGecko commented Apr 2, 2023

The title in your https://veckoparcels.readthedocs.io/en/docstrings/ version mentions v2.3.0; will that be the latest after we merge?

As of 398ba3b the version number is determined automatically using the parcels.__version__ attribute. new_docs (the target of this PR) is at v2.3.0. When we re-sync and merge new_docs into master it will be at the intended version.

The copyright statement on the page bottom could/should be updated to 2023?

Can do. Should we dynamically determine the year for the copyright statement? i.e. update the copyright statement from:

copyright = '2022, The OceanParcels Team'

to

copyright = f"{datetime.datetime.now().year}, The OceanParcels Team"

Happy to fix this in a separate PR.

Should we add these commits (especially the really large ones) to the .git-blame-ignore-revs file too?

I don't think so. The purpose of .git-blame-ignore-revs is to ignore (large) superfluous changes that in the end have no effect on the function of the code (eg. introducing black, introducing isort, whitespace. These are mainly created by automated formatting tools) and would otherwise soil the blame. These commits here mark a shift in how the codebase works with docstrings, and introduce additional edits to the docstrings, which are worth keeping in blame.

@erikvansebille
Copy link
Member

OK is fine, let's then just go for it. The integration tests have skipped (not sure why), but I guess we can merge without these in this case, because only docstrings are affected in this PR?

@VeckoTheGecko
Copy link
Contributor Author

The integration tests have skipped (not sure why)

#1335 rearing its head again 😕

And yes, only docstrings/doc related changes.

@VeckoTheGecko VeckoTheGecko merged commit 6f02481 into OceanParcels:new_docs Apr 2, 2023
6 of 7 checks passed
@VeckoTheGecko VeckoTheGecko deleted the docstrings branch April 2, 2023 14:15
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.

None yet

2 participants