Skip to content

Sourcery configuration

Nick Thapen edited this page Jun 10, 2021 · 19 revisions

The Sourcery configuration file

Sourcery reads configuration settings from .sourcery.yaml in the project directory.

The config file uses YAML syntax. If you are new to YAML see "Learn YAML in 5 minutes".

Default values

Here are the default settings that will be used if the config file doesn't exist, or if a setting isn't included in the config file:

ignore: []

refactor:
  skip: []

metrics:
  quality_threshold: 25.0

clone_detection:
  min_lines: 3
  min_duplicates: 2
  identical_clones_only: false

github:
  labels: []
  ignore_labels: [sourcery-ignore]
  request_review: author
  sourcery_branch: sourcery/{base_branch}

Sourcery options

These are general settings that apply both to editor plugins and the GitHub Bot:

Refactor options

These change how refactoring works and apply to editor plugins and the GitHub Bot:

Metrics options

These configure how code metrics are displayed in the editor plugins.

Clone detection options

These configure the clone detection tool in the editor plugins.

GitHub options

These apply just to the GitHub Bot:

ignore

Paths that Sourcery will ignore and won't be refactored.

The GitHub Bot always ignores .github/workflows/* as the workflows folder cannot be updated by bots.

ignore: 
  - data/*
  - .venv/*
  - '*_test.py'  # Note that any strings beginning with * must be quoted

refactor.skip

Refactoring ids to skip. These refactoring ids are displayed in the plugin suggestions and GitHub Bot comments for easy lookup.

These refactorings will never be suggested by Sourcery.

refactor:
  skip:
    - assign-if-exp
    - de-morgan

It is also possible to skip refactorings in the code using skip comments.

metrics.quality_threshold

Sourcery's code quality score is a percentage which shows the code quality of a method. If the metrics are enabled, methods with a score below this threshold will be shown as warnings in the Problems pane.

metrics:
  quality_threshold: 25.0

clone_detection.min_lines

The minimum number of lines each code section must have to be picked up. The minimum value for this is 3.

clone_detection:
  min_lines: 3

clone_detection.min_duplicates

The minimum number of duplicate code sections there must be. The minimum value for this is 2.

clone_detection:
  min_duplicates: 2

clone_detection.identical_clones_only

When this is set only exactly identical sections of duplicate code will be picked up.

clone_detection:
  identical_clones_only: false

github.ignore_labels

Labels to ignore.

PRs with any of these labels will be ignored by Sourcery.

github:
  ignore_labels:
    - sourcery-ignore

github.labels

Add labels to any PRs create by Sourcery.

These can be used to tell other automation to avoid our PRs.

github:
  labels:
    - build-ignore

github.request_review

Request review on created Sourcery PRs

Possible values:

  • author - the author of the original PR or the sender of the refactor request - the default
  • none - nobody
  • owner - the owner of the base repository - this is not valid for organizations
  • username - a specific user
  • org/teamname- a specific team

One value will apply to both origin and forked PRs:

github:                                                                                 
  request_review: owner

Or you can also specify separate values:

github:                                                                                 
  request_review:
    origin: owner
    forked: author

github.sourcery_branch

Name Sourcery Pull Request branches.

This must contain {base_branch} which will be replaced with the branch name on the original Pull Request.

github:
  sourcery_branch: sourcery/{base_branch}