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

Turn on documentation rules in pre-commit #406

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

emolter
Copy link
Contributor

@emolter emolter commented Feb 19, 2025

Resolves JP-3885

Closes spacetelescope/jwst#9182

This PR turns on the Ruff "D" rules and numpydoc-validation pre-commit hook in order to ensure that all docstrings in stdatamodels follow the same style as jwst.

In order to bring the repository into compliance, I had to add a lot of brand-new docstrings to specific reference models, and these were not always models that I understand very well - during review, please pay special attention to these.

A few docstrings, specifically in wcs_ref_models.py, remain that I couldn't easily figure out how to populate because I didn't know enough about how the distortion models work. Hopefully one of the reviewers can provide clarity there.

Tasks

  • update or add relevant tests
  • update relevant docstrings and / or docs/ page
  • Does this PR change any API used downstream? (if not, label with no-changelog-entry-needed)
    • write news fragment(s) in changes/: echo "changed something" > changes/<PR#>.<changetype>.rst (see below for change types)
    • run jwst regression tests with this branch installed ("git+https://github.com/<fork>/stdatamodels@<branch>")
news fragment change types...
  • changes/<PR#>.feature.rst: new feature
  • changes/<PR#>.bugfix.rst: fixes an issue
  • changes/<PR#>.doc.rst: documentation change
  • changes/<PR#>.removal.rst: deprecation or removal of public API
  • changes/<PR#>.misc.rst: infrastructure or miscellaneous change

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.44%. Comparing base (4e83608) to head (5331100).
Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #406      +/-   ##
==========================================
+ Coverage   78.16%   78.44%   +0.27%     
==========================================
  Files         115      109       -6     
  Lines        5144     5084      -60     
==========================================
- Hits         4021     3988      -33     
+ Misses       1123     1096      -27     

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nden Would you please take a look at all the TODOs in this file? Or if you're unfamiliar with these, maybe you know who is familiar?

@emolter emolter marked this pull request as ready for review February 19, 2025 16:56
@emolter emolter requested a review from a team as a code owner February 19, 2025 16:56
Copy link
Collaborator

@braingram braingram left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together. I haven't finished reviewing the changes but figured I'd submit the comments so far.

I did not yet review:

  • jwst.datamodels.wcs_ref_models.py
  • jwst.transforms.models

Returns `True` if the given `key` is a built-in FITS keyword, i.e.
a keyword that is managed by ``astropy.io.fits`` and we wouldn't
want to propagate through the `_extra_fits` mechanism.
Check if key is a fits builtin.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Check if key is a fits builtin.
Check if key is a FITS builtin.

pyproject.toml Outdated
@@ -119,6 +119,27 @@ select = [
"E722",
]

[tool.numpydoc_validation]
checks = [
"all",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since all is here do we need the other rules?

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 syntax gives us "all" except the rules added below.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the clarification. Would you add a comment here describing that?


Parameters
----------
hdulist : weakref.ReferenceType
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a weakref? From the usage here it looks to be an HDUList proper:

hdu = get_hdu(hdulist, hdu_name, index=index)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right it's a HDUlist, will update

@@ -742,7 +813,25 @@ def from_fits(hdulist, schema, context, skip_fits_update=None, **kwargs):

def from_fits_asdf(hdulist, ignore_unrecognized_tag=False, **kwargs):
"""
Wrap asdf call to extract optional arguments
Wrap asdf call to extract optional arguments.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this docstring summary makes sense any more. This is much more than a "wrap".

Suggested change
Wrap asdf call to extract optional arguments.
Open the ASDF extension from a FITS hdulist.
If the ASDF extension doesn't exist a new asdf.AsdfFile
instance will be returned.

@@ -911,6 +1011,19 @@ def fits_hash(hdulist):


def get_short_doc(schema):
"""
Get the short description from the schema.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Get the short description from the schema.
Combine the title and description of a schema.

Does this need a docstring? Can we instead make it private? The code seems messy and writing a docstring that describes the behavior would make this docstring even longer (and it's already longer than the code).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I think it's fine to make private, will do

@@ -330,6 +354,8 @@ def instance(self):


class ObjectNode(Node):
"""A schema-validated dictionary-like structure."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""A schema-validated dictionary-like structure."""
"""A dictionary-like Node."""

@@ -410,6 +436,8 @@ def items(self):


class ListNode(Node):
"""A list of schema-validated objects."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""A list of schema-validated objects."""
"""A list-like Node."""

@@ -144,9 +154,21 @@ def _as_fitsrec(val):

def _get_schema_type(schema):
"""
Find the type of a schema and its subschemas.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Find the type of a schema and its subschemas.
Find the type or types used by a schema.

Comment on lines 170 to 171
schema_type : str
The type of the schema, or 'mixed' if the schema has multiple types.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
schema_type : str
The type of the schema, or 'mixed' if the schema has multiple types.
str
The type used by a schema or 'mixed' if the schema has multiple types.

"""
Re-validate the model instance against its schema
"""
"""Re-validate the model instance against its schema."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""Re-validate the model instance against its schema."""
"""Validate the model instance against its schema."""

@emolter emolter force-pushed the numpydoc-validation branch from d89463b to 21e9014 Compare February 24, 2025 18:21
@emolter emolter force-pushed the numpydoc-validation branch from 21e9014 to 5331100 Compare February 27, 2025 15:01
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.

Enable numpydoc-validation style check in stdatamodels
2 participants