diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index a2ed63d..69a2464 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -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: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 384b910..eb0eb87 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 ] diff --git a/Makefile b/Makefile index 8464cfa..1474805 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -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 diff --git a/pyproject.toml b/pyproject.toml index cc89bd0..e5a386b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,6 @@ dependencies = [ [project.optional-dependencies] dev = [ "bandit ~= 1.7", - "black ~= 22.3", "build ~= 0.8", "flake8 ~= 4.0", "ipython ~= 8.4", @@ -42,6 +41,7 @@ dev = [ "pytest ~= 7.1", "pyright~=1.1", "requests_html ~= 0.10", + "ruff == 0.4.4", "tox ~= 3.25", "vcrpy", ] @@ -116,9 +116,6 @@ exclude_lines = [ "if __name__ == .__main__.:", ] -[tool.black] -line-length = 100 - [tool.isort] profile = "black" src_paths = ["src", "tests"] @@ -133,3 +130,7 @@ disable = "R0913" [tool.pylint.format] max-line-length = 100 + +[tool.ruff] +src = ["src", "tests"] +line-length = 100 diff --git a/src/biocommons/seqrepo/cli.py b/src/biocommons/seqrepo/cli.py index d2b76a6..a767d34 100644 --- a/src/biocommons/seqrepo/cli.py +++ b/src/biocommons/seqrepo/cli.py @@ -10,6 +10,7 @@ $ seqrepo --help """ + import argparse import datetime import gzip @@ -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 diff --git a/src/biocommons/seqrepo/fastadir/fabgz.py b/src/biocommons/seqrepo/fastadir/fabgz.py index 987a131..10f9a40 100644 --- a/src/biocommons/seqrepo/fastadir/fabgz.py +++ b/src/biocommons/seqrepo/fastadir/fabgz.py @@ -5,6 +5,7 @@ Files must be named as .fa.bgz to be recognized as blocked gzip compressed """ + import io import logging import os diff --git a/src/biocommons/seqrepo/fastadir/fastadir.py b/src/biocommons/seqrepo/fastadir/fastadir.py index 83b3851..1336a3c 100644 --- a/src/biocommons/seqrepo/fastadir/fastadir.py +++ b/src/biocommons/seqrepo/fastadir/fastadir.py @@ -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: @@ -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() diff --git a/src/biocommons/seqrepo/seqaliasdb/seqaliasdb.py b/src/biocommons/seqrepo/seqaliasdb/seqaliasdb.py index 916106d..2a26ba8 100644 --- a/src/biocommons/seqrepo/seqaliasdb/seqaliasdb.py +++ b/src/biocommons/seqrepo/seqaliasdb/seqaliasdb.py @@ -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 + ) ) # ############################################################################