Skip to content

ruff ¤

Callable for Ruff.

Functions:

  • check

    Run Ruff on the given files or directories.

  • clean

    Clear any caches in the current directory and any subdirectories.

  • config

    List or describe the available configuration options.

  • format

    Run Ruff formatter on the given files or directories.

  • linter

    List all supported upstream linters.

  • rule

    Explain a rule.

check ¤

check(
    *files: str,
    config: str | None = None,
    fix: bool | None = None,
    show_source: bool | None = None,
    show_fixes: bool | None = None,
    diff: bool | None = None,
    watch: bool | None = None,
    fix_only: bool | None = None,
    output_format: str | None = None,
    statistics: bool | None = None,
    add_noqa: bool | None = None,
    show_files: bool | None = None,
    show_settings: bool | None = None,
    select: list[str] | None = None,
    ignore: list[str] | None = None,
    extend_select: list[str] | None = None,
    per_file_ignores: dict[str, list[str]] | None = None,
    fixable: list[str] | None = None,
    unfixable: list[str] | None = None,
    exclude: list[str] | None = None,
    extend_exclude: list[str] | None = None,
    respect_gitignore: bool | None = None,
    force_exclude: bool | None = None,
    no_cache: bool | None = None,
    isolated: bool | None = None,
    cache_dir: str | None = None,
    stdin_filename: str | None = None,
    exit_zero: bool | None = None,
    exit_non_zero_on_fix: bool | None = None,
    verbose: bool = False,
    quiet: bool = False,
    silent: bool = False
) -> int

Run Ruff on the given files or directories.

Parameters:

  • fix (bool | None, default: None ) –

    Attempt to automatically fix lint violations

  • config (str | None, default: None ) –

    Path to the pyproject.toml or ruff.toml file to use for configuration

  • show_source (bool | None, default: None ) –

    Show violations with source code

  • show_fixes (bool | None, default: None ) –

    Show an enumeration of all autofixed lint violations

  • diff (bool | None, default: None ) –

    Avoid writing any fixed files back; instead, output a diff for each changed file to stdout

  • watch (bool | None, default: None ) –

    Run in watch mode by re-running whenever files change

  • fix_only (bool | None, default: None ) –

    Fix any fixable lint violations, but don't report on leftover violations. Implies --fix

  • output_format (str | None, default: None ) –

    Output serialization format for violations [env: RUFF_FORMAT=] [possible values: text, json, junit, grouped, github, gitlab, pylint]

  • statistics (bool | None, default: None ) –

    Show counts for every rule with at least one violation

  • add_noqa (bool | None, default: None ) –

    Enable automatic additions of noqa directives to failing lines

  • show_files (bool | None, default: None ) –

    See the files Ruff will be run against with the current settings

  • show_settings (bool | None, default: None ) –

    See the settings Ruff will use to lint a given Python file

  • select (list[str] | None, default: None ) –

    Comma-separated list of rule codes to enable (or ALL, to enable all rules)

  • ignore (list[str] | None, default: None ) –

    Comma-separated list of rule codes to disable

  • extend_select (list[str] | None, default: None ) –

    Like --select, but adds additional rule codes on top of the selected ones

  • per_file_ignores (dict[str, list[str]] | None, default: None ) –

    List of mappings from file pattern to code to exclude

  • fixable (list[str] | None, default: None ) –

    List of rule codes to treat as eligible for autofix. Only applicable when autofix itself is enabled (e.g., via --fix)

  • unfixable (list[str] | None, default: None ) –

    List of rule codes to treat as ineligible for autofix. Only applicable when autofix itself is enabled (e.g., via --fix)

  • exclude (list[str] | None, default: None ) –

    List of paths, used to omit files and/or directories from analysis

  • extend_exclude (list[str] | None, default: None ) –

    Like --exclude, but adds additional files and directories on top of those already excluded

  • respect_gitignore (bool | None, default: None ) –

    Respect file exclusions via .gitignore and other standard ignore files

  • force_exclude (bool | None, default: None ) –

    Enforce exclusions, even for paths passed to Ruff directly on the command-line

  • no_cache (bool | None, default: None ) –

    Disable cache reads

  • isolated (bool | None, default: None ) –

    Ignore all configuration files

  • cache_dir (str | None, default: None ) –

    Path to the cache directory [env: RUFF_CACHE_DIR=]

  • stdin_filename (str | None, default: None ) –

    The name of the file when passing it through stdin

  • exit_zero (bool | None, default: None ) –

    Exit with status code "0", even upon detecting lint violations

  • exit_non_zero_on_fix (bool | None, default: None ) –

    Exit with a non-zero status code if any files were modified via autofix, even if no lint violations remain

  • verbose (bool, default: False ) –

    Enable verbose logging.

  • quiet (bool, default: False ) –

    Print lint violations, but nothing else.

  • silent (bool, default: False ) –

    Disable all logging (but still exit with status code "1" upon detecting lint violations).

Source code in src/duty/callables/ruff.py
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
@lazy(name="ruff.check")
def check(
    *files: str,
    config: str | None = None,
    fix: bool | None = None,
    show_source: bool | None = None,
    show_fixes: bool | None = None,
    diff: bool | None = None,
    watch: bool | None = None,
    fix_only: bool | None = None,
    output_format: str | None = None,
    statistics: bool | None = None,
    add_noqa: bool | None = None,
    show_files: bool | None = None,
    show_settings: bool | None = None,
    select: list[str] | None = None,
    ignore: list[str] | None = None,
    extend_select: list[str] | None = None,
    per_file_ignores: dict[str, list[str]] | None = None,
    fixable: list[str] | None = None,
    unfixable: list[str] | None = None,
    exclude: list[str] | None = None,
    extend_exclude: list[str] | None = None,
    respect_gitignore: bool | None = None,
    force_exclude: bool | None = None,
    no_cache: bool | None = None,
    isolated: bool | None = None,
    cache_dir: str | None = None,
    stdin_filename: str | None = None,
    exit_zero: bool | None = None,
    exit_non_zero_on_fix: bool | None = None,
    verbose: bool = False,
    quiet: bool = False,
    silent: bool = False,
) -> int:
    """Run Ruff on the given files or directories.

    Parameters:
        fix: Attempt to automatically fix lint violations
        config: Path to the `pyproject.toml` or `ruff.toml` file to use for configuration
        show_source: Show violations with source code
        show_fixes: Show an enumeration of all autofixed lint violations
        diff: Avoid writing any fixed files back; instead, output a diff for each changed file to stdout
        watch: Run in watch mode by re-running whenever files change
        fix_only: Fix any fixable lint violations, but don't report on leftover violations. Implies `--fix`
        output_format: Output serialization format for violations [env: RUFF_FORMAT=] [possible values: text, json, junit, grouped, github, gitlab, pylint]
        statistics: Show counts for every rule with at least one violation
        add_noqa: Enable automatic additions of `noqa` directives to failing lines
        show_files: See the files Ruff will be run against with the current settings
        show_settings: See the settings Ruff will use to lint a given Python file
        select: Comma-separated list of rule codes to enable (or ALL, to enable all rules)
        ignore: Comma-separated list of rule codes to disable
        extend_select: Like --select, but adds additional rule codes on top of the selected ones
        per_file_ignores: List of mappings from file pattern to code to exclude
        fixable: List of rule codes to treat as eligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`)
        unfixable: List of rule codes to treat as ineligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`)
        exclude: List of paths, used to omit files and/or directories from analysis
        extend_exclude: Like --exclude, but adds additional files and directories on top of those already excluded
        respect_gitignore: Respect file exclusions via `.gitignore` and other standard ignore files
        force_exclude: Enforce exclusions, even for paths passed to Ruff directly on the command-line
        no_cache: Disable cache reads
        isolated: Ignore all configuration files
        cache_dir: Path to the cache directory [env: RUFF_CACHE_DIR=]
        stdin_filename: The name of the file when passing it through stdin
        exit_zero: Exit with status code "0", even upon detecting lint violations
        exit_non_zero_on_fix: Exit with a non-zero status code if any files were modified via autofix, even if no lint violations remain
        verbose: Enable verbose logging.
        quiet: Print lint violations, but nothing else.
        silent: Disable all logging (but still exit with status code "1" upon detecting lint violations).
    """
    cli_args = list(files)

    if fix:
        cli_args.append("--fix")

    if show_source:
        cli_args.append("--show-source")

    if show_fixes:
        cli_args.append("--show-fixes")

    if diff:
        cli_args.append("--diff")

    if watch:
        cli_args.append("--watch")

    if fix_only:
        cli_args.append("--fix-only")

    if output_format:
        cli_args.append("--format")
        cli_args.append(output_format)

    if config:
        cli_args.append("--config")
        cli_args.append(config)

    if statistics:
        cli_args.append("--statistics")

    if add_noqa:
        cli_args.append("--add-noqa")

    if show_files:
        cli_args.append("--show-files")

    if show_settings:
        cli_args.append("--show-settings")

    if select:
        cli_args.append("--select")
        cli_args.append(",".join(select))

    if ignore:
        cli_args.append("--ignore")
        cli_args.append(",".join(ignore))

    if extend_select:
        cli_args.append("--extend-select")
        cli_args.append(",".join(extend_select))

    if per_file_ignores:
        cli_args.append("--per-file-ignores")
        cli_args.append(
            " ".join(f"{path}:{','.join(codes)}" for path, codes in per_file_ignores.items()),
        )

    if fixable:
        cli_args.append("--fixable")
        cli_args.append(",".join(fixable))

    if unfixable:
        cli_args.append("--unfixable")
        cli_args.append(",".join(unfixable))

    if exclude:
        cli_args.append("--exclude")
        cli_args.append(",".join(exclude))

    if extend_exclude:
        cli_args.append("--extend-exclude")
        cli_args.append(",".join(extend_exclude))

    if respect_gitignore:
        cli_args.append("--respect-gitignore")

    if force_exclude:
        cli_args.append("--force-exclude")

    if no_cache:
        cli_args.append("--no-cache")

    if isolated:
        cli_args.append("--isolated")

    if cache_dir:
        cli_args.append("--cache-dir")
        cli_args.append(cache_dir)

    if stdin_filename:
        cli_args.append("--stdin-filename")
        cli_args.append(stdin_filename)

    if exit_zero:
        cli_args.append("--exit-zero")

    if exit_non_zero_on_fix:
        cli_args.append("--exit-non-zero-on-fix")

    return _run("check", *cli_args, verbose=verbose, quiet=quiet, silent=silent)

clean ¤

clean(
    *,
    verbose: bool = False,
    quiet: bool = False,
    silent: bool = False
) -> int

Clear any caches in the current directory and any subdirectories.

Parameters:

  • verbose (bool, default: False ) –

    Enable verbose logging.

  • quiet (bool, default: False ) –

    Print lint violations, but nothing else.

  • silent (bool, default: False ) –

    Disable all logging (but still exit with status code "1" upon detecting lint violations).

Source code in src/duty/callables/ruff.py
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
@lazy(name="ruff.clean")
def clean(
    *,
    verbose: bool = False,
    quiet: bool = False,
    silent: bool = False,
) -> int:
    """Clear any caches in the current directory and any subdirectories.

    Parameters:
        verbose: Enable verbose logging.
        quiet: Print lint violations, but nothing else.
        silent: Disable all logging (but still exit with status code "1" upon detecting lint violations).
    """
    return _run("clean", verbose=verbose, quiet=quiet, silent=silent)

config ¤

config(
    *,
    verbose: bool = False,
    quiet: bool = False,
    silent: bool = False
) -> int

List or describe the available configuration options.

Parameters:

  • verbose (bool, default: False ) –

    Enable verbose logging.

  • quiet (bool, default: False ) –

    Print lint violations, but nothing else.

  • silent (bool, default: False ) –

    Disable all logging (but still exit with status code "1" upon detecting lint violations).

Source code in src/duty/callables/ruff.py
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
@lazy(name="ruff.config")
def config(
    *,
    verbose: bool = False,
    quiet: bool = False,
    silent: bool = False,
) -> int:
    """List or describe the available configuration options.

    Parameters:
        verbose: Enable verbose logging.
        quiet: Print lint violations, but nothing else.
        silent: Disable all logging (but still exit with status code "1" upon detecting lint violations).
    """
    return _run("config", verbose=verbose, quiet=quiet, silent=silent)

format ¤

format(
    *files: str,
    config: str | None = None,
    check: bool | None = None,
    diff: bool | None = None,
    target_version: str | None = None,
    preview: bool | None = None,
    exclude: list[str] | None = None,
    extend_exclude: list[str] | None = None,
    respect_gitignore: bool | None = None,
    force_exclude: bool | None = None,
    no_cache: bool | None = None,
    isolated: bool | None = None,
    cache_dir: str | None = None,
    stdin_filename: str | None = None,
    verbose: bool = False,
    quiet: bool = False,
    silent: bool = False
) -> int

Run Ruff formatter on the given files or directories.

Parameters:

  • check (bool | None, default: None ) –

    Avoid writing any formatted files back; instead, exit with a non-zero status code if any files would have been modified, and zero otherwise

  • config (str | None, default: None ) –

    Path to the pyproject.toml or ruff.toml file to use for configuration

  • diff (bool | None, default: None ) –

    Avoid writing any fixed files back; instead, output a diff for each changed file to stdout

  • target_version (str | None, default: None ) –

    The minimum Python version that should be supported [possible values: py37, py38, py39, py310, py311, py312]

  • preview (bool | None, default: None ) –

    Enable preview mode; enables unstable formatting

  • exclude (list[str] | None, default: None ) –

    List of paths, used to omit files and/or directories from analysis

  • extend_exclude (list[str] | None, default: None ) –

    Like --exclude, but adds additional files and directories on top of those already excluded

  • respect_gitignore (bool | None, default: None ) –

    Respect file exclusions via .gitignore and other standard ignore files

  • force_exclude (bool | None, default: None ) –

    Enforce exclusions, even for paths passed to Ruff directly on the command-line

  • no_cache (bool | None, default: None ) –

    Disable cache reads

  • isolated (bool | None, default: None ) –

    Ignore all configuration files

  • cache_dir (str | None, default: None ) –

    Path to the cache directory [env: RUFF_CACHE_DIR=]

  • stdin_filename (str | None, default: None ) –

    The name of the file when passing it through stdin

  • verbose (bool, default: False ) –

    Enable verbose logging.

  • quiet (bool, default: False ) –

    Print lint violations, but nothing else.

  • silent (bool, default: False ) –

    Disable all logging (but still exit with status code "1" upon detecting lint violations).

Source code in src/duty/callables/ruff.py
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
@lazy(name="ruff.format")
def format(
    *files: str,
    config: str | None = None,
    check: bool | None = None,
    diff: bool | None = None,
    target_version: str | None = None,
    preview: bool | None = None,
    exclude: list[str] | None = None,
    extend_exclude: list[str] | None = None,
    respect_gitignore: bool | None = None,
    force_exclude: bool | None = None,
    no_cache: bool | None = None,
    isolated: bool | None = None,
    cache_dir: str | None = None,
    stdin_filename: str | None = None,
    verbose: bool = False,
    quiet: bool = False,
    silent: bool = False,
) -> int:
    """Run Ruff formatter on the given files or directories.

    Parameters:
        check: Avoid writing any formatted files back; instead, exit with a non-zero status code if any files would have been modified, and zero otherwise
        config: Path to the `pyproject.toml` or `ruff.toml` file to use for configuration
        diff: Avoid writing any fixed files back; instead, output a diff for each changed file to stdout
        target_version: The minimum Python version that should be supported [possible values: py37, py38, py39, py310, py311, py312]
        preview: Enable preview mode; enables unstable formatting
        exclude: List of paths, used to omit files and/or directories from analysis
        extend_exclude: Like --exclude, but adds additional files and directories on top of those already excluded
        respect_gitignore: Respect file exclusions via `.gitignore` and other standard ignore files
        force_exclude: Enforce exclusions, even for paths passed to Ruff directly on the command-line
        no_cache: Disable cache reads
        isolated: Ignore all configuration files
        cache_dir: Path to the cache directory [env: RUFF_CACHE_DIR=]
        stdin_filename: The name of the file when passing it through stdin
        verbose: Enable verbose logging.
        quiet: Print lint violations, but nothing else.
        silent: Disable all logging (but still exit with status code "1" upon detecting lint violations).
    """
    cli_args = list(files)

    if check:
        cli_args.append("--check")

    if diff:
        cli_args.append("--diff")

    if config:
        cli_args.append("--config")
        cli_args.append(config)

    if target_version:
        cli_args.append("--target-version")
        cli_args.append(target_version)

    if preview:
        cli_args.append("--preview")

    if exclude:
        cli_args.append("--exclude")
        cli_args.append(",".join(exclude))

    if extend_exclude:
        cli_args.append("--extend-exclude")
        cli_args.append(",".join(extend_exclude))

    if respect_gitignore:
        cli_args.append("--respect-gitignore")

    if force_exclude:
        cli_args.append("--force-exclude")

    if no_cache:
        cli_args.append("--no-cache")

    if isolated:
        cli_args.append("--isolated")

    if cache_dir:
        cli_args.append("--cache-dir")
        cli_args.append(cache_dir)

    if stdin_filename:
        cli_args.append("--stdin-filename")
        cli_args.append(stdin_filename)

    return _run("format", *cli_args, verbose=verbose, quiet=quiet, silent=silent)

linter ¤

linter(
    *,
    output_format: str | None = None,
    verbose: bool = False,
    quiet: bool = False,
    silent: bool = False
) -> int

List all supported upstream linters.

Parameters:

  • output_format (str | None, default: None ) –

    Output format [default: pretty] [possible values: text, json, pretty].

  • verbose (bool, default: False ) –

    Enable verbose logging.

  • quiet (bool, default: False ) –

    Print lint violations, but nothing else.

  • silent (bool, default: False ) –

    Disable all logging (but still exit with status code "1" upon detecting lint violations).

Source code in src/duty/callables/ruff.py
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
@lazy(name="ruff.linter")
def linter(
    *,
    output_format: str | None = None,
    verbose: bool = False,
    quiet: bool = False,
    silent: bool = False,
) -> int:
    """List all supported upstream linters.

    Parameters:
        output_format: Output format [default: pretty] [possible values: text, json, pretty].
        verbose: Enable verbose logging.
        quiet: Print lint violations, but nothing else.
        silent: Disable all logging (but still exit with status code "1" upon detecting lint violations).
    """
    cli_args = []

    if output_format:
        cli_args.append("--format")
        cli_args.append(output_format)

    return _run("linter", *cli_args, verbose=verbose, quiet=quiet, silent=silent)

rule ¤

rule(
    *,
    output_format: str | None = None,
    verbose: bool = False,
    quiet: bool = False,
    silent: bool = False
) -> int

Explain a rule.

Parameters:

  • output_format (str | None, default: None ) –

    Output format (default: pretty, possible values: text, json, pretty).

  • verbose (bool, default: False ) –

    Enable verbose logging.

  • quiet (bool, default: False ) –

    Print lint violations, but nothing else.

  • silent (bool, default: False ) –

    Disable all logging (but still exit with status code "1" upon detecting lint violations).

Source code in src/duty/callables/ruff.py
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
@lazy(name="ruff.rule")
def rule(
    *,
    output_format: str | None = None,
    verbose: bool = False,
    quiet: bool = False,
    silent: bool = False,
) -> int:
    """Explain a rule.

    Parameters:
        output_format: Output format (default: pretty, possible values: text, json, pretty).
        verbose: Enable verbose logging.
        quiet: Print lint violations, but nothing else.
        silent: Disable all logging (but still exit with status code "1" upon detecting lint violations).
    """
    cli_args = []

    if output_format:
        cli_args.append("--format")
        cli_args.append(output_format)

    return _run("rule", *cli_args, verbose=verbose, quiet=quiet, silent=silent)