Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ruff #17

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.github
.vscode
.pytest_cache
.ruff_cache
*.md
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,7 @@ dmypy.json
poetry.lock

# Visual Studio Code
.vscode
.vscode

# Ruff Settings
.ruff_cache
12 changes: 8 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ Namespaces are one honking great idea -- let's do more of those!

# Coding Style

[![PEP20](https://img.shields.io/badge/code%20style-pep20-red.svg)](https://www.python.org/dev/peps/pep-0020/)
[![PEP8](https://img.shields.io/badge/code%20style-pep8-orange.svg)](https://www.python.org/dev/peps/pep-0008/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![bandit](https://img.shields.io/badge/code%20style-bandit-green.svg)](https://github.com/PyCQA/bandit)
We are using [Ruff](https://github.com/astral-sh/ruff) to manage the coding style [rules](https://beta.ruff.rs/docs/rules/).

Rule | Description
--- | ---
E,W | [pycode style](https://pypi.org/project/pycodestyle/)
F | [pyflakes](https://pypi.org/project/pyflakes/)
I | [isort](https://pypi.org/project/isort/)
N | [pep8-naming](https://pypi.org/project/pep8-naming/)
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ local/tests:
poetry run pytest --cov-report=html --cov-report=term --cov .

local/lint:
poetry run flake8 .
poetry run black --check .
poetry run ruff check .
poetry run ruff . --fix --exit-non-zero-on-fix

local/lint/fix:
poetry run black .
Expand All @@ -38,11 +38,10 @@ docker/test:
docker-compose run ${APP_NAME} poetry run pytest --cov-report=html --cov-report=term --cov .

docker/lint:
docker-compose run ${APP_NAME} poetry run flake8 .
docker-compose run ${APP_NAME} poetry run black --check .
docker-compose run ${APP_NAME} poetry run ruff check .

docker/lint/fix:
docker-compose run ${APP_NAME} poetry run black .
docker-compose run ${APP_NAME} poetry run ruff . --fix --exit-non-zero-on-fix

docker/run:
docker-compose run ${APP_NAME} poetry run python src/main.py
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ A python boilerplate project using poetry
- [Docker](https://www.docker.com/get-started) - **pre-requisite**
- [Docker Compose](https://docs.docker.com/compose/) - **pre-requisite**
- [Poetry](https://python-poetry.org/) - **pre-requisite**
- [Flake8](https://flake8.pycqa.org/en/latest/)
- [Black](https://black.readthedocs.io/en/stable/)
- [Ruff](https://github.com/astral-sh/ruff)

*Please pay attention on **pre-requisites** resources that you must install/configure.*

Expand All @@ -29,8 +28,8 @@ Command | Docker | Locally | Description
---- | ------- | ------- | -------
install | `make docker/install` | `make local/install` | to install
tests | `make docker/tests` | `make local/tests` | to run the tests with coverage
lint | `make docker/lint` | `make local/lint` | to run static code analysis using flake8 and black
lint/fix | `make docker/lint/fix` | `make local/lint/fix` | to fix files using black code formatter
lint | `make docker/lint` | `make local/lint` | to run static code analysis using ruff
lint/fix | `make docker/lint/fix` | `make local/lint/fix` | to fix files using ruff
run | `make docker/run` | `make local/run` | to run the project

**Helpful commands**
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ python = "^3.11"
[tool.poetry.dev-dependencies]
pytest = "7.3.2"
pytest-cov = "^4.1.0"
flake8 = "^6.0.0"
black = "^23.3.0"
ruff = "^0.0.272"

[tool.pytest.ini_options]
testpaths = ["tests",]
Expand All @@ -28,9 +27,10 @@ fail_under = 100
[tool.coverage.html]
directory = "htmlcov"

[tool.black]
[tool.ruff]
line-length = 120
target-version = ['py39']
select = ["E", "F", "W", "I", "N"]
target-version = "py311"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
3 changes: 1 addition & 2 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from logging.config import fileConfig as logConfig
from logging import getLogger

from logging.config import fileConfig as logConfig

logConfig("./logging.conf", disable_existing_loggers=False)
logger = getLogger(__name__)
Expand Down