Skip to content

Commit

Permalink
build: replace isort and flake8 with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
engineervix committed Jun 6, 2023
1 parent 324b226 commit 31280f7
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 76 deletions.
31 changes: 7 additions & 24 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ on:
- "v*"

jobs:
# Runs the isort, black & flake8 linting steps inside the specified containers rather than on the VM host.
# Runs the ruff & black linting steps inside the specified containers rather than on the VM host.
# Because of this the network configuration changes from host based network to a container network.
linter_isort:
linter_ruff:
runs-on: ubuntu-22.04
container: python:3.10-slim-bullseye

Expand All @@ -29,10 +29,10 @@ jobs:

- name: Install Dependencies
run: |
pip install -q isort==5.12.0
- name: isort
pip install -q ruff==0.0.270
- name: ruff
run: |
isort . --check-only --profile black
ruff check --format=github .
linter_black:
runs-on: ubuntu-22.04
Expand All @@ -49,21 +49,6 @@ jobs:
run: |
black . --check
linter_flake8:
runs-on: ubuntu-22.04
container: python:3.10-slim-bullseye

steps:
- name: Checkout Code Repository
uses: actions/checkout@v3

- name: Install Dependencies
run: |
pip install -q flake8==6.0.0
- name: flake8
run: |
flake8 app/core
# Runs the frontend linting steps on the VM
linter_stylelint:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -148,9 +133,8 @@ jobs:
runs-on: ubuntu-22.04
needs:
[
linter_isort,
linter_ruff,
linter_black,
linter_flake8,
linter_stylelint,
linter_eslint,
linter_prettier,
Expand Down Expand Up @@ -248,9 +232,8 @@ jobs:
release:
needs:
[
linter_isort,
linter_ruff,
linter_black,
linter_flake8,
linter_stylelint,
linter_eslint,
linter_prettier,
Expand Down
14 changes: 5 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@ repos:
exclude: ^.+\.min\.(js|css)$
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.270
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/commitizen-tools/commitizen
rev: 3.2.2
hooks:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ See `pre-commit-config.yaml` for more details. In addition, please note the foll
### Dev

- [ ] Switch to [Poetry](https://python-poetry.org/)
- [ ] Replace [flake8](https://pypi.org/project/flake8/), [pycodestyle](https://pypi.org/project/pydocstyle/) and [isort](https://pypi.org/project/isort/) with [ruff](https://github.com/charliermarsh/ruff)
- [x] Replace [flake8](https://pypi.org/project/flake8/), [pycodestyle](https://pypi.org/project/pydocstyle/) and [isort](https://pypi.org/project/isort/) with [ruff](https://github.com/charliermarsh/ruff)
- [ ] Test all the things

### More ways to listen
Expand Down
32 changes: 23 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ dev = [
"commitizen",
"coverage[toml]",
"DSLR",
"flake8",
"isort",
"pip-tools",
"pre-commit",
"ruff",
]

[tool.setuptools]
Expand Down Expand Up @@ -73,13 +72,28 @@ exclude = '''
)
'''

[tool.isort]
profile = "black"
skip = ["node_modules", ".git", "__pycache__", "LC_MESSAGES", "venv", ".venv"]
blocked_extensions = ["rst", "html", "js", "svg", "txt", "css", "scss", "png", "snap", "ts", "tsx"]
known_first_party = "app"
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
default_section = "THIRDPARTY"
[tool.ruff]
line-length = 120
target-version = "py310"
select = ["B", "C", "E", "F", "W", "B9"]
ignore = ["E203", "E266", "E501", "F403", "F401"]
exclude = [
".git",
"__pycache__",
"node_modules",
"public",
"venv",
]

[tool.ruff.isort]
known-first-party = ["app"]
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]

[tool.ruff.pycodestyle]
max-doc-length = 120

[tool.ruff.mccabe]
max-complexity = 10

[tool.coverage.run]
include = ["app/core/*"]
Expand Down
12 changes: 2 additions & 10 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ filelock==3.12.0
# via virtualenv
filetype==1.2.0
# via eyed3
flake8==6.0.0
# via zed-news (pyproject.toml)
frozenlist==1.3.3
# via
# aiohttp
Expand All @@ -131,8 +129,6 @@ invoke==2.1.2
# via zed-news (pyproject.toml)
iso8601==1.1.0
# via tortoise-orm
isort==5.12.0
# via zed-news (pyproject.toml)
jinja2==3.1.2
# via
# commitizen
Expand All @@ -153,8 +149,6 @@ marshmallow==3.19.0
# marshmallow-enum
marshmallow-enum==1.5.1
# via dataclasses-json
mccabe==0.7.0
# via flake8
multidict==6.0.4
# via
# aiohttp
Expand Down Expand Up @@ -206,15 +200,11 @@ psycopg-pool==3.1.7
# via psycopg
psycopg2-binary==2.9.6
# via zed-news (pyproject.toml)
pycodestyle==2.10.0
# via flake8
pydantic==1.10.8
# via
# aerich
# langchain
# openapi-schema-pydantic
pyflakes==3.0.1
# via flake8
pygments==2.15.1
# via
# bpython
Expand Down Expand Up @@ -259,6 +249,8 @@ requests-oauthlib==1.3.1
# via apprise
rich==12.6.0
# via dslr
ruff==0.0.270
# via zed-news (pyproject.toml)
s3transfer==0.6.1
# via boto3
sgmllib3k==1.0.0
Expand Down
10 changes: 0 additions & 10 deletions setup.cfg

This file was deleted.

17 changes: 4 additions & 13 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ def import_db_dump(c, dump_file):
c.run(f'inv exec "db" "rm -vf /tmp/{dump_file}"', pty=True)


@task
def fix_path(c):
"""fix the PYTHON_PATH"""
# export PYTHONPATH="${PYTHONPATH}":`pwd`
cwd = os.path.abspath(__file__)
c.run(f'export PYTHONPATH="${{PYTHONPATH}}:{cwd}"', pty=True)


@task
def init_db(c):
"""use aerich to generate schema and generate app migrate location"""
Expand Down Expand Up @@ -264,17 +256,16 @@ def execute_bump_hack(c, branch, is_first_release=False, major=False):
c.run("rm -vf .bump_result.txt", pty=True)


@task(help={"fix": "let black and isort format your files"})
@task(help={"fix": "let black and ruff format your files"})
def lint(c, fix=False):
"""flake8, black and isort"""
"""ruff and black"""

if fix:
c.run("black .", pty=True)
c.run("isort --profile black .", pty=True)
c.run("ruff check --fix .", pty=True)
else:
c.run("black . --check", pty=True)
c.run("isort --check-only --profile black .", pty=True)
c.run("flake8 wb", pty=True)
c.run("ruff check .", pty=True)


# TODO: create a "clean" collection comprising the next two tasks below
Expand Down

0 comments on commit 31280f7

Please sign in to comment.