Skip to content

Commit affecbd

Browse files
authored
Introducing ruff as linter and formatter (basic setup) (open-telemetry#4223)
1 parent e32911b commit affecbd

File tree

144 files changed

+384
-741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+384
-741
lines changed

.flake8

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/workflows/generate_workflows.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from pathlib import Path
22

33
from generate_workflows_lib import (
4-
generate_test_workflow,
5-
generate_lint_workflow,
64
generate_contrib_workflow,
7-
generate_misc_workflow
5+
generate_lint_workflow,
6+
generate_misc_workflow,
7+
generate_test_workflow,
88
)
99

1010
tox_ini_path = Path(__file__).parent.parent.parent.joinpath("tox.ini")

.github/workflows/misc_0.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,21 @@ jobs:
233233

234234
- name: Check workflows are up to date
235235
run: git diff --exit-code || (echo 'Generated workflows are out of date, run "tox -e generate-workflows" and commit the changes in this PR.' && exit 1)
236+
237+
ruff:
238+
name: ruff
239+
runs-on: ubuntu-latest
240+
steps:
241+
- name: Checkout repo @ SHA - ${{ github.sha }}
242+
uses: actions/checkout@v4
243+
244+
- name: Set up Python 3.10
245+
uses: actions/setup-python@v5
246+
with:
247+
python-version: "3.10"
248+
249+
- name: Install tox
250+
run: pip install tox
251+
252+
- name: Run tests
253+
run: tox -e ruff

.isort.cfg

Lines changed: 0 additions & 19 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
repos:
2-
- repo: https://github.com/psf/black-pre-commit-mirror
3-
rev: 24.3.0
4-
hooks:
5-
- id: black
6-
language_version: python3.12
7-
- repo: https://github.com/pycqa/isort
8-
rev: 5.12.0
9-
hooks:
10-
- id: isort
11-
- repo: https://github.com/pycqa/flake8
12-
rev: '6.1.0'
13-
hooks:
14-
- id: flake8
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.6.9
5+
hooks:
6+
# Run the linter.
7+
- id: ruff
8+
args: ["--fix", "--show-fixes"]
9+
# Run the formatter.
10+
- id: ruff-format

CONTRIBUTING.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,15 @@ You can run `tox` with the following arguments:
5858
Python version
5959
- `tox -e spellcheck` to run a spellcheck on all the code
6060
- `tox -e lint-some-package` to run lint checks on `some-package`
61+
- `tox -e ruff` to run ruff linter and formatter checks against the entire codebase
6162

62-
`black` and `isort` are executed when `tox -e lint` is run. The reported errors can be tedious to fix manually.
63-
An easier way to do so is:
64-
65-
1. Run `.tox/lint/bin/black .`
66-
2. Run `.tox/lint/bin/isort .`
67-
68-
Or you can call formatting and linting in one command by [pre-commit](https://pre-commit.com/):
63+
`ruff check` and `ruff format` are executed when `tox -e ruff` is run. We strongly recommend you to configure [pre-commit](https://pre-commit.com/) locally to run `ruff` automatically before each commit by installing it as git hooks. You just need to [install pre-commit](https://pre-commit.com/#install) in your environment:
6964

7065
```console
71-
$ pre-commit
66+
$ pip install pre-commit -c dev-requirements.txt
7267
```
7368

74-
You can also configure it to run lint tools automatically before committing with:
69+
and run this command inside the git repository:
7570

7671
```console
7772
$ pre-commit install

dev-requirements.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
pylint==3.2.1
2-
flake8==6.1.0
3-
isort==5.12.0
4-
black==24.3.0
52
httpretty==1.1.4
63
mypy==1.9.0
74
sphinx==7.1.2
@@ -20,3 +17,4 @@ psutil==5.9.6
2017
GitPython==3.1.41
2118
pre-commit==3.7.0; python_version >= '3.9'
2219
pre-commit==3.5.0; python_version < '3.9'
20+
ruff==0.6.9

docs/conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@
204204
.. |SCM_WEB| replace:: {s}
205205
.. |SCM_RAW_WEB| replace:: {sr}
206206
.. |SCM_BRANCH| replace:: {b}
207-
""".format(
208-
s=scm_web, sr=scm_raw_web, b=branch
209-
)
207+
""".format(s=scm_web, sr=scm_raw_web, b=branch)
210208

211209
# used to have links to repo files
212210
extlinks = {

docs/examples/auto-instrumentation/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
assert len(argv) == 2
3636

3737
with tracer.start_as_current_span("client"):
38-
3938
with tracer.start_as_current_span("client-server"):
4039
headers = {}
4140
inject(headers)

docs/examples/django/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434

3535
with tracer.start_as_current_span("client"):
36-
3736
with tracer.start_as_current_span("client-server"):
3837
headers = {}
3938
inject(headers)

0 commit comments

Comments
 (0)