Skip to content

Commit

Permalink
trying ruff
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
emdneto committed Oct 13, 2024
1 parent 2bcbbcc commit 7a6052e
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 181 deletions.
35 changes: 0 additions & 35 deletions .flake8

This file was deleted.

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
19 changes: 0 additions & 19 deletions .isort.cfg

This file was deleted.

22 changes: 9 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
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
args: ["--fix", "--show-fixes"]
# 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
4 changes: 1 addition & 3 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
pylint==3.2.1
flake8==6.1.0
isort==5.12.0
black==24.3.0
httpretty==1.1.4
mypy==1.9.0
sphinx==7.1.2
Expand All @@ -20,3 +17,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
15 changes: 0 additions & 15 deletions lint-requirements.txt

This file was deleted.

56 changes: 39 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,42 @@ 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*",
]
output-format = "concise"

[tool.ruff.lint]
# https://docs.astral.sh/ruff/linter/#rule-selection
# pylint: https://github.com/astral-sh/ruff/issues/970
select = [
"I", # isort
"F", # pyflakes
"E", # pycodestyle errors
"W", # pycodestyle warnings
"PLC", # pylint convention
"PLE", # pylint error
"Q", # flake8-quotes
]

ignore = [
"E501", # line-too-long
]

[tool.ruff.lint.per-file-ignores]
"docs/**/*.*" = ["PLE"]

[tool.ruff.lint.isort]
known-third-party = [
"psutil",
"pytest",
"redis",
"redis_opentracing",
"opencensus",
]
known-first-party = ["opentelemetry", "opentelemetry_example_app"]
3 changes: 1 addition & 2 deletions scripts/semconv/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@ mkdir -p ${ROOT_DIR}/opentelemetry-semantic-conventions/src/opentelemetry/semcon
generate "./" "./${INCUBATING_DIR}/" "any"

cd "$ROOT_DIR"
${ROOT_DIR}/.tox/lint/bin/black --config pyproject.toml ${ROOT_DIR}/opentelemetry-semantic-conventions/src/opentelemetry/semconv
${ROOT_DIR}/.tox/lint/bin/isort ${ROOT_DIR}/opentelemetry-semantic-conventions/src/opentelemetry/semconv
tox -e ruff
77 changes: 9 additions & 68 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 @@ -199,120 +200,63 @@ commands_pre =

commands =
test-opentelemetry-api: pytest {toxinidir}/opentelemetry-api/tests {posargs}
lint-opentelemetry-api: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/opentelemetry-api
lint-opentelemetry-api: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/opentelemetry-api
lint-opentelemetry-api: flake8 --config {toxinidir}/.flake8 {toxinidir}/opentelemetry-api
lint-opentelemetry-api: pylint {toxinidir}/opentelemetry-api

test-opentelemetry-sdk: pytest {toxinidir}/opentelemetry-sdk/tests {posargs}
lint-opentelemetry-sdk: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/opentelemetry-sdk
lint-opentelemetry-sdk: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/opentelemetry-sdk
lint-opentelemetry-sdk: flake8 --config {toxinidir}/.flake8 {toxinidir}/opentelemetry-sdk
lint-opentelemetry-sdk: pylint {toxinidir}/opentelemetry-sdk
benchmark-opentelemetry-sdk: pytest {toxinidir}/opentelemetry-sdk/benchmarks --benchmark-json={toxinidir}/opentelemetry-sdk/sdk-benchmark.json {posargs}

test-opentelemetry-proto: pytest {toxinidir}/opentelemetry-proto/tests {posargs}
lint-opentelemetry-proto: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/opentelemetry-proto
lint-opentelemetry-proto: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/opentelemetry-proto
lint-opentelemetry-proto: flake8 --config {toxinidir}/.flake8 {toxinidir}/opentelemetry-proto
lint-opentelemetry-proto: pylint {toxinidir}/opentelemetry-proto

test-opentelemetry-semantic-conventions: pytest {toxinidir}/opentelemetry-semantic-conventions/tests {posargs}
lint-opentelemetry-semantic-conventions: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/opentelemetry-semantic-conventions
lint-opentelemetry-semantic-conventions: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/opentelemetry-semantic-conventions
lint-opentelemetry-semantic-conventions: flake8 --config {toxinidir}/.flake8 {toxinidir}/opentelemetry-semantic-conventions
lint-opentelemetry-semantic-conventions: pylint {toxinidir}/opentelemetry-semantic-conventions

test-opentelemetry-getting-started: pytest {toxinidir}/docs/getting_started/tests {posargs}
lint-opentelemetry-getting-started: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/docs/getting_started
lint-opentelemetry-getting-started: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/docs/getting_started
lint-opentelemetry-getting-started: flake8 --config {toxinidir}/.flake8 {toxinidir}/docs/getting_started
lint-opentelemetry-getting-started: pylint {toxinidir}/docs/getting_started

test-opentelemetry-opentracing-shim: pytest {toxinidir}/shim/opentelemetry-opentracing-shim/tests {posargs}
lint-opentelemetry-opentracing-shim: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/shim/opentelemetry-opentracing-shim
lint-opentelemetry-opentracing-shim: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/shim/opentelemetry-opentracing-shim
lint-opentelemetry-opentracing-shim: flake8 --config {toxinidir}/.flake8 {toxinidir}/shim/opentelemetry-opentracing-shim
lint-opentelemetry-opentracing-shim: sh -c "cd shim && pylint --rcfile ../.pylintrc {toxinidir}/shim/opentelemetry-opentracing-shim"

test-opentelemetry-opencensus-shim: pytest {toxinidir}/shim/opentelemetry-opencensus-shim/tests {posargs}
lint-opentelemetry-opencensus-shim: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/shim/opentelemetry-opencensus-shim
lint-opentelemetry-opencensus-shim: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/shim/opentelemetry-opencensus-shim
lint-opentelemetry-opencensus-shim: flake8 --config {toxinidir}/.flake8 {toxinidir}/shim/opentelemetry-opencensus-shim
lint-opentelemetry-opencensus-shim: sh -c "cd shim && pylint --rcfile ../.pylintrc {toxinidir}/shim/opentelemetry-opencensus-shim"

test-opentelemetry-exporter-opencensus: pytest {toxinidir}/exporter/opentelemetry-exporter-opencensus/tests {posargs}
lint-opentelemetry-exporter-opencensus: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/exporter/opentelemetry-exporter-opencensus
lint-opentelemetry-exporter-opencensus: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/exporter/opentelemetry-exporter-opencensus
lint-opentelemetry-exporter-opencensus: flake8 --config {toxinidir}/.flake8 {toxinidir}/exporter/opentelemetry-exporter-opencensus
lint-opentelemetry-exporter-opencensus: sh -c "cd exporter && pylint --rcfile ../.pylintrc {toxinidir}/exporter/opentelemetry-exporter-opencensus"

test-opentelemetry-exporter-otlp-proto-common: pytest {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-common/tests {posargs}
lint-opentelemetry-exporter-otlp-proto-common: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-common
lint-opentelemetry-exporter-otlp-proto-common: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-common
lint-opentelemetry-exporter-otlp-proto-common: flake8 --config {toxinidir}/.flake8 {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-common
lint-opentelemetry-exporter-otlp-proto-common: sh -c "cd exporter && pylint --rcfile ../.pylintrc {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-common"

test-opentelemetry-exporter-otlp-combined: pytest {toxinidir}/exporter/opentelemetry-exporter-otlp/tests {posargs}
lint-opentelemetry-exporter-otlp-combined: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/exporter/opentelemetry-exporter-otlp
lint-opentelemetry-exporter-otlp-combined: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/exporter/opentelemetry-exporter-otlp
lint-opentelemetry-exporter-otlp-combined: flake8 --config {toxinidir}/.flake8 {toxinidir}/exporter/opentelemetry-exporter-otlp
lint-opentelemetry-exporter-otlp-combined: sh -c "cd exporter && pylint --rcfile ../.pylintrc {toxinidir}/exporter/opentelemetry-exporter-otlp"

test-opentelemetry-exporter-otlp-proto-grpc: pytest {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-grpc/tests {posargs}
lint-opentelemetry-exporter-otlp-proto-grpc: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-grpc
lint-opentelemetry-exporter-otlp-proto-grpc: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-grpc
lint-opentelemetry-exporter-otlp-proto-grpc: flake8 --config {toxinidir}/.flake8 {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-grpc
lint-opentelemetry-exporter-otlp-proto-grpc: sh -c "cd exporter && pylint --rcfile ../.pylintrc {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-grpc"
benchmark-opentelemetry-exporter-otlp-proto-grpc: pytest {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-grpc/benchmarks --benchmark-json=exporter-otlp-proto-grpc-benchmark.json {posargs}

test-opentelemetry-exporter-otlp-proto-http: pytest {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-http/tests {posargs}
lint-opentelemetry-exporter-otlp-proto-http: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-http
lint-opentelemetry-exporter-otlp-proto-http: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-http
lint-opentelemetry-exporter-otlp-proto-http: flake8 --config {toxinidir}/.flake8 {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-http
lint-opentelemetry-exporter-otlp-proto-http: sh -c "cd exporter && pylint --rcfile ../.pylintrc {toxinidir}/exporter/opentelemetry-exporter-otlp-proto-http"

test-opentelemetry-exporter-prometheus: pytest {toxinidir}/exporter/opentelemetry-exporter-prometheus/tests {posargs}
lint-opentelemetry-exporter-prometheus: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/exporter/opentelemetry-exporter-prometheus
lint-opentelemetry-exporter-prometheus: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/exporter/opentelemetry-exporter-prometheus
lint-opentelemetry-exporter-prometheus: flake8 --config {toxinidir}/.flake8 {toxinidir}/exporter/opentelemetry-exporter-prometheus
lint-opentelemetry-exporter-prometheus: sh -c "cd exporter && pylint --rcfile ../.pylintrc {toxinidir}/exporter/opentelemetry-exporter-prometheus"

test-opentelemetry-exporter-zipkin-combined: pytest {toxinidir}/exporter/opentelemetry-exporter-zipkin/tests {posargs}
lint-opentelemetry-exporter-zipkin-combined: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/exporter/opentelemetry-exporter-zipkin
lint-opentelemetry-exporter-zipkin-combined: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/exporter/opentelemetry-exporter-zipkin
lint-opentelemetry-exporter-zipkin-combined: flake8 --config {toxinidir}/.flake8 {toxinidir}/exporter/opentelemetry-exporter-zipkin
lint-opentelemetry-exporter-zipkin-combined: sh -c "cd exporter && pylint --rcfile ../.pylintrc {toxinidir}/exporter/opentelemetry-exporter-zipkin"

test-opentelemetry-exporter-zipkin-proto-http: pytest {toxinidir}/exporter/opentelemetry-exporter-zipkin-proto-http/tests {posargs}
lint-opentelemetry-exporter-zipkin-proto-http: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/exporter/opentelemetry-exporter-zipkin-proto-http
lint-opentelemetry-exporter-zipkin-proto-http: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/exporter/opentelemetry-exporter-zipkin-proto-http
lint-opentelemetry-exporter-zipkin-proto-http: flake8 --config {toxinidir}/.flake8 {toxinidir}/exporter/opentelemetry-exporter-zipkin-proto-http
lint-opentelemetry-exporter-zipkin-proto-http: sh -c "cd exporter && pylint --rcfile ../.pylintrc {toxinidir}/exporter/opentelemetry-exporter-zipkin-proto-http"

test-opentelemetry-exporter-zipkin-json: pytest {toxinidir}/exporter/opentelemetry-exporter-zipkin-json/tests {posargs}
lint-opentelemetry-exporter-zipkin-json: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/exporter/opentelemetry-exporter-zipkin-json
lint-opentelemetry-exporter-zipkin-json: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/exporter/opentelemetry-exporter-zipkin-json
lint-opentelemetry-exporter-zipkin-json: flake8 --config {toxinidir}/.flake8 {toxinidir}/exporter/opentelemetry-exporter-zipkin-json
lint-opentelemetry-exporter-zipkin-json: sh -c "cd exporter && pylint --rcfile ../.pylintrc {toxinidir}/exporter/opentelemetry-exporter-zipkin-json"

test-opentelemetry-propagator-b3: pytest {toxinidir}/propagator/opentelemetry-propagator-b3/tests {posargs}
lint-opentelemetry-propagator-b3: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/propagator/opentelemetry-propagator-b3
lint-opentelemetry-propagator-b3: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/propagator/opentelemetry-propagator-b3
lint-opentelemetry-propagator-b3: flake8 --config {toxinidir}/.flake8 {toxinidir}/propagator/opentelemetry-propagator-b3
lint-opentelemetry-propagator-b3: sh -c "cd propagator && pylint --rcfile ../.pylintrc {toxinidir}/propagator/opentelemetry-propagator-b3"
benchmark-opentelemetry-propagator-b3: pytest {toxinidir}/propagator/opentelemetry-propagator-b3/benchmarks --benchmark-json=propagator-b3-benchmark.json {posargs}

test-opentelemetry-propagator-jaeger: pytest {toxinidir}/propagator/opentelemetry-propagator-jaeger/tests {posargs}
lint-opentelemetry-propagator-jaeger: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/propagator/opentelemetry-propagator-jaeger
lint-opentelemetry-propagator-jaeger: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/propagator/opentelemetry-propagator-jaeger
lint-opentelemetry-propagator-jaeger: flake8 --config {toxinidir}/.flake8 {toxinidir}/propagator/opentelemetry-propagator-jaeger
lint-opentelemetry-propagator-jaeger: sh -c "cd propagator && pylint --rcfile ../.pylintrc {toxinidir}/propagator/opentelemetry-propagator-jaeger"

test-opentelemetry-test-utils: pytest {toxinidir}/tests/opentelemetry-test-utils/tests {posargs}
lint-opentelemetry-test-utils: black --diff --check --config {toxinidir}/pyproject.toml {toxinidir}/tests/opentelemetry-test-utils
lint-opentelemetry-test-utils: isort --diff --check-only --settings-path {toxinidir}/.isort.cfg {toxinidir}/tests/opentelemetry-test-utils
lint-opentelemetry-test-utils: flake8 --config {toxinidir}/.flake8 {toxinidir}/tests/opentelemetry-test-utils
lint-opentelemetry-test-utils: sh -c "cd tests && pylint --rcfile ../.pylintrc {toxinidir}/tests/opentelemetry-test-utils"

coverage: {toxinidir}/scripts/coverage.sh
Expand All @@ -329,17 +273,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 +394,11 @@ commands_pre =
commands =
pyright --version
pyright

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

0 comments on commit 7a6052e

Please sign in to comment.