Skip to content

Commit

Permalink
style: format with Ruff (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson authored Jun 21, 2024
1 parent 0730c62 commit 7c35332
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
run: |
isort --check src
- name: Format check with black
- name: Format check with ruff
run: |
black --check src
ruff format --check src
- name: Security check with bandit
run: |
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ repos:
entry: isort
language: system
types: [python]
- id: black
name: black
entry: black
language: system
types: [python]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff-format
args: [ --check ]
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ build: %:
cqa:
flake8 src --count --select=E9,F63,F7,F82 --show-source --statistics
isort --profile black --check src
black --check src
ruff format --check src tests
bandit -ll -r src

#=> test: execute tests
Expand Down Expand Up @@ -97,7 +97,7 @@ cqa:
flake8 src --show-source --statistics
pyright
isort --check src --profile black
black --check src
ruff format --check src
bandit -ll -r src

#=> reformat: reformat code
Expand All @@ -108,13 +108,13 @@ reformat:
############################################################################
#= UTILITY TARGETS

#=> reformat: reformat code with yapf and commit
#=> reformat: reformat code and commit
.PHONY: reformat
reformat:
@if ! git diff --cached --exit-code >/dev/null; then echo "Repository not clean" 1>&2; exit 1; fi
black src tests
ruff src tests
isort src tests
git commit -a -m "reformatted with black and isort"
git commit -a -m "reformatted with ruff and isort"

#=> rename: rename files and substitute content for new repo name
.PHONY: rename
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ dependencies = [
[project.optional-dependencies]
dev = [
"bandit ~= 1.7",
"black ~= 22.3",
"build ~= 0.8",
"flake8 ~= 4.0",
"ipython ~= 8.4",
Expand All @@ -42,6 +41,7 @@ dev = [
"pytest ~= 7.1",
"pyright~=1.1",
"requests_html ~= 0.10",
"ruff == 0.4.4",
"tox ~= 3.25",
"vcrpy",
]
Expand Down Expand Up @@ -116,9 +116,6 @@ exclude_lines = [
"if __name__ == .__main__.:",
]

[tool.black]
line-length = 100

[tool.isort]
profile = "black"
src_paths = ["src", "tests"]
Expand All @@ -133,3 +130,7 @@ disable = "R0913"

[tool.pylint.format]
max-line-length = 100

[tool.ruff]
src = ["src", "tests"]
line-length = 100
6 changes: 5 additions & 1 deletion src/biocommons/seqrepo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$ seqrepo --help
"""

import argparse
import datetime
import gzip
Expand Down Expand Up @@ -524,7 +525,10 @@ def load(opts: argparse.Namespace) -> None:
fh = io.open(fn, mode="rt", encoding="ascii")
_logger.info("Opened " + fn)
seq_bar = tqdm.tqdm(
FastaIter(fh), unit=" seqs", disable=disable_bar, leave=False # type: ignore noqa: E501
FastaIter(fh), # type: ignore
unit=" seqs",
disable=disable_bar,
leave=False,
)
for defline, seq in seq_bar: # type: ignore
n_seqs_seen += 1
Expand Down
1 change: 1 addition & 0 deletions src/biocommons/seqrepo/fastadir/fabgz.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Files must be named as .fa.bgz to be recognized as blocked gzip compressed
"""

import io
import logging
import os
Expand Down
8 changes: 2 additions & 6 deletions src/biocommons/seqrepo/fastadir/fastadir.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ def __init__(
if schema_version != expected_schema_version:
raise RuntimeError(
"""Upgrade required: Database schema
version is {} and code expects {}""".format(
schema_version, expected_schema_version
)
version is {} and code expects {}""".format(schema_version, expected_schema_version)
)

if fd_cache_size == 0:
Expand Down Expand Up @@ -142,9 +140,7 @@ def fetch(self, seq_id: str, start: Optional[int] = None, end: Optional[int] = N
if self._writing and self._writing["relpath"] == rec["relpath"]:
_logger.warning(
"""Fetching from file opened for writing;
closing first ({})""".format(
rec["relpath"]
)
closing first ({})""".format(rec["relpath"])
)
self.commit()

Expand Down
5 changes: 3 additions & 2 deletions src/biocommons/seqrepo/seqaliasdb/seqaliasdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def __init__(
# if we're not at the expected schema version for this code, bail
if schema_version != expected_schema_version: # pragma: no cover
raise RuntimeError(
"Upgrade required: Database schema"
"version is {} and code expects {}".format(schema_version, expected_schema_version)
"Upgrade required: Database schema" "version is {} and code expects {}".format(
schema_version, expected_schema_version
)
)

# ############################################################################
Expand Down

0 comments on commit 7c35332

Please sign in to comment.