Skip to content

init-hook pylint argument not working #179

Closed

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 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

Activity

  1. DonJayamanne commented on Nov 14, 2017

    @DonJayamanne
    Author

    Try the following:

        "python.linting.pylintArgs": [
            "--init-hook",
            "import sys; sys.path.insert(0, 'c:/Development/PythonCode/TestExt/hello')"
        ]
  2. Tobotimus commented on Nov 18, 2017

    @Tobotimus

    After testing, that workaround does indeed solve the issue.

  3. locked as resolved and limited conversation to collaborators on Jul 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions