Skip to main content

pylint-venv provides a Pylint init-hook to use the same Pylint installation with different virtual environments.

Project description

CI and release pipeline PyPI PyPI - Python Version PyPI - License

pylint-venv

Pylint does not respect the currently activated virtualenv if it is not installed in every virtual environment individually. This module provides a Pylint init-hook to use the same Pylint installation with different virtual environments.

Installation

pip install pylint-venv

Add the hook to your Pylint configuration. See the section below corresponding to the type of configuration file you use.

Configure with pyproject.toml

Add the following to your pyproject.toml:

[tool.pylint.MAIN]
init-hook = """
try: import pylint_venv
except ImportError: pass
else: pylint_venv.inithook()
"""

Configure with .pylintrc

Add the following to your .pylintrc:

[MAIN]
init-hook=
    try: import pylint_venv
    except ImportError: pass
    else: pylint_venv.inithook()

If you add this to your ~/.pylintrc in your home directory, it will be applied to all projects by default.

Usage

The hook will then be used automatically if

  • a virtualenv without pylint is active,

  • or a Conda environment without pylint is active,

  • or no environment is active but your CWD contains virtualenv directory.

Anything listed in the PYLINT_VENV_PATH environment variable is considered a virtualenv directory. The default, if the variable is unset, is .venv. Use a colon (:) as path separator. Example for checking directories .venv and .virtualenv:

PYLINT_VENV_PATH=.venv:.virtualenv

You can also call the hook via a command line argument:

$ pylint --init-hook="import pylint_venv; pylint_venv.inithook()"

This way you can also explicitly set an environment to be used:

$ pylint --init-hook="import pylint_venv; pylint_venv.inithook('$(pwd)/env')"

If pylint itself is installed in a virtualenv, then you can ignore it by passing force_venv_activation=True to force the activation of a different virtualenv:

$ pylint --init-hook="import pylint_venv; pylint_venv.inithook(force_venv_activation=True)"

This will try to automatically detect virtualenv and activate it.

Troubleshooting

General

pylint_venv fails to import

Most likely pylint-venv is not installed in the same virtual environment as pylint. Either make sure to ensure pylint-venv into the same virtual environment as pylint, or add the appropriate path in the init hook:

import sys
sys.path.append("/path/to/installation/folder/of/pylint_venv")
pylint_venv breaks parsing with tools

When tools call pylint with -f json, an extra line may break the parser, as the output is no longer valid json. To avoid printing “using venv …”, pass quiet=True to inithook

$ pylint -f json --init-hook="import pylint_venv; pylint_venv.inithook(quiet=True)"
Virtual environment does not get used (installed modules are reported as ‘unable to import’)

Most likely the virtual environment does not get activated because pylint itself runs in a virtual environment. You can force the activation of the virtual environment with the force_venv_activation=True flag to the pylint_venv.inithook function.

Homebrew

Homebrew installs pylint into a separate virtual environment, thus you will need to set the force_venv_activation=True flag. This also means, that pylint_venv will be in a different search path and you must add the proper path to sys.path. You can use the following configuration adjusted to your Python version:

[MAIN]
init-hook=
    import sys
    sys.path.append("/usr/local/lib/python3.8/site-packages")
    try: import pylint_venv
    except ImportError: pass
    else: pylint_venv.inithook(force_venv_activation=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylint_venv-3.0.4.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

pylint_venv-3.0.4-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pylint_venv-3.0.4.tar.gz.

File metadata

  • Download URL: pylint_venv-3.0.4.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Linux/6.5.0-1025-azure

File hashes

Hashes for pylint_venv-3.0.4.tar.gz
Algorithm Hash digest
SHA256 4c71c2ad14fc0549699440bcc460994ffddc1481b9078404b4c43d2806ef0f59
MD5 f0783cfe8bf8f043a6f53d809548ea0b
BLAKE2b-256 48ac88e53ad1362392e68a36a4f08ca82c76e6cb6321d8ecba901cca5a70dcc1

See more details on using hashes here.

File details

Details for the file pylint_venv-3.0.4-py3-none-any.whl.

File metadata

  • Download URL: pylint_venv-3.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Linux/6.5.0-1025-azure

File hashes

Hashes for pylint_venv-3.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 31006a3df398f58f962c9e5620e756b284e8b2bc490594ce5ee5da41920cb32c
MD5 dae2a93fbb9b593df8415a36256065bb
BLAKE2b-256 a610040e1928236e3d34b26639e3427df88c7249a85aadc621cea2158589b4f8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page