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

pydocstyle's default --match option should be honored #494

Closed
koluacik opened this issue May 24, 2021 · 16 comments
Closed

pydocstyle's default --match option should be honored #494

koluacik opened this issue May 24, 2021 · 16 comments
Assignees
Labels
enhancement New feature or request

Comments

@koluacik
Copy link

koluacik commented May 24, 2021

What's the output of :CocCommand pyright.version
[coc.nvim] coc-pyright 1.1.141 with Pyright 1.1.142

By default pydocstyle does not check file names starting with test_ for docstrings. Running pydocstyle from shell confirms this. However, I still see missing docstring warnings while working on my test files. I could disable linting altogether for test files, or disable pydocstyle while writing tests, but both are inconvenient. Ideally, there should be a way to specify arguments passed to pydocstyle there is.

Is this an issue with the upstream, or can this be handled within coc-pyright?

edit: Appearently, there is an option for that: "python.linting.pydocstyleArgs": [ "--match='(?!test_).*\\.py" ] (notice the double \ because coc complained about invalid escape character.) Should this option have a default value that reflects that of the standalone pydocstyle?

@fannheyward fannheyward added the enhancement New feature or request label May 24, 2021
@yaegassy
Copy link
Contributor

@fannheyward It is pydocstyle, but apparently it is not excluded if you pass the file as absolute or relative path.

(venv) $ pwd
/private/tmp/pydocstylecheck
(venv) $ cat test_main.py
import unittest

class TestMain(unittest.TestCase):
    def test_name(self):
        pass
(venv) $ # NG (not excluded)
(venv) $ pydocstyle /private/tmp/pydocstylecheck/test_main.py
/private/tmp/pydocstylecheck/test_main.py:1 at module level:
        D100: Missing docstring in public module
/private/tmp/pydocstylecheck/test_main.py:3 in public class `TestMain`:
        D101: Missing docstring in public class
/private/tmp/pydocstylecheck/test_main.py:4 in public method `test_name`:
        D102: Missing docstring in public method
(venv) $ # OK
(venv) $ pydocstyle test_main.py
(venv) $

REF?:

Fix?:

In my environment, I confirmed that it worked fine by passing the file name as is. https://github.com/fannheyward/coc-pyright/blob/master/src/linters/pydocstyle.ts#L12

    const messages = await this.run([path.basename(Uri.parse(document.uri).fsPath)], document, cancellation);

(If the this issue has already been solved, you can ignore it.)

@fannheyward fannheyward reopened this May 24, 2021
@fannheyward
Copy link
Owner

@yaegassy yes, you're right, this fix won't work.

@yaegassy
Copy link
Contributor

yaegassy commented May 24, 2021

@fannheyward I checked this PR in coc.nvim before it was merged. neoclide/coc.nvim#3106

This PR has nothing to do with anything. I'm sorry for the noise.

@fannheyward
Copy link
Owner

@fannheyward
Copy link
Owner

Use file name is incorrect, for example:

main.py
test
test/__init__.py
test/m.py
test/test_m.py

nvim main.py is working, but nvim test/m.py will run something like pydocstyle m.py.

@yaegassy
Copy link
Contributor

yaegassy commented May 24, 2021

@fannheyward Isn't it a problem that can be solved by passing the "file name" instead of the "file path"?

Fix (Idea):

    const messages = await this.run([path.basename(Uri.parse(document.uri).fsPath)], document, cancellation);

@fannheyward
Copy link
Owner

@yaegassy "file name" is not ok. nvim test/m.py will become pydocstyle m.py that m.py not found to run.

@yaegassy
Copy link
Contributor

@fannheyward Oh... that's exactly how it should behave... :(

@fannheyward
Copy link
Owner

fannheyward commented May 25, 2021

@yaegassy my example maybe misleading. For example:

main.py
lib/m.py
lib/test_m.py

If we use "file name", nvim main.py is OK, but nvim lib/m.py runs pydocstyle m.py.

@yaegassy
Copy link
Contributor

yaegassy commented May 25, 2021

Unfortunately, "vscode-python" is not excluded either... It's currently a specification :(

vscode-pydocstyle

@fannheyward
Copy link
Owner

The key problem is pydocstyle lib will ignore test_m.py by default, but pydocstyle lib/test_m.py will run it.

@fannheyward
Copy link
Owner

Fix: run pydocstyle for current document's dir, and file message for current document only.

@yaegassy
Copy link
Contributor

yaegassy commented May 25, 2021

@fannheyward I've tried this commit: d4b3e3b

It seems to run recursively when you pass the directory, so it may take too long to complete for large projects.

In some cases, the pydocstyle process might stay up for a very long time.

For example, if you run it on a python file directly under the root of the project, it will be executed on all python files in the project.

@fannheyward
Copy link
Owner

@yaegassy good catch.

@fannheyward
Copy link
Owner

fannheyward commented May 25, 2021

Check filename with ^test_.*\.py$, return empty when matched. This is a hack fix, I think pydocstyle should fix it.

@aiwalter
Copy link

@fannheyward for me this does not work, it seems it just excludes all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants