CircleCI orb for Python code quality automation. Provides formatting, linting, static analysis, and automated PR reviews with slash command support.
- π¨ Auto-formatting with Black and isort
- π Comprehensive linting with pylint, flake8, mypy, and bandit
- π€ Automated PR reviews with Danger
- π Smart rebasing with conflict resolution
- β‘ Slash command support for interactive PR workflows
version: 2.1
orbs:
python-quality: branchbutler-labs/python-quality@1.0.0
workflows:
code-quality:
jobs:
- python-quality/code-quality:
context: branchbutlerversion: 2.1
orbs:
python-quality: branchbutler-labs/python-quality@1.0.0
workflows:
pr-checks:
jobs:
- python-quality/code-quality:
auto-commit: true
filters:
branches:
ignore: main
- python-quality/pr-review:
requires:
- python-quality/code-qualityFormat Python code with Black and isort.
Parameters:
line-length(integer, default:100) - Maximum line lengthauto-commit(boolean, default:true) - Auto-commit changespaths(string, default:".") - Paths to formatisort-profile(string, default:"black") - isort profile
Example:
steps:
- python-quality/format:
line-length: 120
auto-commit: trueRun Python linters and static analysis.
Parameters:
fail-on-error(boolean, default:true) - Fail on linting errorsrun-pylint(boolean, default:true) - Run pylintrun-flake8(boolean, default:true) - Run flake8run-mypy(boolean, default:true) - Run mypyrun-bandit(boolean, default:true) - Run banditmax-line-length(integer, default:100) - Maximum line lengthpaths(string, default:".") - Paths to lint
Example:
steps:
- python-quality/lint:
fail-on-error: false
run-mypy: trueRun Danger for automated PR review.
Parameters:
github-token(env_var_name, default:GITHUB_TOKEN) - GitHub token variablemin-description-length(integer, default:10) - Minimum PR description lengthmax-file-size(integer, default:500000) - Maximum file size in bytes before warningfail-on-warnings(boolean, default:false) - Fail on warnings
Example:
steps:
- python-quality/danger:
min-description-length: 20
fail-on-warnings: trueRebase PR branch onto target branch.
Parameters:
base-branch(string, default:"main") - Base branch to rebase ontoauto-resolve-conflicts(boolean, default:false) - Auto-resolve conflictsforce-push(boolean, default:true) - Force push after rebase
Example:
steps:
- python-quality/rebase:
base-branch: "develop"
auto-resolve-conflicts: trueRun full code quality suite with formatting and linting.
Parameters:
checkout-code(boolean, default:true) - Checkout repositoryrun-format(boolean, default:true) - Run formattingrun-lint(boolean, default:true) - Run lintingline-length(integer, default:100) - Maximum line lengthauto-commit(boolean, default:false) - Auto-commit changes
Example:
jobs:
- python-quality/code-quality:
line-length: 100
auto-commit: true
context: branchbutlerAutomated PR review with Danger.
Parameters:
min-description-length(integer, default:10) - Minimum PR description lengthmax-file-size(integer, default:500000) - Maximum file size in bytes before warningfail-on-warnings(boolean, default:false) - Fail on warnings
Example:
jobs:
- python-quality/pr-review:
min-description-length: 20
fail-on-warnings: trueUse these commands in PR comments to trigger actions:
Auto-format code with Black and isort.
/format
Run comprehensive linting.
/lint
Rebase PR branch onto target.
/rebase
Run automated PR review.
/danger
Note: Slash commands require webhook setup. See slash command documentation.
Python executor with pre-installed tools.
Parameters:
tag(string, default:"3.11") - Python versionresource-class(enum, default:"medium") - Resource class
Example:
executor:
name: python-quality/python
tag: "3.10"
resource-class: "large"version: 2.1
orbs:
python-quality: branchbutler-labs/python-quality@1.0.0
workflows:
format:
jobs:
- python-quality/code-quality:
run-format: true
run-lint: false
auto-commit: trueversion: 2.1
orbs:
python-quality: branchbutler-labs/python-quality@1.0.0
workflows:
lint:
jobs:
- python-quality/code-quality:
run-format: false
run-lint: trueversion: 2.1
orbs:
python-quality: branchbutler-labs/python-quality@1.0.0
jobs:
my-custom-job:
executor: python-quality/python
steps:
- checkout
- python-quality/format:
line-length: 120
- python-quality/lint:
run-mypy: true
fail-on-error: false
- run:
name: Run tests
command: pytest
workflows:
main:
jobs:
- my-custom-jobversion: 2.1
orbs:
python-quality: branchbutler-labs/python-quality@1.0.0
workflows:
pr-automation:
jobs:
# Format and commit on PRs
- python-quality/code-quality:
name: format-code
run-format: true
run-lint: false
auto-commit: true
filters:
branches:
ignore: main
# Lint after formatting
- python-quality/code-quality:
name: lint-code
run-format: false
run-lint: true
requires:
- format-code
filters:
branches:
ignore: main
# Run automated PR review
- python-quality/pr-review:
requires:
- lint-code
filters:
branches:
ignore: mainYour repository should have:
- Python project with Python files (
.py) - Optional:
requirements.txtand/orrequirements-dev.txt - Optional:
.pylintrc,.flake8,mypy.inifor custom linter config
GITHUB_TOKEN- GitHub personal access token withreposcope
CIRCLECI_TOKEN- For slash command integration
- CircleCI CLI:
brew install circleci - CircleCI account with orb publishing enabled
circleci orb validate src/@orb.ymlcircleci orb pack src > orb.ymlcircleci orb publish orb.yml branchbutler-labs/python-quality@dev:firstcircleci orb publish promote branchbutler-labs/python-quality@dev:first patchContributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Submit a pull request
- Documentation: CircleCI Orb Registry
- Issues: GitHub Issues
- Website: Branch Butler
MIT License - See LICENSE file for details.
Part of the Branch Butler family of DevOps automation tools.
π branchbutler.com | π GitHub