From db75f204288a16dc9718bdc1faa452fa403a27a5 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Thu, 8 Aug 2024 09:36:03 -0400 Subject: [PATCH 1/3] style: update ruff --- .pre-commit-config.yaml | 2 +- pyproject.toml | 22 ++++++++++++++++++---- src/agct/__init__.py | 1 + src/agct/converter.py | 3 ++- tests/conftest.py | 3 ++- tests/test_converter.py | 1 + tests/test_liftover.py | 1 + tests/test_rust_api.py | 1 + 8 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6c38be6..80376c4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.0 + rev: v0.5.0 # ruff version hooks: - id: ruff-format - id: ruff diff --git a/pyproject.toml b/pyproject.toml index 6245343..3ad5be9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ tests = [ ] dev = [ "maturin", - "ruff==0.2.0", + "ruff==0.5.0", "pre-commit", ] @@ -78,6 +78,8 @@ select = [ "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 + "LOG", # https://docs.astral.sh/ruff/rules/#flake8-logging-log + "INP", # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp "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 @@ -85,9 +87,13 @@ select = [ "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 + "SLF", # https://docs.astral.sh/ruff/rules/#flake8-self-slf "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 + "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 ] fixable = [ @@ -98,15 +104,19 @@ fixable = [ "ANN", "B", "C4", + "LOG", "G", "PIE", "PT", "RSE", "SIM", + "PERF", + "FURB", "RUF" ] -# ANN101 - missing-type-self # ANN003 - missing-type-kwargs +# ANN101 - missing-type-self +# ANN102 - missing-type-cls # D203 - one-blank-line-before-class # D205 - blank-line-after-summary # D206 - indent-with-spaces* @@ -122,7 +132,7 @@ fixable = [ # S321 - suspicious-ftp-lib-usage # *ignored for compatibility with formatter ignore = [ - "ANN101", "ANN003", + "ANN003", "ANN101", "ANN102", "D203", "D205", "D206", "D213", "D300", "D400", "D415", "E111", "E114", "E117", "E501", "W191", @@ -135,4 +145,8 @@ ignore = [ # ANN102 - missing-type-cls # S101 - assert # B011 - assert-false -"tests/*" = ["ANN001", "ANN2", "ANN102", "S101", "B011"] +# INP001 - implicit-namespace-package +"tests/*" = ["ANN001", "ANN2", "ANN102", "S101", "B011", "INP001"] + +[tool.ruff.format] +docstring-code-format = true diff --git a/src/agct/__init__.py b/src/agct/__init__.py index cdb2f06..31c2e91 100644 --- a/src/agct/__init__.py +++ b/src/agct/__init__.py @@ -1,4 +1,5 @@ """Provide fast liftover in Python via the ``chainfile`` crate.""" + from agct.converter import Converter, Genome, Strand __all__ = ["Converter", "Strand", "Genome"] diff --git a/src/agct/converter.py b/src/agct/converter.py index a7680c4..286af46 100644 --- a/src/agct/converter.py +++ b/src/agct/converter.py @@ -1,4 +1,5 @@ """Perform chainfile-driven liftover.""" + import logging from collections.abc import Callable from enum import Enum @@ -96,7 +97,7 @@ def _download_function_builder(from_db: Genome, to_db: Genome) -> Callable: :return: Function that downloads appropriate chainfile from UCSC """ - def _download_data(version: str, file: Path) -> None: + def _download_data(version: str, file: Path) -> None: # noqa: ARG001 """Download and gunzip chainfile from UCSC. :param version: not used diff --git a/tests/conftest.py b/tests/conftest.py index 269261a..1964dba 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ """Configure tests.""" + import os from pathlib import Path @@ -7,7 +8,7 @@ DATA_DIR = Path(__file__).parents[0] / "data" -def pytest_sessionstart(session): +def pytest_sessionstart(session): # noqa: ARG001 """Perform actions after Session object is created. * set test data directory diff --git a/tests/test_converter.py b/tests/test_converter.py index 6db2ce7..6041fd5 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -1,4 +1,5 @@ """Module for testing Converter initialization""" + import pytest from tests.conftest import DATA_DIR diff --git a/tests/test_liftover.py b/tests/test_liftover.py index 2ac1fdb..d931509 100644 --- a/tests/test_liftover.py +++ b/tests/test_liftover.py @@ -1,4 +1,5 @@ """Run liftover tests.""" + from agct import Converter, Genome, Strand diff --git a/tests/test_rust_api.py b/tests/test_rust_api.py index a8019d2..4f2d894 100644 --- a/tests/test_rust_api.py +++ b/tests/test_rust_api.py @@ -1,4 +1,5 @@ """Test some non-public aspects of the Rust layer.""" + import pytest from agct._core import ChainfileError, Converter From 8d75783948f0f025edbfa8988a5260844b68d20a Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Thu, 9 Jan 2025 14:08:46 -0500 Subject: [PATCH 2/3] update --- .pre-commit-config.yaml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/pyproject.toml b/pyproject.toml index 16c6baf..693f6ed 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", ] From e72fe0b5286ec9b5c1dc602929f27dafc2ad7baf Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Thu, 9 Jan 2025 14:22:27 -0500 Subject: [PATCH 3/3] style use ruff --- analysis/speed_test.ipynb | 3 ++- pyproject.toml | 29 ++++++++++++++++++++++++++--- src/agct/__init__.py | 2 +- src/agct/converter.py | 18 +++++++++--------- 4 files changed, 38 insertions(+), 14 deletions(-) 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 693f6ed..939fc04 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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