Skip to content

chore: upgrade Ruff configuration and reformat codebase#861

Open
pvital wants to merge 22 commits intomainfrom
ruff_update
Open

chore: upgrade Ruff configuration and reformat codebase#861
pvital wants to merge 22 commits intomainfrom
ruff_update

Conversation

@pvital
Copy link
Copy Markdown
Member

@pvital pvital commented Apr 7, 2026

This PR modernizes the repository’s Ruff setup and applies the resulting formatting and lint cleanup across the codebase and tests.

  • Upgraded pre-commit Ruff integration in .pre-commit-config.yaml
    • bumped Ruff from v0.7.0 to v0.15.9
    • switched the lint hook from ruff to ruff-check
    • extended formatting hook coverage to Python and Markdown files
  • Added Ruff configuration to pyproject.toml
    • set Python target version to 3.9
    • configured repository exclusions for non-source directories
    • enabled preview mode and concise output
    • defined lint rule selection for style, import ordering, simplification, string modernizations, and copyright checks
  • Applied repository-wide Ruff-driven cleanup across source and test files
    • normalized import ordering
    • reformatted multiline logging, context managers, assertions, and long calls
    • simplified membership checks, such as key in dict instead of key in dict.keys()
    • removed unused imports in several tests
    • cleaned whitespace and newline issues
  • Fixed SonarQube failed conditions on new code
    • Deleted src/instana/util/gunicorn.py since the code is duplicated in running_in_gunicorn() function from src/instana/log.py.
    • Adapted code to import running_in_gunicorn() from src/instana/log.py.
    • Add tests for running_in_gunicorn() to increase the coverage on new code.

@pvital pvital self-assigned this Apr 7, 2026
@pvital pvital added the chore label Apr 7, 2026
@pvital pvital changed the title Ruff update chore: upgrade Ruff configuration and reformat codebase Apr 7, 2026
pvital added 22 commits April 7, 2026 14:38
Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
used ruff (pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations, like unused imports.
- isort-compatible import sorting.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
…ormat.

Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
…ring join.

Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
….keys()`.

Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
…ead of `try`-`except`-`pass`.

Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
…aders.get(<index>, None)`.

Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
…le contexts instead of nested `with` statements.

Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
…sted `if` statements.

Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
…directly.

Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
…e`-block.

Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
…se True`.

Used Ruff (vscode and pre-commit) to:
- Black-compatible code formatting.
- fix all auto-fixable violations.
- isort-compatible import sorting.
- flake8-simplify manual fixes.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
- Deleted `src/instana/util/gunicorn.py` since the code is duplicated in `running_in_gunicorn()` function from `src/instana/log.py`.
- Adapted code to import `running_in_gunicorn()` from `src/instana/log.py`.
- Add tests for `running_in_gunicorn()` to increase the coverage on new code.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 7, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
3.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@pvital pvital marked this pull request as ready for review April 7, 2026 20:14
@pvital pvital requested a review from a team as a code owner April 7, 2026 20:14
if tracing_disable_config := config["tracing"].get("disable", None):
return parse_span_disabling(tracing_disable_config)
if "tracing" in config and (
tracing_disable_config := config["tracing"].get("disable", None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tracing_disable_config := config["tracing"].get("disable", None)
tracing_disable_config := config["tracing"].get("disable")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting to see how Ruff did not catch this SIM910. It should be part of commit 08083c5.

Comment on lines +58 to +68
return bool(
rule_value == "*"
or match_type == "strict"
and span_value == rule_value
or match_type == "contains"
and rule_value in span_value
or match_type == "startswith"
and span_value.startswith(rule_value)
or match_type == "endswith"
and span_value.endswith(rule_value)
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a slight adjustment for better readability.
Also I think we don't need the bool() wrapper here, as all those comparison operators already return boolean values.

Suggested change
return bool(
rule_value == "*"
or match_type == "strict"
and span_value == rule_value
or match_type == "contains"
and rule_value in span_value
or match_type == "startswith"
and span_value.startswith(rule_value)
or match_type == "endswith"
and span_value.endswith(rule_value)
)
return (
rule_value == "*" or
(match_type == "strict" and span_value == rule_value) or
(match_type == "contains" and rule_value in span_value) or
(match_type == "startswith" and span_value.startswith(rule_value)) or
(match_type == "endswith" and span_value.endswith(rule_value))
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to apply your suggestion, but probably this will be re-formatted back to the original by Ruff when running the pre-commit rule. Let's see.

import uvicorn
from ...helpers import testenv
from instana.log import logger
from instana.log import logger as logger
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Will remove this line

Comment on lines +7 to +10

from ....log import logger
from ..base import BaseHelper
from ....util import DictionaryOfStan
from ..base import BaseHelper
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change these relative imports to absolute imports?

Copy link
Copy Markdown
Contributor

@GSVarsha GSVarsha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants