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

better doc on excluding files in pyproject.toml #13883

Closed
copdips opened this issue Oct 13, 2022 · 8 comments
Closed

better doc on excluding files in pyproject.toml #13883

copdips opened this issue Oct 13, 2022 · 8 comments

Comments

@copdips
Copy link

copdips commented Oct 13, 2022

Documentation

hello,

Could anyone provide a better doc about the exculde section in the pyproject.toml file ?

Current doc says:

[tool.mypy]
python_version = "2.7"
warn_return_any = true
warn_unused_configs = true
exclude = [
    '^file1\.py$',  # TOML literal string (single-quotes, no escaping necessary)
    "^file2\\.py$",  # TOML basic string (double-quotes, backslash and other characters need escaping)
]

IMHO, it's not very clear, at least, it should explain what kind of files are exclude by the syntax of '^file1\.py$', and what for "^file2\\.py$". And is it for any file with the same name under any folder ?
In addition, could you please provide an example how to exclude by a file path keywork. Suppose i have some files located at : /a/b/c/file.py, I would like to exclude all files where their location has the keywork /c/, how to achieve that.

@hauntsaninja
Copy link
Collaborator

@copdips
Copy link
Author

copdips commented Oct 15, 2022

Thanks, in fact, I'm using pyproject.toml with mypy in pre-commit.
It seems that the exclusion declared in pyproject.toml works well when running mypy directly out of pre-commit, but doesn't work with pre-commit.

I intentionaly make a file (venv/pyodbc.pyi) in my venv with mypy error, and also a real python file inside of the project (scripts/test_sleep.py) with mypy error too.

My pyproject.toml conf looks like:

[tool.mypy]
exclude = [
    "^venv/",
    "^scripts/",
]

Running mypy . with venv activated, it doesn't show the errors on the two file, it's expected, as both of the files are excluded in pyproject.toml, and by commenting the exclude part, mypy . can show the errors on the two file, so far, all good.

Now running mypy under pre-commit, .pre-commit-config.yaml looks like:

repos:
  - repo: local
    hooks:
      - id: mypy
        name: mypy
        language: system
        entry: mypy
        types: [python]
        args:
          - --show-error-codes

Running pre-commit run mypy --all-files (always with venv activated) shows only the error in the file scripts/test_sleep.py no matter I comment or uncomment the exclude part in pyproject.toml, and the type error in venv/pyodbc.pyi is never shown neither.

Adding config-file param in .pre-commit-config.yaml doesn't help neither:

repos:
  - repo: local
    hooks:
      - id: mypy
        name: mypy
        language: system
        entry: mypy
        types: [python]
        args:
          - --show-error-codes
          - --config-file
          - pyproject.toml

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Oct 17, 2022

Use pre-commit's pass_filenames: false. mypy does whole program analysis so pre-commits file diffing isn't saving you work

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2022
@hauntsaninja
Copy link
Collaborator

#13916

@copdips
Copy link
Author

copdips commented Oct 17, 2022

#13916

thx a lot, but with the suggested param, I got the error:

mypy.....................................................................Failed
- hook id: mypy
- exit code: 2

usage: mypy [-h] [-v] [-V] [more options; see below]
            [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
mypy: error: Missing target module, package, files, or command.

removing the pass_filenames: false from the hook removes the error.

@choucavalier
Copy link

i have the same issue... running pre-commit run mypy -a is completely discarding my exclude rules in my pyproject.toml file

@pedropaulofb
Copy link

#13916

thx a lot, but with the suggested param, I got the error:

mypy.....................................................................Failed
- hook id: mypy
- exit code: 2

usage: mypy [-h] [-v] [-V] [more options; see below]
            [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
mypy: error: Missing target module, package, files, or command.

removing the pass_filenames: false from the hook removes the error.

I have the same problem. @copdips or @tgy, could you solve the problem? May I ask you how? Thanks in advance.

@copdips
Copy link
Author

copdips commented Nov 16, 2023

Hello,

to be honnest, I haven't used mypy for a while, what I can show is my last config, I don't run mypy directly, always from pre-commit.

# file pyproject.toml

[tool.mypy]
ignore_missing_imports = true
warn_return_any = true
warn_unused_configs = true
show_error_codes = true
# strict = true
exclude = ["^.venv/", "^build/", "^_local_test/"]
# file .pre-commit-config.yaml

- id: mypy
  name: mypy
  language: system
  entry: mypy
  types: [python]

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

No branches or pull requests

4 participants