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

Added linting of docstrings #580

Merged
merged 3 commits into from
Jun 10, 2024
Merged

Added linting of docstrings #580

merged 3 commits into from
Jun 10, 2024

Conversation

Sherwin-14
Copy link
Contributor

@Sherwin-14 Sherwin-14 commented May 21, 2024

I have added the linting for docstrings. Please have a look at it ;) Resolves #454


📚 Documentation preview 📚: https://earthaccess--580.org.readthedocs.build/en/580/

@Sherwin-14
Copy link
Contributor Author

@mfisher87 Hey, the hooks failed on this one because it had picked up the errors identified by ruff. How can we tackle this?

Copy link
Collaborator

@mfisher87 mfisher87 left a comment

Choose a reason for hiding this comment

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

Wow, that produced a lot of new linting errors 😆 😅

I think we can, for now, ignore the D1* errors in the pyoroject.toml settings because it's going to be a lot of work to add docstrings to every module, class, and function.

Ruff seems to have autofixers for most of the D2* and D4* errors. I'd try running ruff with ruff check --fix, and if that doesn't fix enough things, try ruff check --fix --unsafe-fixes. If you need to use unsafe fixes, please keep an extra eye out for anything weird :)

pyproject.toml Outdated Show resolved Hide resolved
@mfisher87
Copy link
Collaborator

@Sherwin-14 I'd highly recommend using Ruff with pre-commit instead of installing it standalone. Once you have installed pre-commit, you can use it to install hooks for this project with pre-commit install. Then, every time you run a commit, checks and even automatic fixes will occur, preventing you from pushing commits that might fail checks later! It's my favorite tool :) You can also trigger checks manually with pre-commit run -a.

We also use it on the Benefit Tool project.

@Sherwin-14
Copy link
Contributor Author

Sherwin-14 commented May 21, 2024

@mfisher87 Hey Matt, even with your suggestion of unsafe fixes we still have 258 unsolved errors.

@mfisher87
Copy link
Collaborator

Sounds like it auto-fixed about 500 errors, nice! Can you commit and push those? Then I can see what kind of errors are left. Maybe we want to set those to ignored.

What about ignoring the D1* rules? How many errors did that eliminate?

@Sherwin-14
Copy link
Contributor Author

Sherwin-14 commented May 21, 2024

I found 159 errors barring D1*

@mfisher87
Copy link
Collaborator

Can you push those changes up?

@mfisher87
Copy link
Collaborator

mfisher87 commented May 21, 2024

Surprised D205 wasn't autofixed... weird. D417 and any others you're still getting you can add to the ignore list along with D1. All these autofixes are already a huge improvement, and we can un-ignore and fix more errors as time goes on. If you are willing to manually fix any of these errors, you're also welcome to do that :)

@mfisher87 mfisher87 marked this pull request as draft May 21, 2024 16:45
@mfisher87 mfisher87 marked this pull request as ready for review May 21, 2024 16:46
@mfisher87
Copy link
Collaborator

Woops, didn't mean to make this draft.

@Sherwin-14
Copy link
Contributor Author

I think I should push the changes, adding D417 errors to the ignore list as well. What do you think about this? Also fixing some of those issues is something I too considered ;)

Copy link
Collaborator

@mfisher87 mfisher87 left a comment

Choose a reason for hiding this comment

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

I think one last tweak and we're ready to go. Nice work!

pyproject.toml Outdated Show resolved Hide resolved
@Sherwin-14 Sherwin-14 force-pushed the linting branch 3 times, most recently from dc87dd7 to caad446 Compare May 23, 2024 10:28
Copy link
Collaborator

@mfisher87 mfisher87 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @Sherwin-14 !

Will plan to merge tomorrow just in case anyone wants to take a last look. CC participants of the discussion that originated this need: @danielfromearth @jhkennedy @andypbarrett

@danielfromearth
Copy link
Collaborator

danielfromearth commented May 24, 2024

Yay, I'm glad to see these changes!

One thing that I don't mind one way or the other, but I'm curious...

Docstrings like this (in auth.py):

def get_s3_credentials(
        self,
        daac: Optional[str] = None,
        provider: Optional[str] = None,
        endpoint: Optional[str] = None,
    ) -> Dict[str, str]:
        """Gets AWS S3 credentials for a given NASA cloud provider.
        The easier way is to use the DAAC short name; provider is optional if we know it.

        Parameters
        ----------
            daac: The name of a NASA DAAC, e.g. NSIDC or PODAAC.
            provider: A valid cloud provider. Each DAAC has a provider code for their cloud distributions.
            endpoint: Getting the credentials directly from the S3Credentials URL.

        Returns
        -------
            A Python dictionary with the temporary AWS S3 credentials.

        """

...it looks to me like a combination of Google style (with each parameter indented) and numpy style (using ------- lines below the section names; though, for numpy style, parameters wouldn't be indented). Is this combination a ruff-specific style? Does anyone here know?

@mfisher87
Copy link
Collaborator

@mfisher87 mfisher87 self-requested a review May 24, 2024 15:37
Copy link
Collaborator

@mfisher87 mfisher87 left a comment

Choose a reason for hiding this comment

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

@Sherwin-14 I forgot a critical piece! If you check the links in the post above this one, the docs aren't rendering correctly anymore because I forgot we need to set the correct style.

[tool.ruff.lint.pydocstyle]
convention = "google"

To re-apply the rules, we need to run the --fix (maybe also unsafe) operation. We may need/want to un-do the previous fix operation (keeping only changes to pyproject.toml) prior to re-running the fix.

@Sherwin-14
Copy link
Contributor Author

Ruff does not specify a convention by default, select however can be used to specify a small subset of a convention so you can mix and match different parts of a convention which I think is what is going on.

@mfisher87
Copy link
Collaborator

mfisher87 commented May 24, 2024

Ruff does not specify a convention by default, select however can be used to specify a small subset of a convention so you can mix and match different parts of a convention which I think is what is going on.

True, though we use the google convention, so we can use the convention = "google" setting in my previous post as a shortcut for selecting rules. From the docs FAQ on the conventions:

The Google convention includes all D errors apart from: D203, D204, D213, D215, D400, D401, D404, D406, D407, D408, D409, and D413.

By default, no convention is set, and so the enabled rules are determined by the select setting alone.

EDIT: I think I mis-read your post and I'm just re-stating what you said 😆

@mfisher87
Copy link
Collaborator

Copy link
Collaborator

@mfisher87 mfisher87 left a comment

Choose a reason for hiding this comment

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

Hey Sherwin, sorry for another wrench in the works! Looks like we're so close to being there but Ruff seems to have caused some doc pages to render incorrectly because it was too aggressive with trying to populate a subject line. We'll need to do a bit of manual editing to fix it as far as I can tell. If you feel comfortable writing a docstring subject line, that would be so appreciated! But otherwise we can just leave it as TODO. or Placeholder. so the docs render correctly and come back to it later.

If those manual edits pan out to be too time consuming, feel free to ask for help :)

"""???+ Info
The DataCollection class queries against
https://cmr.earthdata.nasa.gov/search/collections.umm_json,
the response has to be in umm_json to use the result classes.
Copy link
Collaborator

@mfisher87 mfisher87 May 26, 2024

Choose a reason for hiding this comment

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

Looks like the linter messed up the indentation on this info box , so now it renders as empty (here: https://earthaccess--580.org.readthedocs.build/en/580/user-reference/collections/collections-query/)! :(

I think this happened because there's no subject line in the docstring like there should be. I think we need to add that. A placeholder would be OK, since there's nothing there right now. Are you OK with adding Placeholder. as the first line for docstrings missing a subject? (NOTE: No need to add any new docstrings)

Returns:
The data visualization links, usually the browse images.
"""Returns:
The data visualization links, usually the browse images.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The docs for this function also didn't render correctly because of a missing subject line :(

https://earthaccess--580.org.readthedocs.build/en/580/user-reference/granules/granules/#earthaccess.results.DataGranule.dataviz_links

@mfisher87 mfisher87 dismissed their stale review May 26, 2024 16:30

Stale

@Sherwin-14
Copy link
Contributor Author

Sherwin-14 commented May 26, 2024 via email

@mfisher87
Copy link
Collaborator

Hey Matt, wouldn't it be better to configure ruff to ignore this!

What are you suggesting we configure ruff to ignore? If we can turn off a rule and fix that behavior I'm for it :)

@Sherwin-14
Copy link
Contributor Author

Sherwin-14 commented May 31, 2024

@mfisher87 Hey Matt, apparently numpy is an implicit dependency brought by one of your packages. This version however, requires distutils which has been removed from Python 3.12 .

@chuckwondo
Copy link
Collaborator

@mfisher87 Hey Matt, apparently numpy is an implicit dependency brought by one of your packages. This version however, requires distutils which has been removed from Python 3.12 .

We don't yet officially support Python 3.12, but thanks for the reminder. I have an unfinished PR that I have to wrap up. Part of the remaining work in that PR is specifically to address this issue by distinguishing numpy versions based upon Python versions. See #571.

earthaccess/search.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@mfisher87 mfisher87 left a comment

Choose a reason for hiding this comment

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

Nice! @chuckwondo @danielfromearth any last minute thoughts?

Copy link
Collaborator

@mfisher87 mfisher87 left a comment

Choose a reason for hiding this comment

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

Ugh, I was too hasty. There's one problem left that I can see.

The collection data type, i.e. HDF5, CSV etc., if available.
"""Placeholder.

Returns: The collection data type, i.e. HDF5, CSV etc., if available.
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Sherwin-14
Copy link
Contributor Author

@mfisher87 Hey sorry about that I have fixed the issue now.you can take a look at it ;)

Copy link
Collaborator

@mfisher87 mfisher87 left a comment

Choose a reason for hiding this comment

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

A couple more spacing changes. Sorry this is so finnicky :)

earthaccess/results.py Outdated Show resolved Hide resolved
earthaccess/results.py Outdated Show resolved Hide resolved
earthaccess/results.py Outdated Show resolved Hide resolved
earthaccess/results.py Outdated Show resolved Hide resolved
earthaccess/results.py Outdated Show resolved Hide resolved
@danielfromearth danielfromearth self-requested a review June 5, 2024 14:34
Copy link
Collaborator

@danielfromearth danielfromearth left a comment

Choose a reason for hiding this comment

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

This looks good! A couple of additional docstring suggestions:

(I wish I could've just used the "suggest changes" feature in GitHub, but it seems like for now you can only do that on lines that have already been changed)

@mfisher87
Copy link
Collaborator

Hey @danielfromearth these are all great ideas! I'd like to keep the scope on this PR as small as possible, though. We only added "Placeholder" where we needed it to enable the other parts of the docstring to work without the new linter rules messing stuff up, for example where there was no subject line but there were parameter definitions. Would you mind creating an issue for those items?

Copy link
Collaborator

@mfisher87 mfisher87 left a comment

Choose a reason for hiding this comment

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

Things look great, docs look great... last call anyone? @danielfromearth @chuckwondo ?

@chuckwondo
Copy link
Collaborator

All good by me.

@mfisher87 mfisher87 merged commit 9f43047 into nsidc:main Jun 10, 2024
11 checks passed
@mfisher87
Copy link
Collaborator

mfisher87 commented Jun 10, 2024

🚀 @Sherwin-14 Thanks so much for your help with locking down our docstrings!

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.

add linting of docstrings, using ruff
4 participants