Skip to content

Commit

Permalink
trying ruff
Browse files Browse the repository at this point in the history
Signed-off-by: emdneto <[email protected]>
  • Loading branch information
emdneto committed Oct 13, 2024
1 parent 2bcbbcc commit 5017c97
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 50 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/misc_0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,21 @@ jobs:

- name: Check workflows are up to date
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)

ruff:
name: ruff
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install tox
run: pip install tox

- name: Run tests
run: tox -e ruff
21 changes: 8 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.3.0
hooks:
- id: black
language_version: python3.12
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: '6.1.0'
hooks:
- id: flake8
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.9
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
13 changes: 4 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,15 @@ You can run `tox` with the following arguments:
Python version
- `tox -e spellcheck` to run a spellcheck on all the code
- `tox -e lint-some-package` to run lint checks on `some-package`
- `tox -e ruff` to run ruff linter and formatter checks against the entire codebase

`black` and `isort` are executed when `tox -e lint` is run. The reported errors can be tedious to fix manually.
An easier way to do so is:

1. Run `.tox/lint/bin/black .`
2. Run `.tox/lint/bin/isort .`

Or you can call formatting and linting in one command by [pre-commit](https://pre-commit.com/):
`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:

```console
$ pre-commit
$ pip install pre-commit -c dev-requirements.txt
```

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

```console
$ pre-commit install
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ psutil==5.9.6
GitPython==3.1.41
pre-commit==3.7.0; python_version >= '3.9'
pre-commit==3.5.0; python_version < '3.9'
ruff==0.6.9
44 changes: 27 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
[tool.black]
line-length = 79
exclude = '''
(
/( # generated files
.tox|
venv|
venv.*|
.venv.*|
target.*|
.*/build/lib/.*|
exporter/opentelemetry-exporter-zipkin-proto-http/src/opentelemetry/exporter/zipkin/proto/http/v2/gen|
opentelemetry-proto/src/opentelemetry/proto/.*/.*|
scripts
)/
)
'''
[tool.pytest.ini_options]
addopts = "-rs -v"
log_cli = true
Expand All @@ -27,3 +10,30 @@ include = [
"opentelemetry-sdk/src",
"opentelemetry-semantic-conventions/src",
]

[tool.ruff]
# https://docs.astral.sh/ruff/configuration/
target-version = "py38"
line-length = 79
extend-exclude = [
"*_pb2*.py*",
]
fix = true
output-format = "concise"

[tool.ruff.lint]
# https://docs.astral.sh/ruff/linter/#rule-selection
# pylint: https://github.com/astral-sh/ruff/issues/970
select = ["E4", "E7", "E9", "F", "W", "Q", "I", "PLE"]
fixable = ["I", "F", "Q", "W"]
ignore = ["F401", "E501"] # TODO: fix all of them later

[tool.ruff.lint.isort]
known-third-party = [
"psutil",
"pytest",
"redis",
"redis_opentracing",
"opencensus",
]
known-first-party = ["opentelemetry", "opentelemetry_example_app"]
20 changes: 9 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ envlist =
public-symbols-check
shellcheck
generate-workflows
ruff

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

[testenv:lint]
basepython: python3
recreate = True
deps =
-r dev-requirements.txt

commands =
black --config {toxinidir}/pyproject.toml {toxinidir} --diff --check
isort --settings-path {toxinidir}/.isort.cfg {toxinidir} --diff --check-only
flake8 --config {toxinidir}/.flake8 {toxinidir}

[testenv:spellcheck]
basepython: python3
recreate = True
Expand Down Expand Up @@ -461,3 +451,11 @@ commands_pre =
commands =
pyright --version
pyright

[testenv:ruff]
basepython: python3
deps =
-c {toxinidir}/dev-requirements.txt
pre-commit
commands =
pre-commit run -a --color=always

0 comments on commit 5017c97

Please sign in to comment.