Im using pylint 1.6.4 and git-pylint-commit-hook 2.1.1 to lint my files on pre-commit. I also use alembic to generate my migrations, they are stored in <project-root>/migrations/versions.
The problem is that the generated migrations are not valid and pylint generates a warning for them. I can ignore migrations with --ignore=migrations. (Pylint ignores them by default anyway because migrations isn't a python module, it's simply a directory). But git-pylint-commit-hook calls pylint with list of changed files to validate. And pylint doesn't check if the file should be ignored if you give it a list of filenames, not modules.
This causes the pre-commit hook to fail when there is a new migration to be commited.
Running pylint on migrations/versions/d1f0e08ea6d2_skill_table.py (file 2/13).. 8.6/10.00 FAILED
************* Module d1f0e08ea6d2_skill_table.py
C: 5, 0: Trailing whitespace (trailing-whitespace)
C: 1, 0: Invalid module name "d1f0e08ea6d2_skill_table" (invalid-name)
C: 16, 0: Import "from alembic import op" should be placed at the top of the module (wrong-import-position)
C: 17, 0: Import "import sqlalchemy as sa" should be placed at the top of the module (wrong-import-position)
C: 20, 0: Missing function docstring (missing-docstring)
C:171, 0: Missing function docstring (missing-docstring)
I tried to add #pylint: skip-file to beginning of each migration file. This skips the file but generates and error that the file was skipped:
Running pylint on migrations/versions/d1f0e08ea6d2_skill_table.py (file 2/13).. 0/10.00 FAILED
************* Module d1f0e08ea6d2_skill_table.py
I: 1, 0: Ignoring entire file (file-ignored)
So I tried to ignore error file-ignored in .pylintrc like this:
[messages control]
disable=unused-argument
It works and the error is no longer reported but pre-commit hook fails because it doesn't find any statements:
Running pylint on migrations/versions/d1f0e08ea6d2_skill_table.py (file 2/13).. 0/10.00 FAILED
Report
======
0 statements analysed.
Notice that in both cases pylint evaluates the files as 0.0/10.0 so setting lower threshold for failure isn't the solution.
The question is, how do I make git-pylint-commit-hook and pylint to ignore my migrations?
This is an old question but I have just ran into this issue myself. I found the answer while searching this thread.
To solve this problem, just add an exclude directive with a regex that matches your folder.
If you want to exclude the migrations folder, by example, just add:
exclude: ^tests/
To your Pylint settings. Mine looks like this:
- repo: local
hooks:
- id: system
name: PyLint
entry: poetry run pylint
language: system
exclude: ^alembic/
files: \.py$
Related
I have some libraries which are returning the following error having run mypy .
module is installed, but missing library stubs or py.typed marker
To ignore this (as I would like to ignore errors for this particular library) I have tried adding the following to pyproject.toml:
+[mypy-<library name>.*]
+ignore_missing_imports = true
This however returns the following error:
Invalid TOML file /home/...: Empty table name at line ...
I was under the impression that this was the correct approach - perhaps things have changed though.
My question is - how do I tell mypy to ignore a particular library missing stubs, and do so within pyproject.toml
Edit
I just found : mypy overrides in toml are ignored?
which suggests something similar to:
[[tool.mypy.overrides]]
module = "library.*"
ignore_missing_imports = true
Which isn't the syntax I remember, so will leave this up to double check.
In my python project, after upgrading mypy from 0.770 to 0.782 an error is received in files where there were previously no type errors:
my_pkg_name\__init__.py: error: Source file found twice under different module names: 'top_pkg.my_pkg_name' and 'my_pkg_name'
Found 1 error in 1 file (checked 1 source file)
I'm pretty sure this is related to Issue #8944 on mypy and the way which vscode-python executes mypy on the open files. I've tried adding various mypy flags (e.g. --namespace-packages, --no-namespace-packages) but this did not resolve the issue.
my_pkg_name does contain an __init__.py and so does top_pkg. With mypy==0.770 this was not a problem.
Looking at the extension's output this is how mypy is invoked:
> ~\.virtualenvs\OfflineSystem.38\Scripts\python.exe `
c:\Users\***\.vscode\extensions\ms-python.python-2020.8.108011\pythonFiles\pyvsc-run-isolated.py mypy `
--ignore-missing-imports --follow-imports=silent --show-column-numbers `
d:\***\top_pkg\my_pkg_name\sub_pkg\my_file.py
Should change something in the mypy-related vscode settings for this to work?
I had a similar issue, but not via VSCode. The fix in my case was to remove an __init__.py file from a directory that was being included by adding it to the MYPYPATH, and so wasn't actually being treated as a module (so it shouldn't really have had the __init__.py file).
You said you tried adding the --namespace-packages flag, but I think you would need --no-namespace-packages to disable the new checker which might be causing your problem.
I am having a fabric script and i am using below statement
from fabric.api import *
Now i know this isn't as per PEP8 standards but this is really needed specially for a library like fabric and we can really import everything from it. Because of this flake8 is complaining on multiple lines with F405 code.
I have disabled this for one line using #noqa but since there multiple lines with same PEP8 violation how can i ask flake8 to ignore this particular error code.
I have also tried # noqa: F405 at the beginning of the file but that didn't work.
Starting from version 3.7.0, flake8 supports per file ignores out of the box. You can check the documentation on the command line flag / config file option here
Putting
[flake8]
ignore = E405
in your .flake8 config file will work.
Flake8 itself does not support per-file configuration, see the post:
https://gitlab.com/pycqa/flake8/issues/156
But for advanced configuration, e.g. per-file, recommended way is to use flake8-putty
The homepage gives you an example:
Disable only D102 on foo.py
putty-ignore = foo.py : D102
I have a file named main.py with the following code:
#!/usr/bin/env python3
import utils.stuff
if __name__ == "__main__":
print("hi from main.py")
utils.stuff.foo()
In the directory with main.py, I have a subdirectory named utils which has a file named stuff.py with the following code:
print("hi from stuff.py")
def foo():
print("foo")
If I run ./main.py from the command line, I get the following output:
hi from stuff.py
hi from main.py
foo
That is exactly what I expect. However, if I run pylint main.py, I get the following output:
No config file found, using default configuration
************* Module main
C: 1, 0: Missing module docstring (missing-docstring)
E: 3, 0: No name 'stuff' in module 'utils' (no-name-in-module)
E: 3, 0: Unable to import 'utils.stuff' (import-error)
E: 7, 4: Module 'utils' has no 'stuff' member (no-member)
followed by some more detailed statistics that do not seem relevant to my question. Why is this happening? What can I do to make Pylint aware of utils/stuff.py? I am running Python 3.5.2, Pylint 1.6.4 and OS X 10.11.6.
You need a create utils/__init__.py. This will make python aware of the submodule and also allows you to run any code you want to happen on import. If you don't want anything to run then just include a docstring.
I got this error when my function was named start:
from views import start
It worked when I changed the name of the function.
I sometimes got this pylint warning in PyCharm. The code works and PyCharm is able to navigate to the imported function if I Ctrl-click on the name.
From https://pycodequ.al/docs/pylint-messages/e0611-no-name-in-module.html
There can be false positive issues of the type when
pylint is run with an incompatible python version
pylint is run in an environment that misses a depedency of your code (this is more likely to lead to issues of type import-error
(E0401))
the name you are importing is in turn imported into the target module by a wildcard import
A false positive warning can be disabled with a comment:
# pylint: disable = no-name-in-module
The warning can also be disabled in pyproject.toml section of pylint:
[tool.pylint.'MESSAGES CONTROL']
disable=[
'no-name-in-module'
]
Flake8's pre-commit hook for git raises flake8: error: input not specified whenever I do git commit.
The hook file is identical to the official example :
#!/usr/bin/python
import sys
from flake8.run import git_hook
COMPLEXITY = 10
STRICT = False
if __name__ == '__main__':
sys.exit(git_hook(complexity=COMPLEXITY, strict=STRICT, ignore='E501'))
Yes, this is due to a bug in flake8 2.1.0. To work around this, create an empty setup.cfg or tox.ini file in your project directory. I just created a bug ticket for this: https://bitbucket.org/tarek/flake8/issue/133/git_hook-broken-when-setupcfg-and-toxini
There was a similar bug on a previous flake8 version (issue 68, fixed by commit 8fe9bfb)
But a very recent version of flake8 might have re-introduced that bug again (tweet, 6:02 PM - 20 Nov 13):
I'm not sure what happened to flake8 after update.
My old trusty pre-commit hook now returns, "flake8: error: input not specified".
The OP dlutxx reports in the comments:
until they fixed this bug, I'll just append the source directory to sys.argv within the pre-commit file.
Ugly, but [it] works.