Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Allow per-function skips #203

Merged
merged 5 commits into from
Sep 2, 2016
Merged

Allow per-function skips #203

merged 5 commits into from
Sep 2, 2016

Conversation

larsoner
Copy link
Contributor

@larsoner larsoner commented Aug 30, 2016

Allows per-function skips. Ready for review/merge from my end.

I added tests and updated docs in hopefully correct ways.

Closes #202.
Closes #97.

Comments like "#noqa" can be added to the end of function
and method definitions to skip checks.
@sigmavirus24
Copy link
Member

I'm starting to think that certain things should be part of reusable library code because now pycodestyle, pydocstyle, and flake8 have just slightly different implementations of almost the same thing and that's going to lead to really weird inconsistencies between the three.

Further, from what I can tell, this will directly conflict with people running pydocstyle from inside Flake8 (e.g., via flake8-docstrings), which is something I'm strongly against.

@larsoner
Copy link
Contributor Author

Further, from what I can tell, this will directly conflict with people running pydocstyle from inside Flake8 (e.g., via flake8-docstrings), which is something I'm strongly against.

How do you mean? # noqa will turn off both flake8 and pydocstyle, whereas doing something like # pydocstyle: D101 should only affect pydocstyle, and in theory something like # pydocstyle: D101 flake8: E204 should work fine too.

@larsoner
Copy link
Contributor Author

I'm starting to think that certain things should be part of reusable library code because now pycodestyle, pydocstyle, and flake8 have just slightly different implementations of almost the same thing and that's going to lead to really weird inconsistencies between the three.

This might be true, but I'd prefer to do that as a separate subsequent refactoring. It will be hard to get all these libraries to settle on and adopt a new shared API, and in the meantime, something like this is badly needed for this library to be usable for many people.

@larsoner
Copy link
Contributor Author

Actually it looks like flake8 offers:

  1. # noqa to ignore everything (and really this probably should cause pydocstyle to ignore it, too)
  2. # noqa: E501 so we can easily piggyback on that with e.g. # noqa: E501,D101 in a compatible way. I tested this in flake8 and it works fine.
  3. # flake8: noqa we can again piggyback with # flake8: noqa pydocstyle:noqa in a compatible way. I tested this with flake8 and it works fine.

So I don't see any conflicts in this scheme...?

* Added the ability to ignore specific function and method doctstrings with
comments:

1. "# noqa" or "# pydocstyle: noqa" skips all checks.
Copy link
Member

Choose a reason for hiding this comment

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

@Eric89GXL This and # pydocstyle: D102,D203 are what I'm talking about. You should just use # noqa below. Even so, having # pydocstyle: noqa in a file will skip the whole file? That's what people are going to expect from having used # flake8: noqa. You're going to confuse people with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sigmavirus24
Copy link
Member

This might be true, but I'd prefer to do that as a separate subsequent refactoring.

Absolutely, but that means the logic in this PR would only complicate that because it's completely turning the semantics of these comments on their head. I don't see a need to use # pycodestyle: <codes> as the prefix here. pydocstyle and flake8 have an overlap in developers. Reusing # noqa: <codes> seems reasonable. It will also keep comments succinct.

@larsoner
Copy link
Contributor Author

@sigmavirus24 Got rid of # pydocstyle: noqa and it should be fully compatible with flake8 now, feel free to see if you're happy with it

@jayvdb
Copy link
Member

jayvdb commented Aug 31, 2016

Do you really need to invoke pydocstyle directly, and add noqa support into pydocstyle ?

Could you use flake8-docstrings which gives you # noqa or also add flake8-putty to give you # flake8: disable=<codes> (but is customisable to support # noqa: <codes>) ?

@larsoner larsoner closed this Aug 31, 2016
@larsoner
Copy link
Contributor Author

I'll try those alternatives

@larsoner
Copy link
Contributor Author

larsoner commented Sep 1, 2016

@jayvdb I tried pip install flake8-docstrings and then doing flake8 instead of pydocstyle. It does respect # noqa and # noqa: D103, which helps. But at least at a first pass it has some drawbacks out of the box:

  1. It doesn't respect the pydocstyle set of skips/includes in setup.cfg. So I'm not sure how to have flake8 run on one set of files for style and another set of files for pyflakes and pep8 without having to pass arguments to each (cumbersome and defeats purpose of config).
  2. Installing it this way makes flake8 by default always do pydocstyle checks, which is undesirable. I assume there is a way to have it "off" by default (?), but this again adds barrier to entry with every additional step necessary to configure their system.

I assume there are workarounds for this, but isn't it less clean than having pydocstyle respect # noqa and # noqa: <codes> when invoked on its own? After all, isn't pydocstyle designed to be run on its own? The documentation makes it seem that way. With this PR, I can just tell people "run pip install flake8 pydocstyle; flake8; pydocstyle" and everything will work properly, and it doesn't seem so obvious with the flake8 case. But it seems like there is sustained opposition to having this functionality here, so I'll drop it unless you're enthusiastic about it.

@jayvdb
Copy link
Member

jayvdb commented Sep 1, 2016

flake8-putty solves 1.
You can disable pydocstyle by default, using ignore=D, but again you probably wont need this if you use flake8-putty to decide what parts of the code that pydocstyle should be used or ignored.

@sigmavirus24
Copy link
Member

@Eric89GXL note, that there are many teams in the PyCQA and @jayvdb is a member of one (which is not the team that maintains pydocstyle).

My opposition was merely in having divergent behaviour between two projects which you seem to have resolved.

If you have need for specific configuration from pydocstyle in flake8's configuration through flake8-docstrings you can create an issue on https://gitlab.com/pycqa/flake8-docstrings and we can work towards fixing those deficiencies you're finding.

@larsoner
Copy link
Contributor Author

larsoner commented Sep 1, 2016 via email

@larsoner
Copy link
Contributor Author

larsoner commented Sep 1, 2016 via email

@larsoner
Copy link
Contributor Author

larsoner commented Sep 1, 2016

So this PR's documentation / API proposal was:

``pydocstyle`` inline commenting to skip specific checks on specific
functions or methods. The supported comments that can be added are:

1. ``"# noqa"`` skips all checks.

2. ``"# noqa: D102,D203"`` can be used to skip specific checks. Note that
   this is compatible with skips from `flake8 <http://flake8.pycqa.org/>`_,
   e.g. ``# noqa: D102,E501,D203``.

Since it's not being used, I guess the doc should have something like this added to show people how to use it with current master:

3. Install `flake8-docstrings`

4. Change any existing `flake8` calls on your system have to have `--ignore=D`, as installation of `flake8-docstrings` will enable these new checks by default.

5. Install `flake8-putty`.

6. Configure `flake8-putty` for each repo to triage which files get passed to `flake8` checking and `pydocstyle` checking, by <doing something>

I think step (4) is especially painful for devs who work on multiple repos, many of which use flake8 (I know many such devs). It discourages actually using pydocstyle. It's also odd that users need to go through all this to get one type of skip functionality, when other types (like config types) are supported directly by pydocstyle out of the box.

@Nurdok
Copy link
Member

Nurdok commented Sep 1, 2016

Hi folks - sorry for joining this party so late :)

@sigmavirus24 - it seems like the issues you mentioned have been resolved (not using pydocstyle in the ignore comment). As long as this issue doesn't break flake8, it seems fine to me. If we can come up with a nice way to share the code for the ignoring mechanism later, I'll happily refactor this.

@Eric89GXL - thanks for the PR. I'll go ahead and give you a code review now :)

@@ -17,3 +17,9 @@ Configuration Files
^^^^^^^^^^^^^^^^^^^

.. include:: snippets/config.rst


Per-file configuration
Copy link
Member

Choose a reason for hiding this comment

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

How about "In-file configuration" so it'll be more clear?

@larsoner larsoner reopened this Sep 1, 2016
@larsoner
Copy link
Contributor Author

larsoner commented Sep 1, 2016

Thanks fro the comments @Nurdok, comments addressed. I'm happy to squash to a single commit so I avoid touching a bunch of now-unchanged lines if it helps.

In-file configuration
^^^^^^^^^^^^^^^^^^^^^

.. include:: snippets/per_file.rst
Copy link
Member

Choose a reason for hiding this comment

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

The snippet name should also be changed.

@@ -140,13 +144,17 @@ def is_empty_or_comment(line):
return ''.join(reversed(list(filtered_src)))

def __str__(self):
return 'in %s %s `%s`' % (self._publicity, self._human, self.name)
out = 'in %s %s `%s`' % (self._publicity, self._human, self.name)
Copy link
Member

Choose a reason for hiding this comment

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

Please change this to format as well while you're at it :)

Copy link
Contributor Author

@larsoner larsoner Sep 1, 2016 via email

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I'll only hold you to lines you changed, but if you feel like going over the code, I'd be grateful.

@Nurdok
Copy link
Member

Nurdok commented Sep 1, 2016

@Eric89GXL Just a few more comments :) I don't really mind about squashing either way.

@larsoner
Copy link
Contributor Author

larsoner commented Sep 2, 2016

@Nurdok comments addressed. The only % string operations left in the file are to logging calls, which AFAIK have to stay as %s-style.

@Nurdok Nurdok merged commit 2ce9e41 into PyCQA:master Sep 2, 2016
@larsoner larsoner deleted the skips branch September 2, 2016 19:34
@Nurdok
Copy link
Member

Nurdok commented Sep 2, 2016

Merged!
@Eric89GXL - thank you so much for putting in the time and effort and especially in the face of resistence.

@larsoner
Copy link
Contributor Author

larsoner commented Sep 2, 2016

No problem, thanks for the helpful discussions.

@Nurdok the next one that would make my life easier is #171. Any thoughts over there?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants