sourcery review
¶
With the review
command, you can detect and fix issues in a single file or in your entire project.
It takes only one argument and provides several options.
Usage¶
sourcery review [OPTIONS] [SRC]
Examples¶
Review the current directory:
sourcery review .
Review the core
directory using the Google Python Style Guide:
sourcery review --enable gpsg core
Argument¶
SRC¶
The target file or directory to review.
If SRC
is -
, the command reads the path to review from stdin
.
Options¶
--diff
¶
Type: text Since version: 0.12.11
Run only on changed code returned by a diff
command.
For example: git diff
To review only code that hasn't been committed yet:
sourcery review --diff "git diff" .
To review your changes compared to the main
branch:
sourcery review --diff "git diff main" .
Usages:
- Code review: Detect issues only in code that has changed in the current pull request.
- Working with a legacy codebase: Provide quality standards for new code without getting tons of warnings for the existing code.
- The
--diff
option is recommended when using Sourcery in a pre-commit hook
--enable
¶
Type: text (multiple) Since version: 1.0.0
Only run the specified rule or tag. This option can be used multiple times.
To review your whole repository with the Google Python Style Guide:
sourcery review --enable gpsg .
To review your whole repository only with the import rules of the Google Python Style Guide:
sourcery review --enable gpsg-import .
To check which tests don't adhere to some specific custom rules:
sourcery review --enable my-rule1 --enable my-other-rule tests
Note that if you want to use a set of rules additionally to the default rules, you need to explicitly enable the default rules. For example, to review your repo with the default rules and the Google Python Style Guide:
sourcery review --enable gpsg --enable default .
Usages:
- Review with only high priority rules.
- Use rule packages, like the Google Python Style Guide.
- Config fine-tuning. See which issues a new rule (or group of rules) would detect.
--disable
¶
Type: text (multiple) Since version: 1.0.0
Skip the specified rule or tag. This option can be used multiple times.
To review example.py
but ignore the rules tagged as "warning":
sourcery review --disable warning example.py
To review your whole repository with the Google Python Style Guide but without the docstring rules:
sourcery review --enable gpsg --disable gpsg-docstrings .
Usages:
- Ignore low priority rules.
- Config fine-tuning.
--check
¶
Type: bool
Return exit code 1 if unsolved issues found.
By default, Sourcery returns the exit code 0 if a review has run successfully, even if the review has found several issues.
Usages:
- The
--check
option is recommended when using Sourcery as a quality gate, e.g. in CI
--fix
¶
Type: bool
Apply the changes suggested by Sourcery.
By default, Sourcery only shows suggested improvements, but doesn't overwrite your code. With the --fix
option, Sourcery applies the changes where possible.
Fix all issues Sourcery can fix in the current directory:
sourcery review --fix .
Apply a single rule at all relevant places:
sourcery review --enable add-encoding-param --fix .
Usages:
- Clean up: Fix dozens of issues with a single command.
- With custom rules: migration to a higher version of a library.
--config
¶
Type: file or URL Since version: 0.12.10
Location of the Sourcery YAML config file. Can be a file or URL.
sourcery review --config ~/experimental_architecture_rules.yaml .
Usages:
- Shared custom rules across multiple projects.
- Config fine-tuning: Try out custom rules without adding them to the project's config file.
--csv
¶
Type: bool
Output in CSV format
--verbose
¶
Type: bool
Verbose output with explanation and code snippets. Not recommended if you expect more than 10-15 issues. (Both for readability and performance reasons.)
sourcery review --verbose example.py
--summary
/ --no-summary
¶
Type: bool Since version: 0.13.0
Flag to determine whether to print a summary of the review. Default: true.
Usages:
- The
--no-summary
option is recommended when using Sourcery in a pre-commit hook
--help
¶
Alias: -h
Show the help message and exit.