diff --git a/CHANGES.md b/CHANGES.md index 6c8b1eb..ac1a853 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Official support for Pylint 3. - Official support for Python 3.12. +- Documentation for configuration within `pyproject.toml` + ([#17](https://github.com/jgosmann/pylint-venv/issues/17), + [#19](https://github.com/jgosmann/pylint-venv/pull/19)). ## [3.0.2] - 2023-06-12 diff --git a/README.rst b/README.rst index 949d29e..574cd76 100644 --- a/README.rst +++ b/README.rst @@ -12,8 +12,29 @@ 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. -Add the following to your ``~/.pylintrc``: +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 @@ -22,6 +43,13 @@ Add the following to your ``~/.pylintrc``: 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 diff --git a/test/pyproject.toml b/test/pyproject.toml new file mode 100644 index 0000000..15bcc55 --- /dev/null +++ b/test/pyproject.toml @@ -0,0 +1,5 @@ +[tool.pylint.MAIN] +init-hook = """ +import pylint_venv +pylint_venv.inithook(force_venv_activation=True) +""" diff --git a/test/test.sh b/test/test.sh index 1feecdb..10a1165 100755 --- a/test/test.sh +++ b/test/test.sh @@ -8,4 +8,5 @@ VENV_DIR=$(mktemp -d) python3 -m venv "$VENV_DIR" source "$VENV_DIR/bin/activate" pylint --rcfile "$WORKDIR/pylintrc" "$WORKDIR/empty.py" 2>&1 | tee "$VENV_DIR/pylint.log" | grep "^Using venv: $VENV_DIR\$" +pylint --rcfile "$WORKDIR/pyproject.toml" "$WORKDIR/empty.py" 2>&1 | tee "$VENV_DIR/pylint.log" | grep "^Using venv: $VENV_DIR\$" rm -r "$VENV_DIR"