airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Enable More PyDocStyle Checks

Open kaxil opened this issue 5 years ago • 64 comments

~~We use PyDocStyle in pre-commit to enforce docstring style~~

We use Ruff to enforce docsting style https://github.com/apache/airflow/blob/23b8e839a35e84d57c5cf38b0b21171ac3bd1ecc/pyproject.toml#L47-L74

We follow pep257 style (http://www.pydocstyle.org/en/stable/error_codes.html) for checks.

Currently, we ignore the following rules:

The task is to complete the following missing rules:

Missing Docstrings

  • [ ] D100 | Missing docstring in public module
  • [ ] D102 | Missing docstring in public method
  • [ ] D104 | Missing docstring in public package
  • ~[ ] D105 | Missing docstring in magic method~ : As discussed in https://lists.apache.org/thread/8jbg1dd2lr2cfydtqbjxsd6pb6q2wkc3, https://github.com/apache/airflow/pull/38452 - we remove the D105 rule from our checks.
  • [ ] D107 | Missing docstring in __init__

Whitespace Issues

  • [x] D200 | One-line docstring should fit on one line with quotes -- (https://github.com/apache/airflow/pull/11688)
  • [x] D202 | No blank lines allowed after function docstring -- (https://github.com/apache/airflow/pull/11032)
  • [x] D204 | 1 blank line required after class docstring -- (https://github.com/apache/airflow/pull/11031)
  • [x] D205 | 1 blank line required between summary line and description

Docstring Content Issues

  • [x] D400 | First line should end with a period
  • [x] D401 | First line should be in imperative mood https://github.com/apache/airflow/issues/37256

It would be good if we can enable them one by one -- separate PRs are ok

Let me know if you need any help

kaxil avatar Sep 05 '20 01:09 kaxil

I've taken:

  • [x] D204

Might be an idea @kaxil to add a checklist for all rules needing updating in the initial issue comment. This way potential contributors can know which ones are done and which are still open to do? Just a quality of life idea so we don't have to look at the PRs individually.

pcandoalmeida avatar Sep 19 '20 23:09 pcandoalmeida

@pcandoalmeida That's a good idea, I updated the description and added a check-box.

kaxil avatar Sep 19 '20 23:09 kaxil

Hi @kaxil I'm working on D202 now.

pcandoalmeida avatar Sep 20 '20 10:09 pcandoalmeida

Morning @kaxil what do you think about adding the Hacktoberfest label to this issue?

pcandoalmeida avatar Sep 25 '20 10:09 pcandoalmeida

Morning @kaxil what do you think about adding the Hacktoberfest label to this issue?

Good idea again, just added :)

kaxil avatar Sep 25 '20 10:09 kaxil

Hi I wanna try D205. Can I try this ?

ktrueda avatar Oct 10 '20 16:10 ktrueda

I started to fix D205 (1 blank line required between summary line and description). It's difficult because a lot of docs has not summary line.

For example, https://github.com/apache/airflow/blob/d86cf37a35b69fea806be7610deb332468dfba4b/airflow/configuration.py#L481-L486

This docs has no summary line and there are a lot of docs like this. I cannot make summary line for all these docs. If I deal all docs as summary line, the doc obey D205. But it is not easy to read.

How can I do that? If someone has any idea, please help me.

ktrueda avatar Oct 11 '20 05:10 ktrueda

@ktrueda You can do 2 things:

  1. Add a summary line:
Remove an option if it exists in config from a file or 
default config. 

If both of config have the same option, this removes 
the option in both configs unless remove_default=False.
  1. Only update blank line for which docstrings exists. In this case, we won't be able to enable D205 for all of them but when in future we have summary lines, it would make the word easier.

I would prefer (1) though

kaxil avatar Oct 11 '20 20:10 kaxil

@kaxil Thank you for your help. I would prefer (1) too. So I'll try that way.

Since I found thousands of docs to fix, I need much times. Leave it to me.

ktrueda avatar Oct 12 '20 13:10 ktrueda

@kaxil Can I take D200?

potix2 avatar Oct 20 '20 05:10 potix2

Hiya 👋🏼 @potix2 I believe D200 is currently being worked on 😃

pcandoalmeida avatar Oct 20 '20 10:10 pcandoalmeida

@pcandoalmeida Yeah, I'm working on it. I'll send a pull request soon.

potix2 avatar Oct 20 '20 12:10 potix2

I'm working on D400.

potix2 avatar Oct 23 '20 14:10 potix2

I would like to tackle this issue if it hasn't been assigned recently. Thanks! @uranusjr :)

peter0083 avatar Sep 26 '21 06:09 peter0083

Go ahead 👍 Note that the ignore list above is out of date; please find the correct list in the pre-commit config file on main.

uranusjr avatar Sep 26 '21 06:09 uranusjr

status update:

  • Haven't forgotten this issue 🐌. I'm still working D205 and would like to ask if there is an automated way to apply all the changes. If not, I will probably switch from my MacBook Air to my Linux which is more powerful which I hope can reduce the wait time when it goes through the pre-commit checks.

many thanks!

peter0083 avatar Nov 13 '21 17:11 peter0083

Maybe try docformatter? You’d probably want to do this in small batches, maybe even one file at a time, to see how well it works.

uranusjr avatar Nov 13 '21 20:11 uranusjr

Maybe try docformatter? You’d probably want to do this in small batches, maybe even one file at a time, to see how well it works.

sounds good. I will give docformatter a shot. thank you for the tips. @uranusjr. 🙏

peter0083 avatar Nov 14 '21 19:11 peter0083

I'm working on D400.

hi @potix2 Do still wish to work on it?

eladkal avatar Feb 14 '22 17:02 eladkal

@eladkal I gave up D400, because I got too many conflicts. I'm sorry for late reply.

potix2 avatar Mar 30 '22 15:03 potix2

@eladkal sorry I give up on D205. I will let other developers tackle this one 😞

peter0083 avatar Apr 09 '22 06:04 peter0083

@eladkal, is somebody working here: D400(First line should end with a period)? If not, I'd like to give it a try.

edithturn avatar Jun 27 '22 16:06 edithturn

feel free!

eladkal avatar Jun 27 '22 17:06 eladkal

@eladkal @kaxil I took D400, there are a lot of files there 😄 . My question is in this part where we have a long first line Screen Shot 2022-06-30 at 18 33 52

Pre commits (D400) is asking to add a period at the end of the line, It is not the case, I think. Should I just remove the new line and convert it in a single line to avoid have that issue?

edithturn avatar Jun 30 '22 23:06 edithturn

Simply removing the newline would trigger another check complaining the line is too long. It would be best to rewrite it and split the sentence into two shorter ones. This particular exampel can be rewritten to

Check metric values are within a certain tolerance.

The metrics are given as SQL expressions, and the tolerance with parameter *days_back*.

uranusjr avatar Jul 01 '22 08:07 uranusjr

Simply removing the newline would trigger another check complaining the line is too long. It would be best to rewrite it and split the sentence into two shorter ones. This particular exampel can be rewritten to

Check metric values are within a certain tolerance.

The metrics are given as SQL expressions, and the tolerance with parameter *days_back*.

Hard to automate I am a afraid :(

potiuk avatar Jul 01 '22 17:07 potiuk

@potiuk @uranusjr I counted all the changes that are needed for D400, they are 3150 changes. Finish this in a single PR could be hard. I got an idea. How about to keep ignoring D400 in pre-commits - --add-ignore=D100,D102,D103,D104,D105,D107,D202,D400,D401,D205 and still working in minitaks (100 or 200 files) and send PR fixing what @uranusjr is saying? I could make progress in this way. What do you think?

edithturn avatar Jul 01 '22 22:07 edithturn

@edithturn SGTM. The smaller the changes are, the easier it will be to review and merge.

mik-laj avatar Jul 04 '22 19:07 mik-laj

Yep

potiuk avatar Jul 06 '22 22:07 potiuk

Thanks, it is better!

edithturn avatar Jul 07 '22 00:07 edithturn