Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RUFF_OUTPUT_FILE environment variable support #10992

Merged
merged 1 commit into from Apr 17, 2024

Conversation

sisp
Copy link
Contributor

@sisp sisp commented Apr 17, 2024

Summary

I've added support for configuring the ruff check output file via the environment variable RUFF_OUTPUT_FILE akin to #1731.

This is super useful when, e.g., generating a GitLab code quality report while running Ruff as a pre-commit hook. Usually, ruff check should print its human-readable output to stdout, but when run through pre-commit in a GitLab CI job it should write its output in gitlab format to a file. So, to override these two settings only during CI, environment variables come handy, and RUFF_OUTPUT_FORMAT already exists but RUFF_OUTPUT_FILE has been missing.

A (simplified) GitLab CI job config for this scenario might look like this:

pre-commit:
  stage: test
  image: python
  variables:
    RUFF_OUTPUT_FILE: gl-code-quality-report.json
    RUFF_OUTPUT_FORMAT: gitlab
  before_script:
    - pip install pre-commit
  script:
    - pre-commit run --all-files --show-diff-on-failure
  artifacts:
    reports:
      codequality: gl-code-quality-report.json

Test Plan

I tested it manually.

Copy link

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@charliermarsh charliermarsh added the configuration Related to settings and configuration label Apr 17, 2024
Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

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

This seems reasonable to me.

@charliermarsh charliermarsh merged commit 518b29a into astral-sh:main Apr 17, 2024
17 checks passed
@sisp sisp deleted the feat/env-ruff-output-file branch April 17, 2024 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Related to settings and configuration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants