Skip to content

Commit

Permalink
chore: replace black, flake8 and isort with ruff and ruff-format (#30)
Browse files Browse the repository at this point in the history
Signed-off-by: gruebel <anton.gruebel@gmail.com>
  • Loading branch information
gruebel authored Jan 9, 2024
1 parent 684a90a commit c5584ee
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 141 deletions.
41 changes: 16 additions & 25 deletions .github/workflows/pullrequest.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
# separate terms of service, privacy policy, and support
# documentation.

name: PR
name: "Build, lint, and test"

on:
push:
branches:
- main
pull_request:
branches: [master, main]
branches:
- main

permissions:
contents: read
Expand All @@ -17,33 +21,26 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
container: ["python:3.8", "python:3.9", "python:3.10", "python:3.11"]
container:
image: ${{ matrix.container }}
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: bufbuild/buf-setup-action@v1.27.1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
github_token: ${{ github.token }}
python-version: ${{ matrix.python-version }}
cache: "pip"

- name: Cache virtualenvironment
uses: actions/cache@v2
- uses: bufbuild/buf-setup-action@v1.27.1
with:
path: ~/.venv
key: ${{ hashFiles('requirements.txt') }}
github_token: ${{ github.token }}

- name: Upgrade pip
run: pip install --upgrade pip

- name: Create and activate Virtualenv
run: |
[ ! -d ".venv" ] && python -m venv .venv
. .venv/bin/activate
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
Expand All @@ -52,14 +49,8 @@ jobs:
- name: Install dependencies
run: pip install -r requirements.txt

- name: Run black formatter check
run: black --check .

- name: Run flake8 formatter check
run: flake8 .

- name: Run isort formatter check
run: isort .
- name: Run pre-commit
uses: pre-commit/action@v3.0.0

- name: Generate flagd protobuf files
run: |
Expand Down
84 changes: 0 additions & 84 deletions .github/workflows/merge.yml

This file was deleted.

27 changes: 6 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
default_stages: [commit]
repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
exclude: ^openfeature/contrib/providers/flagd/proto/(.*)

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
language_version: python3.9
- id: ruff
- id: ruff-format
exclude: ^openfeature/contrib/providers/flagd/proto/(.*)

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.5.0
hooks:
- id: check-toml
- id: check-yaml
- id: trailing-whitespace
- id: check-merge-conflict
- id: debug-statements

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
["flake8-print", "flake8-builtins", "flake8-functions==0.0.4"]
exclude: ^openfeature/contrib/providers/flagd/proto/(.*)
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ test: venv ## Run pytest on the tests/ directory
$(VENV_ACTIVATE); pytest tests/

.PHONY: lint
lint: venv ## Check code with flake8 and black
$(VENV_ACTIVATE); flake8 .
$(VENV_ACTIVATE); black --check .
lint: venv ## Check code with ruff
$(VENV_ACTIVATE); pre-commit run -a

.PHONY: format
format: venv ## Format code with black
$(VENV_ACTIVATE); black .
$(VENV_ACTIVATE); pre-commit run -a ruff-format
61 changes: 57 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,64 @@ dependencies = []
requires-python = ">=3.8"

[project.optional-dependencies]
dev = ["black", "flake8", "isort", "pip-tools", "pytest", "pre-commit"]
dev = ["pip-tools", "pytest", "pre-commit"]

[project.urls]
Homepage = "https://github.com/open-feature/python-sdk-contrib"

[tool.isort]
profile = "black"
multi_line_output = 3
[tool.ruff]
exclude = [
".git",
".venv",
"__pycache__",
"venv",
"openfeature/contrib/providers/flagd/proto/*"
]
target-version = "py38"

[tool.ruff.lint]
select = [
"A",
"B",
"C4",
"C90",
"E",
"F",
"FLY",
"FURB",
"I",
"LOG",
"N",
"PERF",
"PGH",
"PLC",
"PLR0913",
"PLR0915",
"RUF",
"S",
"SIM",
"T10",
"T20",
"UP",
"W",
"YTT",
]
ignore = [
"E501", # the formatter will handle any too long line
# all following rules will be removed in the next PR
"I001",
"B018",
"B904",
]
preview = true

[tool.ruff.lint.per-file-ignores]
"tests/**/*" = ["S101"]

[tool.ruff.lint.pylint]
max-args = 6
max-statements = 30

[tool.ruff.lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
requests==2.31.0
opentelemetry-sdk==1.20.0
openfeature-sdk==0.3.1
pylint==3.0.0
pytest==7.4.2
pytest-mock==3.11.1
black==23.9.1
pre-commit==3.4.0
flake8==6.1.0
coverage==7.3.2
grpcio==1.59.0
grpcio-tools==1.59.0

0 comments on commit c5584ee

Please sign in to comment.