pylint-venv


Namepylint-venv JSON
Version 3.0.4 PyPI version JSON
download
home_pagehttps://github.com/jgosmann/pylint-venv/
Summarypylint-venv provides a Pylint init-hook to use the same Pylint installation with different virtual environments.
upload_time2024-10-27 10:42:14
maintainerJan Gosmann
docs_urlNone
authorJan Gosmann
requires_python<4.0.0,>=3.7.2
licenseMIT
keywords pylint virtualenv venv
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://github.com/jgosmann/pylint-venv/actions/workflows/ci.yml/badge.svg
  :target: https://github.com/jgosmann/pylint-venv/actions/workflows/ci.yml
  :alt: CI and release pipeline
.. image:: https://img.shields.io/pypi/v/pylint-venv
  :target: https://pypi.org/project/pylint-venv/
  :alt: PyPI
.. image:: https://img.shields.io/pypi/pyversions/pylint-venv
  :target: https://pypi.org/project/pylint-venv/
  :alt: PyPI - Python Version
.. image:: https://img.shields.io/pypi/l/pylint-venv
  :target: https://pypi.org/project/pylint-venv/
  :alt: 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
------------

.. code:: bash

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

.. code:: 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``:

.. code:: ini

    [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``:

.. code:: console

    PYLINT_VENV_PATH=.venv:.virtualenv

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

.. code:: console

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

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

.. code:: console

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

.. code:: console

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

.. code:: python

    import sys
    sys.path.append("/path/to/installation/folder/of/pylint_venv")


pylint_venv breaks parsing with tools
"""""""""""""""""""""""""""""""""""""

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

.. code:: console

   $ 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 :code:`force_venv_activation=True` flag to the
:code:`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:

.. code:: ini

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


.. _Pylint: http://www.pylint.org/
.. _virtualenv: https://virtualenv.pypa.io/en/latest/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jgosmann/pylint-venv/",
    "name": "pylint-venv",
    "maintainer": "Jan Gosmann",
    "docs_url": null,
    "requires_python": "<4.0.0,>=3.7.2",
    "maintainer_email": "jan@hyper-world.de",
    "keywords": "pylint, virtualenv, venv",
    "author": "Jan Gosmann",
    "author_email": "jan@hyper-world.de",
    "download_url": "https://files.pythonhosted.org/packages/48/ac/88e53ad1362392e68a36a4f08ca82c76e6cb6321d8ecba901cca5a70dcc1/pylint_venv-3.0.4.tar.gz",
    "platform": null,
    "description": ".. image:: https://github.com/jgosmann/pylint-venv/actions/workflows/ci.yml/badge.svg\n  :target: https://github.com/jgosmann/pylint-venv/actions/workflows/ci.yml\n  :alt: CI and release pipeline\n.. image:: https://img.shields.io/pypi/v/pylint-venv\n  :target: https://pypi.org/project/pylint-venv/\n  :alt: PyPI\n.. image:: https://img.shields.io/pypi/pyversions/pylint-venv\n  :target: https://pypi.org/project/pylint-venv/\n  :alt: PyPI - Python Version\n.. image:: https://img.shields.io/pypi/l/pylint-venv\n  :target: https://pypi.org/project/pylint-venv/\n  :alt: PyPI - License\n\n\npylint-venv\n===========\n\nPylint_ does not respect the currently activated virtualenv_ if it is not\ninstalled in every virtual environment individually.  This module provides\na Pylint init-hook to use the same Pylint installation with different virtual\nenvironments.\n\nInstallation\n------------\n\n.. code:: bash\n\n    pip install pylint-venv\n    \nAdd the hook to your Pylint configuration. See the section below corresponding\nto the type of configuration file you use.\n\nConfigure with ``pyproject.toml``\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nAdd the following to your ``pyproject.toml``:\n\n.. code:: toml\n   \n    [tool.pylint.MAIN]\n    init-hook = \"\"\"\n    try: import pylint_venv\n    except ImportError: pass\n    else: pylint_venv.inithook()\n    \"\"\"\n\n\nConfigure with ``.pylintrc``\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nAdd the following to your ``.pylintrc``:\n\n.. code:: ini\n\n    [MAIN]\n    init-hook=\n        try: import pylint_venv\n        except ImportError: pass\n        else: pylint_venv.inithook()\n        \nIf you add this to your ``~/.pylintrc`` in your home directory, it will be\napplied to all projects by default.\n\n        \nUsage\n-----\n\nThe hook will then be used automatically if\n\n- a virtualenv without pylint is active,\n\n- or a Conda environment without pylint is active,\n\n- or no environment is active but your CWD contains virtualenv directory.\n\nAnything listed in the ``PYLINT_VENV_PATH`` environment variable is considered\na virtualenv directory. The default, if the variable is unset, is `.venv`. Use\na colon (`:`) as path separator. Example for checking directories ``.venv`` and\n``.virtualenv``:\n\n.. code:: console\n\n    PYLINT_VENV_PATH=.venv:.virtualenv\n\nYou can also call the hook via a command line argument:\n\n.. code:: console\n\n    $ pylint --init-hook=\"import pylint_venv; pylint_venv.inithook()\"\n\nThis way you can also explicitly set an environment to be used:\n\n.. code:: console\n\n    $ pylint --init-hook=\"import pylint_venv; pylint_venv.inithook('$(pwd)/env')\"\n\nIf ``pylint`` itself is installed in a virtualenv, then you can ignore it by passing\n``force_venv_activation=True`` to force the activation of a different virtualenv:\n\n.. code:: console\n\n    $ pylint --init-hook=\"import pylint_venv; pylint_venv.inithook(force_venv_activation=True)\"\n\n\nThis will try to automatically detect virtualenv and activate it.\n\n\nTroubleshooting\n---------------\n\nGeneral\n^^^^^^^\n\npylint_venv fails to import\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n\nMost likely pylint-venv is not installed in the same virtual environment as\npylint. Either make sure to ensure pylint-venv into the same virtual environment\nas pylint, or add the appropriate path in the init hook:\n\n.. code:: python\n\n    import sys\n    sys.path.append(\"/path/to/installation/folder/of/pylint_venv\")\n\n\npylint_venv breaks parsing with tools\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n\nWhen tools call pylint with :code:`-f json`, an extra line may break the parser, as the \noutput is no longer valid json. To avoid printing \"using venv ...\", pass :code:`quiet=True`\nto :code:`inithook`\n\n.. code:: console\n\n   $ pylint -f json --init-hook=\"import pylint_venv; pylint_venv.inithook(quiet=True)\"\n\n\nVirtual environment does not get used (installed modules are reported as 'unable to import')\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n\nMost likely the virtual environment does not get activated because pylint itself\nruns in a virtual environment. You can force the activation of the virtual\nenvironment with the :code:`force_venv_activation=True` flag to the\n:code:`pylint_venv.inithook` function.\n\n\nHomebrew\n^^^^^^^^\n\nHomebrew installs pylint into a separate virtual environment, thus you will\nneed to set the `force_venv_activation=True` flag. This also means, that\npylint_venv will be in a different search path and you must add the proper\npath to `sys.path`. You can use the following configuration adjusted to your\nPython version:\n\n.. code:: ini\n\n    [MAIN]\n    init-hook=\n        import sys\n        sys.path.append(\"/usr/local/lib/python3.8/site-packages\")\n        try: import pylint_venv\n        except ImportError: pass\n        else: pylint_venv.inithook(force_venv_activation=True)\n\n\n.. _Pylint: http://www.pylint.org/\n.. _virtualenv: https://virtualenv.pypa.io/en/latest/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "pylint-venv provides a Pylint init-hook to use the same Pylint installation with different virtual environments.",
    "version": "3.0.4",
    "project_urls": {
        "Homepage": "https://github.com/jgosmann/pylint-venv/",
        "Repository": "https://github.com/jgosmann/pylint-venv/"
    },
    "split_keywords": [
        "pylint",
        " virtualenv",
        " venv"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a610040e1928236e3d34b26639e3427df88c7249a85aadc621cea2158589b4f8",
                "md5": "dae2a93fbb9b593df8415a36256065bb",
                "sha256": "31006a3df398f58f962c9e5620e756b284e8b2bc490594ce5ee5da41920cb32c"
            },
            "downloads": -1,
            "filename": "pylint_venv-3.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dae2a93fbb9b593df8415a36256065bb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.7.2",
            "size": 5312,
            "upload_time": "2024-10-27T10:42:13",
            "upload_time_iso_8601": "2024-10-27T10:42:13.065598Z",
            "url": "https://files.pythonhosted.org/packages/a6/10/040e1928236e3d34b26639e3427df88c7249a85aadc621cea2158589b4f8/pylint_venv-3.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "48ac88e53ad1362392e68a36a4f08ca82c76e6cb6321d8ecba901cca5a70dcc1",
                "md5": "f0783cfe8bf8f043a6f53d809548ea0b",
                "sha256": "4c71c2ad14fc0549699440bcc460994ffddc1481b9078404b4c43d2806ef0f59"
            },
            "downloads": -1,
            "filename": "pylint_venv-3.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "f0783cfe8bf8f043a6f53d809548ea0b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.7.2",
            "size": 5772,
            "upload_time": "2024-10-27T10:42:14",
            "upload_time_iso_8601": "2024-10-27T10:42:14.138480Z",
            "url": "https://files.pythonhosted.org/packages/48/ac/88e53ad1362392e68a36a4f08ca82c76e6cb6321d8ecba901cca5a70dcc1/pylint_venv-3.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-27 10:42:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jgosmann",
    "github_project": "pylint-venv",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pylint-venv"
}
        
Elapsed time: 0.39693s