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: replace black with ruff #532

Merged
merged 5 commits into from
Feb 13, 2024
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
22 changes: 0 additions & 22 deletions .flake8

This file was deleted.

13 changes: 9 additions & 4 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: black
uses: psf/black@stable
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.11

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

- name: ruff
uses: chartboost/ruff-action@v1
- name: Check style
run: python3 -m ruff check . && ruff format --check .
11 changes: 3 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: detect-private-key
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
language_version: python3.11
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.280
rev: v0.2.0
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 @@ -12,8 +12,7 @@ variation-normalizer = {editable = true, path = "."}
jupyter = "*"
ipykernel = "*"
psycopg2-binary = "*"
ruff = "*"
black = "*"
ruff = "==0.2.0"

[packages]
"biocommons.seqrepo" = "*"
Expand Down
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,26 @@ Next, view the OpenAPI docs on your local machine:

### Init coding style tests

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

Check style with `ruff`:

```shell
python3 -m ruff format . && python3 -m ruff check --fix .
```

We use [pre-commit](https://pre-commit.com/#usage) to run conformance tests.

This ensures:

* Check code style
* Check for added large files
* Detect AWS Credentials
* Detect Private Key
* Style correctness
* No large files
* AWS credentials are present
* Private key is present

Before first commit run:
Pre-commit *must* be installed before your first commit. Use the following command:

```shell
```commandline
pre-commit install
```

Expand Down
2 changes: 1 addition & 1 deletion codebuild/deploy_eb_env_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
"Status"
]
print(eb_provisioned_product_status)
except Exception as e: # noqa: E722
except Exception as e:
print(e)
print("The EB environment is already running....")
105 changes: 79 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,93 @@
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta:__legacy__"

[tool.black]
line-length = 88

[tool.ruff]
# pycodestyle (E, W)
# Pyflakes (F)
# flake8-annotations (ANN)
# flake8-quotes (Q)
# pydocstyle (D)
# pep8-naming (N)
# isort (I)
select = ["E", "W", "F", "ANN", "Q", "D", "N", "I"]

fixable = ["I", "F401"]
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
]

lint.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
# ANN101 - missing-type-self
# ANN003 - missing-type-kwargs
# E501 - line-too-long
ignore = ["D205", "D400", "D415", "ANN101", "ANN003", "E501"]
# E111 - indentation-with-invalid-multiple*
# E114 - indentation-with-invalid-multiple-comment*
# E117 - over-indented*
# E501 - line-too-long*
# W191 - tab-indentation*
# PGH003 - blanket-type-ignore
# *ignored for compatibility with formatter
lint.ignore = [
"ANN101", "ANN003",
"D203", "D205", "D206", "D213", "D300", "D400", "D415",
"E111", "E114", "E117", "E501",
"W191",
"PGH003",
"S321",
]

[tool.ruff.flake8-quotes]
docstring-quotes = "double"
exclude = [
"setup.py"
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
# ANN001 - missing-type-function-argument
# ANN2 - missing-return-type
# ANN201 - Missing type annotation
# ANN102 - missing-type-cls
# N805 - invalid-first-argument-name-for-method
# F821 - undefined-name
# F401 - unused-import
"tests/*" = ["ANN001", "ANN2", "ANN102"]
"setup.py" = ["F821"]
"*__init__.py" = ["F401"]
"variation/schemas/*" = ["ANN201", "N805", "ANN001"]
# S101 - assert
# B011 - assert-false
# RUF001 - ambiguous-unicode-character-string
"tests/*" = ["ANN001", "ANN102", "ANN2", "S101", "B011"]
"variation/schemas/*" = ["ANN001", "ANN201", "N805", "S101"]
"codebuild/*" = ["T201"]

[tool.ruff.lint.flake8-bugbear]
# Allow default arguments like, e.g., `data: List[str] = fastapi.Query(None)`.
extend-immutable-calls = ["fastapi.Query"]
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ dev =
pytest
pytest-asyncio
pytest-cov
ruff
ruff == 0.2.0
pre-commit
jupyter
ipykernel
psycopg2-binary
black

[tool:pytest]
addopts = --ignore setup.py --ignore=codebuild/ --doctest-modules --cov-report term-missing --cov .
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,11 @@ def assertion_checks(normalize_response, test_variation):
def cnv_assertion_checks(resp, test_fixture):
"""Check that actual response for to copy number matches expected"""
try:
getattr(resp, "copy_number_count")
cnc = resp.copy_number_count
except AttributeError:
actual = resp.copy_number_change.model_dump(exclude_none=True)
else:
actual = resp.copy_number_count.model_dump(exclude_none=True)
actual = cnc.model_dump(exclude_none=True)
expected = test_fixture.model_dump(exclude_none=True)
assert actual == expected
assert resp.warnings == []
4 changes: 3 additions & 1 deletion tests/test_classifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Module for testing classifiers"""
from pathlib import Path

import pytest
import yaml

Expand Down Expand Up @@ -30,7 +32,7 @@
@pytest.fixture(scope="module")
def all_fixtures():
"""Create fixture for classifiers"""
with open(f"{PROJECT_ROOT}/tests/fixtures/classifiers.yml") as stream:
with Path(f"{PROJECT_ROOT}/tests/fixtures/classifiers.yml").open() as stream:
return yaml.safe_load(stream)


Expand Down
12 changes: 6 additions & 6 deletions tests/test_gnomad_vcf_to_protein.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def delins_neg():
return models.Allele(**params)


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_substitution(
test_handler,
braf_v600e,
Expand Down Expand Up @@ -327,7 +327,7 @@ async def test_substitution(
assertion_checks(resp, multi_nuc_sub_neg)


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_reference_agree(test_handler, vhl_reference_agree):
"""Test that reference agree queries return correct response"""
# https://www.ncbi.nlm.nih.gov/clinvar/variation/379039/?new_evidence=true
Expand All @@ -338,7 +338,7 @@ async def test_reference_agree(test_handler, vhl_reference_agree):
assert resp.warnings == []


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_insertion(test_handler, protein_insertion, protein_insertion2):
"""Test that insertion queries return correct response"""
# positive strand (CA645561585)
Expand All @@ -356,7 +356,7 @@ async def test_insertion(test_handler, protein_insertion, protein_insertion2):
assert resp.warnings == []


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_deletion(test_handler, protein_deletion_np_range, cdk11a_e314del):
"""Test that deletion queries return correct response"""
resp = await test_handler.gnomad_vcf_to_protein("17-39723966-TTGAGGGAAAACACAT-T")
Expand All @@ -371,7 +371,7 @@ async def test_deletion(test_handler, protein_deletion_np_range, cdk11a_e314del)
assert resp.warnings == []


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_delins(test_handler, delins_pos, delins_neg):
"""Test that delins queries return correct response"""
# CA645561524, Positive Strand
Expand All @@ -389,7 +389,7 @@ async def test_delins(test_handler, delins_pos, delins_neg):
assert resp.gene_context


@pytest.mark.asyncio
@pytest.mark.asyncio()
async def test_invalid(test_handler):
"""Test that invalid queries return correct response"""
resp = await test_handler.gnomad_vcf_to_protein("BRAF V600E")
Expand Down
Loading
Loading