I have a pre-commit set up on a python repo. I have a .pre-commit-config.yaml file where I specify my pylint settings/arguments. Previously my pylint hook worked.
Pylint config in .pre-commit-config.yaml:
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args:
[
"-rn",
"--rcfile=./polestar.rc",
"--fail-under=6"
]
This config previously worked. Now I get the following error.
pylint: error: no such option: --fail-under
I can't think of anything that has changed to cause this issue.
Any advice would be great or suggestions as to what could fix it.
Found issue: the python environment I was in had a old version of pylint installed. I updated the pylint version to latest and the option to set --fail-under became available again.
Related
I am trying to build a GTK application in MacOS (Monterey, v. 12.4) that includes both C GTK components and Python GTK components. I am following the instructions from both here and here. I had minimal issues with the first part (although for some reason I got an error where jhbuild said cargo did not exist when building librsvg during the call to jhbuild build meta-gtk-osx-gtk3, despite .new_local/bin being at the front of PATH). The instructions there were simply:
sh gtk-osx-setup.sh
alias jhbuild="PATH=.new_local/bin:$PATH jhbuild"
jhbuild bootstrap-gtk-osx
jhbuild build meta-gtk-osx-bootstrap meta-gtk-osx-gtk3
In any case, the issue that I am having now is installing either set of bindings for Python. When I attempt to build either, jhbuild states both:
jhbuild#Cytocyberneticss-Mac-mini ~ % jhbuild build meta-gtk-osx-python-gtk3
Loading .env environment variables...
jhbuild build: A module called ''meta-gtk-osx-python-gtk3'' could not be found.
Usage: run_jhbuild.py [ -f config ] command [ options ... ]
jhbuild#Cytocyberneticss-Mac-mini ~ % jhbuild build meta-gtk-osx-python
Loading .env environment variables...
jhbuild build: A module called ''meta-gtk-osx-python'' could not be found.
Usage: run_jhbuild.py [ -f config ] command [ options ... ]
I do not have home-brew or MacPorts installed so neither of those could be getting in the way. I really am at a loss as to what the problems is here, when the other builds went fine. Any pointers would be greatly appreciated. Let me know if you need any more information about my setup.
As per the package maintainer:
I need to rewrite that Python wiki page, it's thoroughly out of date.
meta-gtk-osx-python-gtk3 got changed to meta-gtk-osx-python2-gtk3, and current versions of gtk-osx don't support gtk2. What's more, python2 is obsolete and its use is deprecated; you should use meta-gtk-osx-python3-gtk3. I haven't yet made a meta-gtk-osx-python3-gtk4 but you can easily do so in your own moduleset if your application is ready for it.
So simply use either:
jhbuild build meta-gtk-osx-python3-gtk3
jhbuild build meta-gtk-osx-python2-gtk3
This question will be irrelevant though as soon as the Wiki is updated...
i'm using vscode for python3 in Ubuntu. Error-squiggle-lines have stopped working for Python(it works for other languages). And I am using Microsoft's Python extension.
vscode v1.41.1
Ubuntu v18.04
this is what i have tried:
I thought maybe it's because i installed anaconda so uninstalled it but didn't fix it.
then I re-installed vs code after deleting its config from .config/code but that didn't work either.
also set python linting to true from command palette
it's not showing error squiggle lines:
here is the Microsoft's python extension's contributions regarding linting(sorry for poor readability):
Whether to lint Python files. true python.linting.flake8Args Arguments passed in. Each argument is a separate item in the array. python.linting.flake8CategorySeverity.E Severity of Flake8 message type 'E'. Error python.linting.flake8CategorySeverity.F Severity of Flake8 message type 'F'. Error python.linting.flake8CategorySeverity.W Severity of Flake8 message type 'W'. Warning python.linting.flake8Enabled Whether to lint Python files using flake8 false python.linting.flake8Path Path to flake8, you can use a custom version of flake8 by modifying this setting to include the full path. flake8 python.linting.ignorePatterns Patterns used to exclude files or folders from being linted. .vscode/*.py,**/site-packages/**/*.py python.linting.lintOnSave Whether to lint Python files when saved. true python.linting.maxNumberOfProblems Controls the maximum number of problems produced by the server. 100 python.linting.banditArgs Arguments passed in. Each argument is a separate item in the array. python.linting.banditEnabled Whether to lint Python files using bandit. false python.linting.banditPath Path to bandit, you can use a custom version of bandit by modifying this setting to include the full path. bandit python.linting.mypyArgs Arguments passed in. Each argument is a separate item in the array. --ignore-missing-imports,--follow-imports=silent,--show-column-numbers python.linting.mypyCategorySeverity.error Severity of Mypy message type 'Error'. Error python.linting.mypyCategorySeverity.note Severity of Mypy message type 'Note'. Information python.linting.mypyEnabled Whether to lint Python files using mypy. false python.linting.mypyPath Path to mypy, you can use a custom version of mypy by modifying this setting to include the full path. mypy python.linting.pycodestyleArgs Arguments passed in. Each argument is a separate item in the array. python.linting.pycodestyleCategorySeverity.E Severity of pycodestyle message type 'E'. Error python.linting.pycodestyleCategorySeverity.W Severity of pycodestyle message type 'W'. Warning python.linting.pycodestyleEnabled Whether to lint Python files using pycodestyle false python.linting.pycodestylePath Path to pycodestyle, you can use a custom version of pycodestyle by modifying this setting to include the full path. pycodestyle python.linting.prospectorArgs Arguments passed in. Each argument is a separate item in the array. python.linting.prospectorEnabled Whether to lint Python files using prospector. false python.linting.prospectorPath Path to Prospector, you can use a custom version of prospector by modifying this setting to include the full path. prospector python.linting.pydocstyleArgs Arguments passed in. Each argument is a separate item in the array. python.linting.pydocstyleEnabled Whether to lint Python files using pydocstyle false python.linting.pydocstylePath Path to pydocstyle, you can use a custom version of pydocstyle by modifying this setting to include the full path. pydocstyle python.linting.pylamaArgs Arguments passed in. Each argument is a separate item in the array. python.linting.pylamaEnabled Whether to lint Python files using pylama. false python.linting.pylamaPath Path to pylama, you can use a custom version of pylama by modifying this setting to include the full path. pylama python.linting.pylintArgs Arguments passed in. Each argument is a separate item in the array. python.linting.pylintCategorySeverity.convention Severity of Pylint message type 'Convention/C'. Information python.linting.pylintCategorySeverity.error Severity of Pylint message type 'Error/E'. Error python.linting.pylintCategorySeverity.fatal Severity of Pylint message type 'Fatal/F'. Error python.linting.pylintCategorySeverity.refactor Severity of Pylint message type 'Refactor/R'. Hint python.linting.pylintCategorySeverity.warning Severity of Pylint message type 'Warning/W'. Warning python.linting.pylintEnabled Whether to lint Python files using pylint. true python.linting.pylintPath Path to Pylint, you can use a custom version of pylint by modifying this setting to include the full path. pylint python.linting.pylintUseMinimalCheckers Whether to run Pylint with minimal set of rules. true
python.linting.pylintEnabled is: true
python.linting.pylintPath is: pylint
all the errors in visual studio's console of developer tools:
console.ts:137 [Extension Host] Error Python Extension: 2020-01-18 18:35:53: Failed to serialize gatherRules for DATASCIENCE.SETTINGS [TypeError: Cannot convert object to primitive value at Array.join (<anonymous>) at Array.toString (<anonymous>) at /home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:1:12901 at Array.forEach (<anonymous>) at Object.l [as sendTelemetryEvent] (/home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:1:12818) at C.sendSettingsTelemetry (/home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:75:707093) at C.r.value (/home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:1:87512) at Timeout._onTimeout (/home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:1:86031) at listOnTimeout (internal/timers.js:531:17) at processTimers (internal/timers.js:475:7)]
t.log # console.ts:137
2console.ts:137 [Extension Host] Notification handler 'textDocument/publishDiagnostics' failed with message: Cannot read property 'connected' of undefined
t.log # console.ts:137
2console.ts:137 [Extension Host] (node:21707) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
t.log # console.ts:137
$logExtensionHostMessage # mainThreadConsole.ts:39
_doInvokeHandler # rpcProtocol.ts:398
_invokeHandler # rpcProtocol.ts:383
_receiveRequest # rpcProtocol.ts:299
_receiveOneMessage # rpcProtocol.ts:226
(anonymous) # rpcProtocol.ts:101
fire # event.ts:581
fire # ipc.net.ts:453
_receiveMessage # ipc.net.ts:733
(anonymous) # ipc.net.ts:592
fire # event.ts:581
acceptChunk # ipc.net.ts:239
(anonymous) # ipc.net.ts:200
t # ipc.net.ts:28
emit # events.js:200
addChunk # _stream_readable.js:294
readableAddChunk # _stream_readable.js:275
Readable.push # _stream_readable.js:210
onStreamRead # internal/stream_base_commons.js:166
output for python in output panel:
User belongs to experiment group 'AlwaysDisplayTestExplorer - control'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'AA_testing - experiment'
> conda --version
> pyenv root
> python3.7 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> /usr/bin/python3.8 -c "import sys;print(sys.executable)"
> conda info --json
> conda env list
Starting Microsoft Python language server.
> conda --version
> /usr/bin/python3.8 ~/.vscode/extensions/ms-python.python-2020.1.58038/pythonFiles/interpreterInfo.py
> /usr/bin/python3.8 ~/.vscode/extensions/ms-python.python-2020.1.58038/pythonFiles/interpreterInfo.py
how to get the squiggle lines to work again?
In your settings.json file(search for settings.json in the command palette), declare the following:
"python.linting.pylintEnabled": true, "python.jediEnabled": false
if you just want the changes in your workspace then change the settings.json file in .vscode folder
In latest version of visual studio code, workspace is not registering settings from checkboxes so you have to explicitly declare in settings.json what settings you want to enable for your workspace. Flake8 is not affected by this. Pylint and Microsoft Python Language Server seem to be not working due to this.
side note:got this solution from sys-temd's reply on github.com/microsoft/vscode-python/issues
What I tried but not working
pip install -U pylint
declare "python.linting.pylintEnabled": true, "python.jediEnabled": false
Then I try to recreate a brand-new settings.json, pylint turns out working.
Therefore, I trace which line affects pylint.
In my case, it's the line beginning from "python.linting.pylintArgs":
Solution
Removing the line beginning from "python.linting.pylintArgs": will solve the problem.
Make sure in your settings you didn't turn off linting (and specifically Pylint if that's what you want to use). Also make sure you have Pylint installed and the Python extension knows where it is (either by creating an environment and installing into there or installing it globally and setting "python.linting.pylintPath"). Otherwise check the output of the "Python" channel in the Output Panel to see how Pylint is being executed and make sure that works when you copy-and-paste it into a terminal as appropriate.
pip install -U pylint
Solved my issue
If the main problem is those squiggle lines or some minor errors in the workspace then you can download the 'pylance extension' and enable it in settings of 'python language server'. This language server is even better (i think) because it is lighter than 'jedi' language server and also tells about the unused modules and variables or even the undefined variables as those squiggle lines show.
I'm currently trying to implement steam login into website. But I'm unable to get pass this error within the code. I've created the database object but it keeps showing the error I mentioned earlier. I'm not sure whether SQLAlchemy has changed or what since I used it.
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
The message emitted by pylint is
E1101: Instance of 'SQLAlchemy' has no 'Column' member (no-member)
EDIT: After read and try np8's answer my previous answer is wrong there is a package you have to install, which is pylint_flask_sqlalchemy
so the answer will be
on your project directory find folder .vscode (if you dont have it, just create it) then create file settings.json and add this line
{
# You have to put it in this order to make it works
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_flask_sqlalchemy",
"pylint_flask", # This package is optional
]
}
You also need to have pylint-flask-sqlalchemy and if you want to use pylint-flask install on your current python environment:
pip install pylint-flask-sqlalchemy
pip install pylint-flask
pip install pylint-flask
In case of Visual Studio Code: Open File > Preferences > Settings > Edit in settings.json as below:
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]
Summary of working and non-working configurations
It seems that this can be configured so many ways incorrectly, that I decided to write the different options down. I am assuming VS Code, but for command line or other editor, arguments and their order is the same. These were tested using the latest versions of all the packages (list in the bottom of this post)
Working versions
# What you'll need is pylint_flask_sqlalchemy
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy"]
# You can add pylint_flask but only if it is *AFTER* pylint_flask_sqlalchemy
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy", "pylint_flask"]
Non-working versions
# pylint_flask does not help, but can break it (see below)
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]
# You can NOT add pylint_flask *BEFORE* pylint_flask_sqlalchemy
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask", "pylint_flask_sqlalchemy"]
# CAUTION: These will disable pylint silently altogether!
# Do not use dash (-) but underscore (_)!
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask-sqlalchemy", "pylint-flask"]
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask"]
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask-sqlalchemy"]
Details for those who are interested
pylint_flask_sqlalchemy
The pylint-flask-sqlalchemy1 was created specifically to fix this2. You can enable it by adding it to --load-plugins of pylint. In command line this would be
python -m pylint --load-plugins pylint_flash_sqlalchemy <mymodule.py>
and in VS Code (Settings (JSON)):
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy"]
1Also mirrored to GitHub: https://github.com/anybox/pylint_flask_sqlalchemy
2See this comment on pylint Issue tracker.
pylint_flask
pylint-flask is pylint plugin for Flask. It has nothing to do with Flask-SQLAlchemy and it does not even try to solve the false positive issues pylint has with Flask-SQLAlchemy3. The only possibility to use pylint-flask to "make the errors disappear" is to load it with erroneusly with dashes, which makes the whole pylint to be disabled.
It seems that pylint-flask must be loaded after pylint-flas-sqlalchemy; I tested with my setup, and for some reason
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask", "pylint_flask_sqlalchemy"]
will not work, but
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy", "pylint_flask"]
will. So the order of loading plugins matters.
3 See the code for yourself: pylint-flask source & pylint-flask-sqlaclhemy source
Caution: Do not remove your linting accidentally
As the documentation of pylint-flask and pylint-flask-sqlalchemy says, the names in the argument --load-plugins should be written with underscores; If you use
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask", "pylint-flask-sqlalchemy"]
in VS Code, the errors will be gone, but so will be all of your linting as the pylint crashes silently in the background.
Installing pylint-flask-sqlalchemy
pip install pylint-flask-sqlalchemy
Used versions
Flask 1.1.2
Flask-SQLAlchemy 2.4.4
pylint 2.5.3
pylint-flask 0.6
pylint-flask-sqlalchemy 0.2.0
See also
Discussion on pylint GitHub issue: "Problem with Flask-SQLAlchemy, cannot find valid and existing property in SQLAlchemy object."
Open the Command Palette (Command+Shift+P on macOS and Ctrl+Shift+P on Windows/Linux) and type in one of the following commands:
Python: Select Linter
Switch from PyLint to flake8 or other supported linters.
I've just encountered this issue. Neither of the suggested solutions worked for me, but the following does.
First, install these modules:
pip install pylint-flask
pip install pylint-flask-sqlalchemy
Then, in Visual Studio Code, you need to add the following to your settings.json file:
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask", "pylint-flask-sqlalchemy"]
For Windows, this works: In case of Visual Studio Code: Open File > Preferences > Settings > Edit in settings.json ->
and add this code after comma below existing settings:
"python.linting.pylintArgs": [
"--load-plugins",
"pylint-flask"
]
Sorry this is a long question. See the sentence in bold at the bottom for the TL;DR version.
I've spent many hours trying to track down a problem where pylint sometimes doesn't report all the errors in a module. Note that it does find some errors (e.g. long lines), just not all of them (e.g. missing docstrings).
I'm running pylint 1.7.2 on Ubuntu 16.04. (The version available from apt was 1.5.2 but installing via pip gives 1.7.2.)
We typically run pylint from tox, with a tox.ini that looks something like this (this is a cut-down version):
[tox]
envlist = py35
[testenv]
setenv =
MODULE_NAME=our_module
ignore_errors = True
deps =
-r../requirements.txt
whitelist_externals = bash
commands =
pip install --editable=file:///{toxinidir}/../our_other_module
pip install -e .
bash -c \'set -o pipefail; pylint --rcfile=../linting/pylint.cfg our_module | tee pylint.log\'
Amongst other things, the ../requirements.txt file contains a line for pylint==1.7.2.
The behaviour is like this:
[wrong] When the line that imports our_other_module is present, pylint appears to complete successfully and not report any warnings, even though there are errors in the our_module code that it should pick up.
[correct] When that line is commented out, pylint generates the expected warnings.
As part of tracking this down I took two copies of the .tox folder with and without the module import, naming them .tox-no-errors-reported and .tox-with-errors-reported respectively.
So now, even without sourcing their respective tox virtualenvs, I can do the following:
$ .tox-no-errors-reported/py35/bin/pylint --rcfile=../linting/pylint.cfg our_module -- reports no linting warnings
$ .tox-with-errors-reported/py35/bin/pylint --rcfile=../linting/pylint.cfg our_module -- reports the expected linting warnings
(where I just changed the pylint script's #! line in each case to reference the python3.5 inside that specific .tox directory instead of the unrenamed .tox)
By diffing .tox-no-errors-reported and .tox-with-errors-reported, I've found that they are very similar. But I can make the "no errors" version start to report errors by removing the path to our_other_module from .tox-no-errors-reported/py35/lib/python3.5/site-packages/easy-install.pth.
So my question is why is pylint using easy_install at runtime, and what is it picking up from our other component that is causing it to fail to report some errors.
As I understand it, pylint has dependencies on astroid and logilab-common, but including these in the requirements.txt doesn't make any difference.
One possible reason for the surprising pylint behavior is the --editable option.
it creates a special .egg-link file in the deployment directory, that links to your project’s source code. And, ..., it will also update the easy-install.pth file to include your project’s source code
The pth file will then affect the sys.path which affects the module import logic of astroid and it is deeply buried in the call stack of pylint.expand_files via pylint.utils.expand_modules. Also pylint identifies the module part and function names in the AST using astroid.modutils.get_module_part.
To test the theory, you can try calling some of the affected astroid functions manually:
import sys, astroid
print(sys.path)
print(astroid.modutils.get_module_part('your_package.sub_package.module'))
astroid.modutils.file_from_modpath(['your_package', 'sub_package', 'module'])
I've been learning about how to do testing in tox for my python project.
I have (what should be) a fairly standard tox initialization file that looks like the following:
[tox]
envlist=py27,flake8
...
[testenv:flake8]
deps=flake8
commands=flake8 library # 'library' is temp. name of project
Everything looks normal, all the test works, and even the flake8 output comes through (output below). However, tox raises an InvocationError (it does the same for testing using pylint)
flake8 recreate: /Users/shostakovich/projects/project_templates/library/.tox/flake8
flake8 installdeps: flake8
flake8 inst: /Users/shostakovich/projects/project_templates/library/.tox/dist/library-0.1.0.zip
flake8 installed: flake8==2.4.1,library==0.1.0,mccabe==0.3,pep8==1.5.7,pyflakes==0.8.1,wheel==0.24.0
library/__main__.py:12:1: F401 'os' imported but unused
library/__main__.py:13:1: F401 're' imported but unused
...
ERROR: InvocationError: '/Users/shostakovich/projects/project_templates/library/.tox/flake8/bin/flake8 library'
I am running tox 2.0.2 on MaxOSX 10.9.5. The problem goes away if I just call flake8 or pylint directly (the version of flake8 is shown above).
tox doesn't fail, it works!
Your flake8 source code check has findings and therefore tox exits with failures, that's your test result. Fix the findings and your done!
You may configure the flake8 run to ignore specific codes with a section in your tox.ini. From the flake8 docs:
[flake8]
ignore = E226,E302,E41
There are more options you may be interested in, e.g. select = ... for whitelisting enabled code checks.
You can also tell flake8 to exit without failure, even if the test results are not perfect. This will suppress the misleading InvocationError. Just add to your command --exit-zero, so for example:
commands=flake8 library --exit-zero