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

How to configure pylint-venv in VS Code? #7

Closed
Sayam753 opened this issue Jul 29, 2020 · 5 comments
Closed

How to configure pylint-venv in VS Code? #7

Sayam753 opened this issue Jul 29, 2020 · 5 comments

Comments

@Sayam753
Copy link

Sayam753 commented Jul 29, 2020

Hello developers
Thanks for this excellent library. pylint-venv works all good in command line. I was wondering if there is a way to configure this in VS Code as well.

I have configuring VSCode user settings using pylintArgs something like this but this does not seem to work.

"python.linting.pylintArgs": [
    "--init-hook=import pylint_venv; pylint_venv.inithook()",
],

and

"python.linting.pylintArgs": [
    "--init-hook",
    "import pylint_venv; pylint_venv.inithook()",
],

Any help on this? Thanks

EDIT: Just open VSCode in virtualenv itself. No need to configure anything. And pylint-venv works like a charm.

@Sayam753
Copy link
Author

Looking upon possible solutions inspired from #5 , I am able to configure VS Code by -

"python.linting.pylintArgs": [
        "--init-hook",
        "import sys;sys.path.append('/Users/user/Env/only_aws/lib/python3.7/site-packages');import pylint_venv;pylint_venv.inithook(force_venv_activation=True)"
    ]

I am closing this issue. But also, I would love to know if this behaviour from pylint-venv is expected or not.
Thanks

@Sayam753
Copy link
Author

Figuring out solutions involving use of .pylintrc, this comment has been super useful.
I just thought it can be helpful for anyone figuring out how to configure this library with .pylintrc. Thanks!

@jgosmann
Copy link
Owner

You might want to take a look at #9. That might clarify a bit what is going on here? Seem like you pylint is also installed in a virtual environment (thus requiring the force_venv_activation flag) that is separate from the environment in which pylint-venv is installed (requiring the sys.path modification).

@Sayam753
Copy link
Author

Sayam753 commented Sep 2, 2020

Hi @jgosmann
Thanks for the reply. Both pylint and pylint-venv are installed in the same environment (system-site-packages). I am able to run pylint through terminal with init-hook all set and virtualenv activated.
I played around more with VSCode and pylint-venv. Removing the import of pylint-venv from .vscode/settings.json also worked the same.

"python.linting.pylintArgs": [
        "--init-hook",
        "import sys; sys.path.append('/Users/user/Env/only_aws/lib/python3.7/site-packages')"
    ]

Now, from this observation, I can say that VSCode does not activate the environment before running pylint and thus, init-hook configured in .pylintrc is not able to detect the environment.
So, we only need to append the path of virtualenv packages. But I am not 100% sure about this behaviour of VSCode.

@Sayam753
Copy link
Author

Sayam753 commented Sep 2, 2020

This is getting really interesting.

  • If I open VSCode in base env (where pylint and pylint-venv are installed) and then select a new virtualenv, we need to pass a path to pylintArgs.
"python.linting.pylintArgs": [
        "--init-hook",
        "import sys; sys.path.append('/Users/user/Env/only_aws/lib/python3.7/site-packages')"
    ]
  • And if I open VSCode in virtualenv itself, I do not need to configure anything at all. And pylint-venv works like a charm.

I edited my initial message as well to open VSCode in virtualenv.
Thanks
Sayam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants