Repository navigation
init-hook pylint argument not working #179
Description
From Toby Harradine (@Tobotimus) on September 18, 2017 1:46
Environment data
VS Code version: 1.16.1
Python Extension version: 0.7.0
Python Version: 3.5.4
OS and version: Windows 10 Version 1703, Build 15063.608
Using --init-hook in the setting python.linting.pylintArgs does not yield the same result as it does when used on the command line or in an rcfile. This may have something to do with the escaped \" character being used.
Here is an example. This is my module main.py:
"""Testing pylint init-hook"""
import requests
requests.get("http")This is my file structure, located at E:/Documents/Python Projects/test-pylint:
test-pylint/
main.py
lib/
requests
# other packages, dependencies etc
.vscode/
settings.json
Actual behavior
When using the following settings in .vscode/settings.json, pylint is unable to import requests:
{
"python.linting.pylintArgs": [
"--init-hook=\"import sys; sys.path.insert(0, 'E:/Documents/Python Projects/test-pylint/lib')\""
]
}From the Python output console:
##########Linting Output - pylint##########
************* Module main
2,0,error,E0401:Unable to import 'requests'
----------------------------------------------------------------------
Your code has been rated at -15.00/10 (previous run: -15.00/10, +0.00)
Expected behavior
When using a .pylintrc file located in the top level directory containing this line:
init-hook="import sys; sys.path.insert(0, 'E:/Documents/Python Projects/test-pylint/lib')"
I get no import errors, as expected. This also goes for when pylint is run straight from the terminal:
E:\Documents\Python Projects\test-pylint>pylint main.py --init-hook="import sys; sys.path.insert(0, 'E:/Documents/Python Projects/test-pylint/lib')"
----------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: -15.00/10, +25.00)
Steps to reproduce:
- Use
"--init-hook=\"import sys; sys.path.insert(0, 'path/to/lib')\""in thepython.linting.pylintArgssetting, see if modules inpath/to/libcan be imported - Include the argument in an rcfile or command line argument instead, and see if it yields the same result
Copied from original issue: DonJayamanne/pythonVSCode#1215
Activity
DonJayamanne commentedon Nov 14, 2017
Try the following:
Tobotimus commentedon Nov 18, 2017
After testing, that workaround does indeed solve the issue.