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

init-hook pylint argument not working #179

Closed
DonJayamanne opened this issue Nov 14, 2017 · 2 comments
Closed

init-hook pylint argument not working #179

DonJayamanne opened this issue Nov 14, 2017 · 2 comments
Labels
area-linting info-needed Issue requires more information from poster

Comments

@DonJayamanne
Copy link

From @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 the python.linting.pylintArgs setting, see if modules in path/to/lib can 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

@DonJayamanne
Copy link
Author

Try the following:

    "python.linting.pylintArgs": [
        "--init-hook",
        "import sys; sys.path.insert(0, 'c:/Development/PythonCode/TestExt/hello')"
    ]

@brettcannon brettcannon added info-needed Issue requires more information from poster area-linting bug Issue identified by VS Code Team member as probable bug labels Nov 14, 2017
@Tobotimus
Copy link

After testing, that workaround does indeed solve the issue.

@DonJayamanne DonJayamanne added closed-fixed and removed bug Issue identified by VS Code Team member as probable bug labels Nov 18, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jul 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-linting info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants