Skip to content

Add RUFF_OUTPUT_FILE environment variable support - #10992

Merged
charliermarsh merged 1 commit into
astral-sh:mainfrom
sisp:feat/env-ruff-output-file
Apr 17, 2024
Merged

charliermarsh merged 1 commit into
astral-sh:mainfrom
sisp:feat/env-ruff-output-file

Conversation

@sisp

@sisp sisp commented Apr 17, 2024

Copy link
Copy Markdown
Contributor

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.

@github-actions

Copy link
Copy Markdown
Contributor

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 of Ruff or ty label Apr 17, 2024

@charliermarsh charliermarsh left a comment

Copy link
Copy Markdown
Member

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
@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 of Ruff or ty

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants