Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test and document configuration with pyproject.toml #19

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions test/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.pylint.MAIN]
init-hook = """
import pylint_venv
pylint_venv.inithook(force_venv_activation=True)
"""
1 change: 1 addition & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"