diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index da4729b..c4c337d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: - id: detect-aws-credentials args: [ --allow-missing-credentials ] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.0 # ruff version + rev: v0.8.6 # ruff version hooks: - id: ruff-format - id: ruff diff --git a/analysis/speed_test.ipynb b/analysis/speed_test.ipynb index deb7d6e..d5230f7 100644 --- a/analysis/speed_test.ipynb +++ b/analysis/speed_test.ipynb @@ -15,7 +15,8 @@ "metadata": {}, "outputs": [], "source": [ - "from pyliftover import LiftOver \n", + "from pyliftover import LiftOver\n", + "\n", "from agct import Converter" ] }, diff --git a/pyproject.toml b/pyproject.toml index 1cb5cb3..cceb833 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ tests = [ ] dev = [ "maturin", - "ruff==0.5.0", + "ruff==0.8.6", "pre-commit>=3.7.1", ] @@ -88,10 +88,14 @@ select = [ "RSE", # https://docs.astral.sh/ruff/rules/#flake8-raise-rse "RET", # https://docs.astral.sh/ruff/rules/#flake8-return-ret "SLF", # https://docs.astral.sh/ruff/rules/#flake8-self-slf + "SLOT", # https://docs.astral.sh/ruff/rules/#flake8-slots-slot "SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim "ARG", # https://docs.astral.sh/ruff/rules/#flake8-unused-arguments-arg "PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth "PGH", # https://docs.astral.sh/ruff/rules/#pygrep-hooks-pgh + "PLC", # https://docs.astral.sh/ruff/rules/#convention-c + "PLE", # https://docs.astral.sh/ruff/rules/#error-e_1 + "TRY", # https://docs.astral.sh/ruff/rules/#tryceratops-try "PERF", # https://docs.astral.sh/ruff/rules/#perflint-perf "FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb "RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf @@ -110,6 +114,9 @@ fixable = [ "PT", "RSE", "SIM", + "PLC", + "PLE", + "TRY", "PERF", "FURB", "RUF" @@ -130,23 +137,39 @@ fixable = [ # E501 - line-too-long* # W191 - tab-indentation* # S321 - suspicious-ftp-lib-usage +# PLC0206 - dict-index-missing-items # *ignored for compatibility with formatter ignore = [ - "ANN003", "ANN101", "ANN102", + "ANN003", "D203", "D205", "D206", "D213", "D300", "D400", "D415", "E111", "E114", "E117", "E501", "W191", "S321", + "PLC0206", ] [tool.ruff.lint.per-file-ignores] # ANN001 - missing-type-function-argument # ANN2 - missing-return-type -# ANN102 - missing-type-cls +# D100 - undocumented-public-module +# D102 - undocumented-public-class +# D103 - undocumented-public-function # S101 - assert # B011 - assert-false # INP001 - implicit-namespace-package -"tests/*" = ["ANN001", "ANN2", "ANN102", "S101", "B011", "INP001"] +"tests/*" = [ + "ANN001", + "ANN2", + "D100", + "D102", + "D103", + "S101", + "B011", + "INP001" +] + +[tool.ruff.lint.flake8-annotations] +mypy-init-return = true [tool.ruff.format] docstring-code-format = true diff --git a/src/agct/__init__.py b/src/agct/__init__.py index 31c2e91..37ef9c3 100644 --- a/src/agct/__init__.py +++ b/src/agct/__init__.py @@ -2,4 +2,4 @@ from agct.converter import Converter, Genome, Strand -__all__ = ["Converter", "Strand", "Genome"] +__all__ = ["Converter", "Genome", "Strand"] diff --git a/src/agct/converter.py b/src/agct/converter.py index 90a6d43..1252272 100644 --- a/src/agct/converter.py +++ b/src/agct/converter.py @@ -90,12 +90,12 @@ def __init__( try: self._converter = _core.Converter(chainfile) - except FileNotFoundError as e: - _logger.error("Unable to open chainfile located at %s", chainfile) - raise e - except _core.ChainfileError as e: - _logger.error("Error reading chainfile located at %s", chainfile) - raise e + except FileNotFoundError: + _logger.exception("Unable to open chainfile located at %s", chainfile) + raise + except _core.ChainfileError: + _logger.exception("Error reading chainfile located at %s", chainfile) + raise @staticmethod def _download_function_builder(from_db: Genome, to_db: Genome) -> Callable: @@ -147,7 +147,7 @@ def convert_coordinate( except _core.NoLiftoverError: results = [] except _core.ChainfileError: - _logger.error( + _logger.exception( "Encountered internal error while converting coordinates - is the chainfile invalid? (%s, %s, %s)", chrom, pos, @@ -159,12 +159,12 @@ def convert_coordinate( try: pos = int(result[1]) except ValueError: - _logger.error("Got invalid position value in %s", result) + _logger.exception("Got invalid position value in %s", result) continue try: strand = Strand(result[2]) except ValueError: - _logger.error("Got invalid Strand value in %s", result) + _logger.exception("Got invalid Strand value in %s", result) continue formatted_results.append((result[0], pos, strand)) return formatted_results