Skip to content

Commit

Permalink
Support alternative virtualenv directories #10
Browse files Browse the repository at this point in the history
This introduces a new PYLINT_VENV_PATH environment variable to pass a
list of paths that will be checked.
  • Loading branch information
Exagone313 committed Jun 5, 2022
1 parent a80a6c1 commit f426644
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Check alternative directory locations given by the `PYLINT_VENV_PATH`
environment variable. The variable consists of paths separated by a
colon `:`.

## [2.1.1] - 2020-08-17

### Fixed
Expand Down
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ The hook will then be used automatically if

- no env is activated but your CWD contains a virtualenv in ``.venv``

- it also reads the ``PYLINT_VENV_PATH`` environment variable for finding
alternative locations, e.g. for checking directories ``.venv`` and
``.virtualenv``:
.. code:: console
PYLINT_VENV_PATH=.venv:.virtualenv
and if pylint is not installed in that env, too.

You can also call the hook via a command line argument:
Expand Down
9 changes: 6 additions & 3 deletions pylint_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ def detect_venv():
if venv:
return venv

# Check if a local ".venv" folder exists
# Check if a virtualenv directory exists (.venv by default, or alternative
# paths given by environment variable)
venv_paths = os.getenv("PYLINT_VENV_PATH", ".venv").split(":")
cwd = os.getcwd()
exec_path = "Scripts" if IS_WIN else "bin"
if os.path.isfile(os.path.join(cwd, ".venv", exec_path, "activate")):
return os.path.join(cwd, ".venv")
for venv_dir in venv_paths:
if os.path.isfile(os.path.join(cwd, venv_dir, exec_path, "activate")):
return os.path.join(cwd, venv_dir)

return None

Expand Down

0 comments on commit f426644

Please sign in to comment.