This only works on setups with a virtual environment at a known consistent location. This way of installing is a workaround until an official solution is available. See astral-sh/ruff#12352.
Alternatively, you can simply copy the ruff.toml skeleton file into the root of your python project or root of your monorepo.
required-version and project.dependencies are already set so you shouldn't be able to accidentally use an incompatible Ruff version.
Although there was an issue before 0.14.11 where config parsing may fail before required-version tells you about it: astral-sh/ruff#19922
To use, simply extend your Ruff configuration with the one from this project.
# ruff.toml
extend = ".venv/Beslogic-Ruff-Config/ruff.toml"GitHub action example:
jobs:
Ruff:
runs-on: ubuntu-latest
env:
RUFF_OUTPUT_FORMAT: github
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v7
with:
activate-environment: true
- run: uv sync --locked --only-group=ruff
- run: ruff check
- run: ruff format --check
# Check format even if the the previous step failed
if: ${{ !cancelled() }}Where the ruff Dependency Group is configured as such in your pyproject.toml:
[dependency-groups]
ruff = [
"beslogic-ruff-config",
"ruff", # Version should come from beslogic-ruff-config and the lock file
]
dev = [
{include-group = "ruff"},
]If a rule doesn't seem to fit your need, try to see if it's configurable before disabling it: https://docs.astral.sh/ruff/settings/#lint
| Never use the following settings, unless you really know that you want to overwrite entire config sections |
Instead, always try to use |
| exclude | extend-exclude |
| include | extend-include |
| fixable | extend-fixable |
| per-file-ignores | extend-per-file-ignores |
| select | extend-select |
| safe-fixes | extend-safe-fixes |
| unsafe-fixes | extend-unsafe-fixes |
| flake8-gettext.function-names | flake8-gettext.extend-function-names |
| flake8-import-conventions.aliases | flake8-import-conventions.extend-aliases |
| flake8-self.ignore-names | flake8-self.extend-ignore-names |
| pep8-naming.ignore-names | pep8-naming.extend-ignore-names |
If you end up with additional configuration that you believe should be applied across all projects. Please open a PR to modify these shared configurations instead.
The following are not part of the default config and are good to know about:
- Use extend-exclude if you need to exclude any file from being checked. Usually for auto-generated files that can't fully be autofixed. Although even then we'd recommend using extend-per-file-ignores instead.
- Use lint.explicit-preview-rules = false OR explicitly add a rule to extend-select to use rules and behaviours still in preview.
- If you are writing a library and want to enforce documentation for all public symbols, consider adding D1 rules to extend-select.
- Similarly, if you want to enforce documenting returns, yields and exceptions, ignore: D406 and D407 (as they are incompatible with pydoclint). Then extend-select: DOC201, DOC402 and/or DOC501 to your liking
- missing-copyright-notice (CPY001) isn't enabled because most projects are either private or consider that setting the license project metadata is sufficient.
- The following rules are currently disabled because they shouldn't be blocking, but Ruff doesn't support warnings yet: flake8-fixme (FIX), missing-todo-link (TD003), try-except-in-loop (PERF203)
Below you should replace <rev> with the latest revision/commit to pin the configuration version.
If you want to rely on the uv lockfile instead of using an explicit revision, you can run uv lock --upgrade-package Beslogic-Ruff-Config to update.
See Using in CI
uv add git+https://github.com/Beslogic/Beslogic-Ruff-Config --dev --rev <rev>
Which should add the following to your pyproject.toml:
[dependency-groups]
dev = [
"Beslogic-Ruff-Config",
]
[tool.uv.sources]
Beslogic-Ruff-Config = { git = "https://github.com/Beslogic/Beslogic-Ruff-Config@<rev>" }pip install git+https://github.com/microsoft/python-type-stubs.git@<rev>