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

style: use ruff #313

Merged
merged 13 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
12 changes: 0 additions & 12 deletions .flake8

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@ jobs:
run: |
python -m pip install pipenv
pipenv install --skip-lock # this is what Elastic beanstalk uses
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install dependencies
run: python3 -m pip install ".[dev]"

- name: Check style
run: python3 -m ruff check . && python3 -m ruff format --check .
20 changes: 11 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.4.0
hooks:
- id: flake8
additional_dependencies: [flake8-docstrings]
- id: check-added-large-files
args: ['--maxkb=1024']
exclude: ^tests/data
- id: detect-private-key
- id: check-added-large-files
- id: detect-private-key
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.0 # ruff version
hooks:
- id: ruff-format
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
3 changes: 1 addition & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pytest-cov = "*"
pytest-asyncio = "*"
mock = "*"
pre-commit = "*"
flake8 = "*"
flake8-docstrings = "*"
ruff = "==0.2.0"
ipykernel = "*"
jupyterlab = "*"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ python3 -m pytest

### And coding style tests

Code style is managed by [flake8](https://github.com/PyCQA/flake8) and checked prior to commit.
Code style is managed by [ruff](https://astral.sh/ruff) and checked prior to commit.

```
see .flake8
python3 -m ruff check --fix . && python3 -m ruff format .

```

Expand Down
84 changes: 83 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dynamic = ["version"]

[project.optional-dependencies]
tests = ["pytest", "pytest-cov", "mock", "pytest-asyncio"]
dev = ["pre-commit", "flake8", "flake8-docstrings"]
dev = ["pre-commit", "ruff==0.2.0"]
notebooks = ["ipykernel", "jupyterlab"]

[project.urls]
Expand Down Expand Up @@ -73,3 +73,85 @@ testpaths = ["tests"]

[tool.coverage.run]
branch = true

[tool.ruff]
src = ["src"]
exclude = ["docs/*", "analysis/*", "codebuild/*"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and ran format on analysis and codebuild but I didn't think it would be worth it to actively maintain them style-wise


[tool.ruff.lint]
select = [
"F", # https://docs.astral.sh/ruff/rules/#pyflakes-f
"E", "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"I", # https://docs.astral.sh/ruff/rules/#isort-i
"N", # https://docs.astral.sh/ruff/rules/#pep8-naming-n
"D", # https://docs.astral.sh/ruff/rules/#pydocstyle-d
"UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up
"ANN", # https://docs.astral.sh/ruff/rules/#flake8-annotations-ann
"ASYNC", # https://docs.astral.sh/ruff/rules/#flake8-async-async
"S", # https://docs.astral.sh/ruff/rules/#flake8-bandit-s
"B", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
"A", # https://docs.astral.sh/ruff/rules/#flake8-builtins-a
"C4", # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
"DTZ", # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz
"T10", # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em
"G", # https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
"PIE", # https://docs.astral.sh/ruff/rules/#flake8-pie-pie
"T20", # https://docs.astral.sh/ruff/rules/#flake8-print-t20
"PT", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
"Q", # https://docs.astral.sh/ruff/rules/#flake8-quotes-q
"RSE", # https://docs.astral.sh/ruff/rules/#flake8-raise-rse
"RET", # https://docs.astral.sh/ruff/rules/#flake8-return-ret
"SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
"PGH", # https://docs.astral.sh/ruff/rules/#pygrep-hooks-pgh
"RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
]
fixable = [
"I",
"F401",
"D",
"UP",
"ANN",
"B",
"C4",
"G",
"PIE",
"PT",
"RSE",
"SIM",
"RUF"
]
# ANN101 - missing-type-self
# ANN003 - missing-type-kwargs
# D203 - one-blank-line-before-class
# D205 - blank-line-after-summary
# D206 - indent-with-spaces*
# D213 - multi-line-summary-second-line
# D300 - triple-single-quotes*
# D400 - ends-in-period
# D415 - ends-in-punctuation
# E111 - indentation-with-invalid-multiple*
# E114 - indentation-with-invalid-multiple-comment*
# E117 - over-indented*
# E501 - line-too-long*
# W191 - tab-indentation*
# S321 - suspicious-ftp-lib-usage
# *ignored for compatibility with formatter
ignore = [
"ANN101", "ANN003",
"D203", "D205", "D206", "D213", "D300", "D400", "D415",
"E111", "E114", "E117", "E501",
"W191",
"S321",
]

[tool.ruff.lint.per-file-ignores]
# ANN001 - missing-type-function-argument
# ANN2 - missing-return-type
# ANN102 - missing-type-cls
# S101 - assert
# B011 - assert-false
# N815 -
"tests/*" = ["ANN001", "ANN2", "ANN102", "S101", "B011"]
"src/metakb/schemas/*" = ["ANN102", "N815"]
19 changes: 8 additions & 11 deletions src/metakb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
"""The MetaKB package."""
from pathlib import Path
import logging
from os import environ
from pathlib import Path

APP_ROOT = Path(__file__).resolve().parents[0]
PROJECT_ROOT = Path(__file__).resolve().parents[1]

if 'METAKB_NORM_EB_PROD' in environ:
LOG_FN = "/tmp/metakb.log"
else:
LOG_FN = "metakb.log"
LOG_FN = "/tmp/metakb.log" if "METAKB_NORM_EB_PROD" in environ else "metakb.log" # noqa: S108

logging.basicConfig(
filename=LOG_FN,
format='[%(asctime)s] - %(name)s - %(levelname)s : %(message)s')
logger = logging.getLogger('metakb')
filename=LOG_FN, format="[%(asctime)s] - %(name)s - %(levelname)s : %(message)s"
)
logger = logging.getLogger("metakb")
logger.setLevel(logging.DEBUG)
logging.getLogger("boto3").setLevel(logging.INFO)
logging.getLogger("botocore").setLevel(logging.INFO)
logging.getLogger("urllib3").setLevel(logging.INFO)
logging.getLogger("python_jsonschema_objects").setLevel(logging.INFO)
logging.getLogger("hgvs.parser").setLevel(logging.INFO)
logging.getLogger("biocommons.seqrepo.seqaliasdb.seqaliasdb").setLevel(logging.INFO) # noqa: E501
logging.getLogger("biocommons.seqrepo.fastadir.fastadir").setLevel(logging.INFO) # noqa: E501
logging.getLogger("biocommons.seqrepo.seqaliasdb.seqaliasdb").setLevel(logging.INFO)
logging.getLogger("biocommons.seqrepo.fastadir.fastadir").setLevel(logging.INFO)
logging.getLogger("requests_cache.patcher").setLevel(logging.INFO)
logging.getLogger("bioregistry.resource_manager").setLevel(logging.INFO)
logging.getLogger("blib2to3.pgen2.driver").setLevel(logging.INFO)
logging.getLogger("neo4j").setLevel(logging.INFO)
logging.getLogger("asyncio").setLevel(logging.INFO)
logger.handlers = []

if 'METAKB_NORM_EB_PROD' in environ:
if "METAKB_NORM_EB_PROD" in environ:
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
Expand Down
Loading
Loading