pylint-venv


Namepylint-venv JSON
Version 3.0.3 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_time2023-10-24 18:52:11
maintainerJan Gosmann
docs_urlNone
authorJan Gosmann
requires_python>=3.7.2,<4.0.0
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": ">=3.7.2,<4.0.0",
    "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/f8/06/f60dce970f626de135961431d77dc10a071f5771128a22548a977874d2a0/pylint_venv-3.0.3.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.3",
    "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": "e2e8ba8f86765480a5778f28258b72e8ab62539e478026aef13a49d3dc5325ab",
                "md5": "cd6e2178297285db17b91f94ec9a9a28",
                "sha256": "3650960aa8dc93fad2377df66a616f41242d37c03178a34964ebb927ca83e1f7"
            },
            "downloads": -1,
            "filename": "pylint_venv-3.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cd6e2178297285db17b91f94ec9a9a28",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7.2,<4.0.0",
            "size": 5309,
            "upload_time": "2023-10-24T18:52:10",
            "upload_time_iso_8601": "2023-10-24T18:52:10.204339Z",
            "url": "https://files.pythonhosted.org/packages/e2/e8/ba8f86765480a5778f28258b72e8ab62539e478026aef13a49d3dc5325ab/pylint_venv-3.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f806f60dce970f626de135961431d77dc10a071f5771128a22548a977874d2a0",
                "md5": "1d16d84660d600a4053bf69fd6838b6d",
                "sha256": "df12a17fca39a94acc1c9a0f1dcf68141e90fe685569d78c046695c67c4e55fa"
            },
            "downloads": -1,
            "filename": "pylint_venv-3.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "1d16d84660d600a4053bf69fd6838b6d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7.2,<4.0.0",
            "size": 5740,
            "upload_time": "2023-10-24T18:52:11",
            "upload_time_iso_8601": "2023-10-24T18:52:11.726142Z",
            "url": "https://files.pythonhosted.org/packages/f8/06/f60dce970f626de135961431d77dc10a071f5771128a22548a977874d2a0/pylint_venv-3.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-24 18:52:11",
    "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.18210s