Skip to content

Commit 5017c97

Browse files
committed
trying ruff
Signed-off-by: emdneto <[email protected]>
1 parent 2bcbbcc commit 5017c97

File tree

6 files changed

+67
-50
lines changed

6 files changed

+67
-50
lines changed

.github/workflows/misc_0.yml

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

229229
- name: Check workflows are up to date
230230
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)
231+
232+
ruff:
233+
name: ruff
234+
runs-on: ubuntu-latest
235+
steps:
236+
- name: Checkout repo @ SHA - ${{ github.sha }}
237+
uses: actions/checkout@v4
238+
239+
- name: Set up Python 3.10
240+
uses: actions/setup-python@v5
241+
with:
242+
python-version: "3.10"
243+
244+
- name: Install tox
245+
run: pip install tox
246+
247+
- name: Run tests
248+
run: tox -e ruff

.pre-commit-config.yaml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
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+
# Run the formatter.
9+
- 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ psutil==5.9.6
2020
GitPython==3.1.41
2121
pre-commit==3.7.0; python_version >= '3.9'
2222
pre-commit==3.5.0; python_version < '3.9'
23+
ruff==0.6.9

pyproject.toml

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
[tool.black]
2-
line-length = 79
3-
exclude = '''
4-
(
5-
/( # generated files
6-
.tox|
7-
venv|
8-
venv.*|
9-
.venv.*|
10-
target.*|
11-
.*/build/lib/.*|
12-
exporter/opentelemetry-exporter-zipkin-proto-http/src/opentelemetry/exporter/zipkin/proto/http/v2/gen|
13-
opentelemetry-proto/src/opentelemetry/proto/.*/.*|
14-
scripts
15-
)/
16-
)
17-
'''
181
[tool.pytest.ini_options]
192
addopts = "-rs -v"
203
log_cli = true
@@ -27,3 +10,30 @@ include = [
2710
"opentelemetry-sdk/src",
2811
"opentelemetry-semantic-conventions/src",
2912
]
13+
14+
[tool.ruff]
15+
# https://docs.astral.sh/ruff/configuration/
16+
target-version = "py38"
17+
line-length = 79
18+
extend-exclude = [
19+
"*_pb2*.py*",
20+
]
21+
fix = true
22+
output-format = "concise"
23+
24+
[tool.ruff.lint]
25+
# https://docs.astral.sh/ruff/linter/#rule-selection
26+
# pylint: https://github.com/astral-sh/ruff/issues/970
27+
select = ["E4", "E7", "E9", "F", "W", "Q", "I", "PLE"]
28+
fixable = ["I", "F", "Q", "W"]
29+
ignore = ["F401", "E501"] # TODO: fix all of them later
30+
31+
[tool.ruff.lint.isort]
32+
known-third-party = [
33+
"psutil",
34+
"pytest",
35+
"redis",
36+
"redis_opentracing",
37+
"opencensus",
38+
]
39+
known-first-party = ["opentelemetry", "opentelemetry_example_app"]

tox.ini

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ envlist =
111111
public-symbols-check
112112
shellcheck
113113
generate-workflows
114+
ruff
114115

115116
[testenv]
116117
deps =
@@ -329,17 +330,6 @@ commands =
329330
; implicit Any due to unfollowed import would result).
330331
mypyinstalled: mypy --install-types --non-interactive --namespace-packages opentelemetry-api/tests/mypysmoke.py --strict
331332

332-
[testenv:lint]
333-
basepython: python3
334-
recreate = True
335-
deps =
336-
-r dev-requirements.txt
337-
338-
commands =
339-
black --config {toxinidir}/pyproject.toml {toxinidir} --diff --check
340-
isort --settings-path {toxinidir}/.isort.cfg {toxinidir} --diff --check-only
341-
flake8 --config {toxinidir}/.flake8 {toxinidir}
342-
343333
[testenv:spellcheck]
344334
basepython: python3
345335
recreate = True
@@ -461,3 +451,11 @@ commands_pre =
461451
commands =
462452
pyright --version
463453
pyright
454+
455+
[testenv:ruff]
456+
basepython: python3
457+
deps =
458+
-c {toxinidir}/dev-requirements.txt
459+
pre-commit
460+
commands =
461+
pre-commit run -a --color=always

0 commit comments

Comments
 (0)