Skip to content

Commit b1fa4ae

Browse files
authored
Feature/544 add ruff to remove unused imports (#605)
* Add ruff to dependencies * Remove unused imports via ruff * Add ruff setting and ignore F401 in tasks where we need to share all the defined nox sessions * Modify project:fix and project:format to include ruff * Add ruff settings to cookiecutter template & update documentation * Adapt changelog * Add on unit tests for other formatting tools * Update isort to latest version * Prepare release 3.0.0
1 parent d767512 commit b1fa4ae

File tree

34 files changed

+730
-441
lines changed

34 files changed

+730
-441
lines changed

.github/actions/security-issues/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ runs:
3939
- name: Install Python Toolbox / Security tool
4040
shell: bash
4141
run: |
42-
pip install exasol-toolbox==2.0.0
42+
pip install exasol-toolbox==3.0.0
4343
4444
- name: Create Security Issue Report
4545
shell: bash

doc/changes/changelog.md

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/changes/changes_3.0.0.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# 3.0.0 - 2025-11-20
2+
3+
## Summary
4+
5+
This is a major release with potentially breaking changes as nox session `project:fix` has been modified and potentially can create many unexpected changes.
6+
7+
This release adds [ruff](https://docs.astral.sh/ruff/) to Nox sessions `project:format` and `project:fix` to check for and remove unused imports.
8+
9+
As `ruff` potentially can also apply many other changes, we recommend updating the `pyproject.toml` file in your project as specified here: [Formatting Code Configuration](https://exasol.github.io/python-toolbox/main/user_guide/features/formatting_code/index.html#configuration).
10+
11+
Additionally, `isort` has been updated from `^6.0.0` to `^7.0.0`. In 7.x, `isort` has provided fixes for Python 3.14.
12+
13+
## Documentation
14+
15+
* #589: Corrected configuration for Sonar documentation for host.url
16+
* #535: Added more information about Sonar's usage of ``exclusions``
17+
* #596: Corrected and added more information regarding ``pyupgrade``
18+
19+
## Features
20+
21+
* #595: Created class `ResolvedVulnerabilities` to track resolved vulnerabilities between versions
22+
* #544: Modified nox sessions `project:fix` and `project:format` to use ruff to remove unused imports
23+
24+
## Refactoring
25+
26+
* #596: Added newline after header in versioned changelog
27+
28+
## Dependency Updates
29+
30+
### `main`
31+
* Updated dependency `bandit:1.8.6` to `1.9.1`
32+
* Updated dependency `black:25.9.0` to `25.11.0`
33+
* Updated dependency `coverage:7.11.0` to `7.12.0`
34+
* Updated dependency `import-linter:2.5.2` to `2.7`
35+
* Updated dependency `isort:6.1.0` to `7.0.0`
36+
* Updated dependency `nox:2025.10.16` to `2025.11.12`
37+
* Updated dependency `pre-commit:4.3.0` to `4.4.0`
38+
* Updated dependency `pydantic:2.12.3` to `2.12.4`
39+
* Updated dependency `pylint:4.0.2` to `4.0.3`
40+
* Updated dependency `pytest:8.4.2` to `9.0.1`
41+
* Updated dependency `pyupgrade:3.21.0` to `3.21.2`
42+
* Added dependency `ruff:0.14.5`
43+
* Updated dependency `shibuya:2025.11.4` to `2025.11.10`

doc/changes/unreleased.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1 @@
11
# Unreleased
2-
3-
## Documentation
4-
5-
* #589: Corrected configuration for Sonar documentation for host.url
6-
* #535: Added more information about Sonar's usage of ``exclusions``
7-
* #596: Corrected and added more information regarding ``pyupgrade``
8-
9-
## Features
10-
11-
* #595: Created class `ResolvedVulnerabilities` to track resolved vulnerabilities between versions
12-
13-
## Refactoring
14-
15-
* #596: Added newline after header in versioned changelog

doc/user_guide/features/formatting_code/index.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ For autoformatting, the following tools are used:
2727
packages, third party packages, and local application imports).
2828
* `pyupgrade <https://pypi.org/project/pyupgrade/>`__ - upgrades syntax for newer
2929
versions of the Python language.
30+
* `ruff <https://docs.astral.sh/ruff/>`__ - includes a plethora of tools to check and
31+
automatically format code. In the PTB, only the following checks are active:
32+
33+
* `unused-import (F401) <https://docs.astral.sh/ruff/rules/unused-import/>`__ - removes unused imports
3034

3135
In the PTB, these tools are bundled into nox sessions to ensure that they are run in a
3236
deterministic manner.
@@ -81,3 +85,16 @@ and is defined in the :meth:`exasol.toolbox.config.BaseConfig.pyupgrade_argument
8185

8286
For further configuration options, see the
8387
`pyupgrade documentation <https://pypi.org/project/pyupgrade/>`__.
88+
89+
ruff
90+
^^^^
91+
92+
Ensure ``ruff`` is configured like so:
93+
94+
.. literalinclude:: ../../../../project-template/{{cookiecutter.repo_name}}/pyproject.toml
95+
:language: toml
96+
:start-at: [tool.ruff.lint]
97+
:end-before: [tool.mypy.overrides]
98+
99+
For further configuration options, see
100+
`ruff options <https://docs.astral.sh/ruff/configuration>`__.

doc/user_guide/features/formatting_code/troubleshooting.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ might want to ignore automatically applied formatting.
3838
| | | |
3939
| | <line-to-ignore> # isort:skip| # isort:skip_file |
4040
+-----------------------+--------------------------------+-----------------------+
41+
| formatting from ruff | .. code-block:: python | .. code-block:: python|
42+
| (example with F401) | | |
43+
| | <line-to-ignore> # noqa: F401| # ruff: noqa F401 |
44+
+-----------------------+--------------------------------+-----------------------+
4145

4246

4347
In the ``checks.yml``, ``project:format`` wants me to reformat code I did not modify

exasol/toolbox/metrics.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
from tempfile import TemporaryDirectory
2020
from typing import (
2121
Any,
22-
Dict,
23-
List,
24-
Optional,
25-
Union,
2622
)
2723

2824

exasol/toolbox/nox/_artifacts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import sys
88
from collections.abc import Iterable
99
from pathlib import Path
10-
from typing import Optional
1110

1211
import nox
1312
from nox import Session

exasol/toolbox/nox/_format.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,26 @@ def _pyupgrade(session: Session, config: Config, files: Iterable[str]) -> None:
3535
)
3636

3737

38+
def _ruff(session: Session, mode: Mode, files: Iterable[str]):
39+
def command(*args: str) -> Iterable[str]:
40+
return args if mode == Mode.Check else list(args) + ["--fix"]
41+
42+
session.run(*command("ruff", "check"), *files)
43+
44+
3845
@nox.session(name="project:fix", python=False)
3946
def fix(session: Session) -> None:
4047
"""Runs all automated fixes on the code base"""
4148
py_files = python_files(PROJECT_CONFIG.root)
4249
_version(session, Mode.Fix)
4350
_pyupgrade(session, config=PROJECT_CONFIG, files=py_files)
51+
_ruff(session, mode=Mode.Fix, files=py_files)
4452
_code_format(session, Mode.Fix, py_files)
4553

4654

4755
@nox.session(name="project:format", python=False)
4856
def fmt_check(session: Session) -> None:
4957
"""Checks the project for correct formatting"""
5058
py_files = python_files(PROJECT_CONFIG.root)
59+
_ruff(session, mode=Mode.Check, files=py_files)
5160
_code_format(session=session, mode=Mode.Check, files=py_files)

exasol/toolbox/nox/tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import nox
2020
from nox import Session
2121

22+
# ruff: noqa F401
2223
from exasol.toolbox.nox._format import (
2324
_code_format,
2425
fix,

0 commit comments

Comments
 (0)