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

numpydoc pre-commit hook #16

Closed
wants to merge 11 commits into from
Closed

Conversation

jdeschamps
Copy link
Member

@jdeschamps jdeschamps commented Oct 27, 2023

Add numpydoc pre-commit hook to enforce numpy docstring format.

Started using this and I am pretty happy with it. There are however some hiccups with mkdocstring, which I have not really examined yet (e.g. md lists not formatted).

@tlambert03
Copy link
Contributor

We already have ruff doing something similar: https://docs.astral.sh/ruff/rules/#pydocstyle-d

And https://docs.astral.sh/ruff/settings/#pydocstyle

What need were you finding that this additional hook fills?

@jdeschamps
Copy link
Member Author

jdeschamps commented Oct 27, 2023

Yes, sorry I overlooked that part a little bit.

[EDIT]: Let's do things properly, I moved my answer to #18.

@jdeschamps jdeschamps reopened this Oct 31, 2023
@jdeschamps
Copy link
Member Author

jdeschamps commented Oct 31, 2023

New behaviour:

use_ruff:
  when: "{{ mode == 'customize' and use_pre_commit }}"
  type: bool
  help: Add ruff for linting?
  default: "{{ mode != 'simple' }}"

use_pydocstyle:
  when: "{{ mode == 'customize' and use_pre_commit and use_ruff }}"
  type: bool
  help: Use pydocstyle (via ruff) for checking documentation compliance?
  default: "{{ use_ruff }}"

use_numpydoc:
  when: "{{ mode == 'customize' and use_pre_commit and not use_pydocstyle }}"
  type: bool
  help: Use numpydoc for checking documentation compliance?
  default: "{{ not use_pydocstyle and mode != 'simple'}}"

pydocstyle and numpydoc are mutually exclusive, and only available if use_pre_commit == True (for both) and use_ruff == True (pycodestyle).

They are both not present in "Simple" mode, and only pydocstyle is set in "Fully featured".

The awkward thing right now is that when choosing pydocstyle, one doesn't know about numpydoc. One could modify the pydocstyle question to mention numpydoc.

@tlambert03
Copy link
Contributor

looking good.

The awkward thing right now is that when choosing pydocstyle, one doesn't know about numpydoc. One could modify the pydocstyle question to mention numpydoc.

yeah, perhaps instead of the two-step process, you could use choices:

something like

docstring_linter:
    when: "{{ mode == 'customize' and use_pre_commit }}"
    type: str
    choices:
        Use pydocstyle (via ruff): pydocstyle
        Use numpydoc: numpydoc
        no docstring linter: null

i guess if they said "no ruff" though, it would be best to remove the (via ruff) option... haven't checked whether you can make the set of choices conditional

@jdeschamps
Copy link
Member Author

Makes a looot more sense. I'll check it out!

@tlambert03
Copy link
Contributor

mind if i close this? :)

@tlambert03 tlambert03 closed this Sep 26, 2024
@jdeschamps
Copy link
Member Author

Nope!

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.

2 participants