Skip to content

Commit 9a73a6e

Browse files
committed
trying ruff
Signed-off-by: emdneto <[email protected]> remove unecessary lint stuff Signed-off-by: emdneto <[email protected]> update pyproject.toml and pre-commit to auto fix lint Signed-off-by: emdneto <[email protected]> add parameter --show-fixes to pre-commit Signed-off-by: emdneto <[email protected]> some fixes to generate.sh in semconv Signed-off-by: emdneto <[email protected]>
1 parent d1904b9 commit 9a73a6e

File tree

10 files changed

+86
-186
lines changed

10 files changed

+86
-186
lines changed

.flake8

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

.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

.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

lint-requirements.txt

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

pyproject.toml

Lines changed: 39 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,42 @@ 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+
output-format = "concise"
22+
23+
[tool.ruff.lint]
24+
# https://docs.astral.sh/ruff/linter/#rule-selection
25+
# pylint: https://github.com/astral-sh/ruff/issues/970
26+
select = [
27+
"I", # isort
28+
"F", # pyflakes
29+
"E", # pycodestyle errors
30+
"W", # pycodestyle warnings
31+
"PLC", # pylint convention
32+
"PLE", # pylint error
33+
"Q", # flake8-quotes
34+
]
35+
36+
ignore = [
37+
"E501", # line-too-long
38+
]
39+
40+
[tool.ruff.lint.per-file-ignores]
41+
"docs/**/*.*" = ["PLE"]
42+
43+
[tool.ruff.lint.isort]
44+
known-third-party = [
45+
"psutil",
46+
"pytest",
47+
"redis",
48+
"redis_opentracing",
49+
"opencensus",
50+
]
51+
known-first-party = ["opentelemetry", "opentelemetry_example_app"]

scripts/semconv/generate.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,4 @@ mkdir -p ${ROOT_DIR}/opentelemetry-semantic-conventions/src/opentelemetry/semcon
5858
generate "./" "./${INCUBATING_DIR}/" "any"
5959

6060
cd "$ROOT_DIR"
61-
${ROOT_DIR}/.tox/lint/bin/black --config pyproject.toml ${ROOT_DIR}/opentelemetry-semantic-conventions/src/opentelemetry/semconv
62-
${ROOT_DIR}/.tox/lint/bin/isort ${ROOT_DIR}/opentelemetry-semantic-conventions/src/opentelemetry/semconv
61+
tox -e ruff

0 commit comments

Comments
 (0)