Skip to content

Conversation

@VeckoTheGecko
Copy link
Contributor

We should use numpydoc to validate docstrings that are part of our public API (validating all the API would be very overkill). The numpydoc CLI tool, as well as ruff, do not have support for delineating what is part of the public and private API since they operate on the file level. You can specify which files to run on - but this doesn't work for us (or many other packages) which import from private modules to expose items in the public API. These tools cannot - for example - import a package and traverse down the package's __all__ variables.

Numpydoc does however have a Sphinx integration which does work quite well for linting the public API (after all, this public API is showed in the API reference, and the goal of numpydoc is to provide high quality user documentation). Running a full Sphinx build (which in our case also runs our notebooks) is a lot just to find a missing comma in a docstring.

This PR does the following:

  • Creates tools/numpydoc-public-api.py script (use -v, -vv etc. to increase the verbosity of the script)
    • This script imports parcels walks down the package structure following the __all__ variables to discover the public API
  • Updates pixi.toml to expose this script via a task numpydoc-lint
  • Updates conf.py to work from the shared tool data

We need to review the errors to skip in the numpydoc_skip_errors section of tools/tool-data.toml to see which rules we want to ignore. Currently we ignore them all.

Unfortunately I don't think we can make this into a pre-commit hook, as the script requires installing Parcels.

I think this should will be sufficient. Closes #1971

This PR is also the result of some of the discussions I had with scipy folks - as alluded to in #1971 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this does create another folder tools in the root of the repository. I think its fine here - and also allows us to add any other tools we need in future. Putting it in .github didn't really seem appropriate since it doesn't have to do with github or really with CI

Though it does bump the README down one item. Open to ideas

Copy link
Member

Choose a reason for hiding this comment

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

Yes, not ideal to add another folder. But we could/should get rid of tests-v3 soon(ish) so that reduced the folder structure by one line ;-)

Any other files/folders we can move?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any other files/folders we can move?

Just had a look - I don't think so

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went ahead and categorised these - mapping out future work that can be done on the docstrings. Happy to go over these together if you want @erikvansebille

"UP", # pyupgrade
"LOG", # logging
"ICN", # import conventions
"G", # logging-format
Copy link
Contributor Author

Choose a reason for hiding this comment

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

introduced in 6167adb

Copy link
Member

@erikvansebille erikvansebille left a comment

Choose a reason for hiding this comment

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

Looks good to me! Fixing the warnings will be another PR, I assume?

@VeckoTheGecko
Copy link
Contributor Author

VeckoTheGecko commented Jan 15, 2026

Fixing the warnings will be another PR, I assume?

Yes, definitely. I also need to check that the docs are flagging warnings correctly (in a way that we can address them) - also another PR

I'll probably also make another issue for the docstrings - I can imagine getting them up to scratch will be over a longer timespan

VeckoTheGecko and others added 10 commits January 15, 2026 14:09
They have a new release
- Create tools/numpydoc-public-api.py script
- Update pixi.toml to expose this script via a task numpydoc-lint
- Update conf.py to work from the shared tool data
We should properly consider this later when we add logging to other parts of the code - but from the outset it doesn't seem like that useful a rule.
@VeckoTheGecko VeckoTheGecko enabled auto-merge (squash) January 15, 2026 13:09
@VeckoTheGecko VeckoTheGecko merged commit 3025125 into Parcels-code:v4-dev Jan 15, 2026
9 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Parcels development Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Validate public API docstrings using Ruff

2 participants