diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 45736c8af..104a97062 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ ci: autofix_commit_msg: "chore: pre-commit auto fixes [...]" repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.2 + rev: v0.3.0 hooks: - id: ruff args: diff --git a/pyproject.toml b/pyproject.toml index 3f4f44545..d94d8412b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -158,13 +158,14 @@ module = [ ignore_missing_imports = true -[tool.ruff] +[tool.ruff.lint] select = [ "B002", # Python does not support the unary prefix increment "B007", # Loop control variable {name} not used within loop body "B014", # Exception handler with duplicate exception "B023", # Function definition does not bind loop variable {name} "B026", # Star-arg unpacking after a keyword argument is strongly discouraged + "B904", # Checks for raise statements in exception handlers that lack a from clause "C", # complexity "COM818", # Trailing comma on bare tuple prohibited "D", # docstrings @@ -179,7 +180,6 @@ select = [ "N804", # First argument of a class method should be named cls "N805", # First argument of a method should be named self "N815", # Variable {name} in class scope should not be mixedCase - "PGH001", # No builtin eval() allowed "PGH004", # Use specific rule codes when using noqa "PLC0414", # Useless import alias. Import alias does not rename original package. "PLC", # pylint @@ -218,7 +218,6 @@ select = [ "T20", # flake8-print "TID251", # Banned imports "TRY004", # Prefer TypeError exception for invalid type - "TRY200", # Use raise from to specify exception cause "TRY302", # Remove exception handler; error is immediately re-raised "UP", # pyupgrade "W", # pycodestyle diff --git a/tests/airflow/test_dag.py b/tests/airflow/test_dag.py index 8676d70f4..49edc76ee 100644 --- a/tests/airflow/test_dag.py +++ b/tests/airflow/test_dag.py @@ -1,4 +1,5 @@ """Check for airflow import errors. Inspiration from https://garystafford.medium.com/devops-for-dataops-building-a-ci-cd-pipeline-for-apache-airflow-dags-975e4a622f83.""" + from __future__ import annotations import pytest diff --git a/tests/gentropy/common/test_session.py b/tests/gentropy/common/test_session.py index b7d0156d2..2ea7ccc1b 100644 --- a/tests/gentropy/common/test_session.py +++ b/tests/gentropy/common/test_session.py @@ -1,4 +1,5 @@ """Tests GWAS Catalog study splitter.""" + from __future__ import annotations from typing import TYPE_CHECKING diff --git a/tests/gentropy/conftest.py b/tests/gentropy/conftest.py index c7af5a589..13409ac16 100644 --- a/tests/gentropy/conftest.py +++ b/tests/gentropy/conftest.py @@ -1,4 +1,5 @@ """Unit test configuration.""" + from __future__ import annotations from pathlib import Path diff --git a/tests/gentropy/dataset/test_colocalisation.py b/tests/gentropy/dataset/test_colocalisation.py index 2937efbca..1651aa2d4 100644 --- a/tests/gentropy/dataset/test_colocalisation.py +++ b/tests/gentropy/dataset/test_colocalisation.py @@ -1,4 +1,5 @@ """Test colocalisation dataset.""" + from __future__ import annotations from gentropy.dataset.colocalisation import Colocalisation diff --git a/tests/gentropy/dataset/test_dataset.py b/tests/gentropy/dataset/test_dataset.py index 340906322..88f44ed5b 100644 --- a/tests/gentropy/dataset/test_dataset.py +++ b/tests/gentropy/dataset/test_dataset.py @@ -1,4 +1,5 @@ """Test Dataset class.""" + from __future__ import annotations import pyspark.sql.functions as f diff --git a/tests/gentropy/dataset/test_gene_index.py b/tests/gentropy/dataset/test_gene_index.py index 68c279cab..999f089b3 100644 --- a/tests/gentropy/dataset/test_gene_index.py +++ b/tests/gentropy/dataset/test_gene_index.py @@ -1,4 +1,5 @@ """Tests on LD index.""" + from __future__ import annotations from gentropy.dataset.gene_index import GeneIndex diff --git a/tests/gentropy/dataset/test_intervals.py b/tests/gentropy/dataset/test_intervals.py index bfa12ad69..26d79acd1 100644 --- a/tests/gentropy/dataset/test_intervals.py +++ b/tests/gentropy/dataset/test_intervals.py @@ -1,4 +1,5 @@ """Tests on LD index.""" + from __future__ import annotations from typing import TYPE_CHECKING diff --git a/tests/gentropy/dataset/test_l2g.py b/tests/gentropy/dataset/test_l2g.py index 045b98d62..a6a14c346 100644 --- a/tests/gentropy/dataset/test_l2g.py +++ b/tests/gentropy/dataset/test_l2g.py @@ -1,4 +1,5 @@ """Tests on L2G datasets.""" + from __future__ import annotations from typing import TYPE_CHECKING @@ -167,8 +168,8 @@ def test_calculate_feature_missingness_rate(spark: SparkSession) -> None: expected_missingness = {"distanceTssMean": 0.0, "distanceTssMinimum": 1.0} observed_missingness = fm.calculate_feature_missingness_rate() assert isinstance(observed_missingness, dict) - assert len(observed_missingness) == len( - fm.features_list # type: ignore + assert fm.features_list is not None and len(observed_missingness) == len( + fm.features_list ), "Missing features in the missingness rate dictionary." assert ( observed_missingness == expected_missingness diff --git a/tests/gentropy/dataset/test_ld_index.py b/tests/gentropy/dataset/test_ld_index.py index c3eff6a4d..dc2b49c09 100644 --- a/tests/gentropy/dataset/test_ld_index.py +++ b/tests/gentropy/dataset/test_ld_index.py @@ -1,4 +1,5 @@ """Tests on LD index.""" + from __future__ import annotations from gentropy.dataset.ld_index import LDIndex diff --git a/tests/gentropy/dataset/test_study_index.py b/tests/gentropy/dataset/test_study_index.py index 1d43b3b07..6e327c086 100644 --- a/tests/gentropy/dataset/test_study_index.py +++ b/tests/gentropy/dataset/test_study_index.py @@ -1,4 +1,5 @@ """Test study index dataset.""" + from __future__ import annotations from gentropy.dataset.study_index import StudyIndex diff --git a/tests/gentropy/dataset/test_study_locus.py b/tests/gentropy/dataset/test_study_locus.py index 037ede068..c12597d54 100644 --- a/tests/gentropy/dataset/test_study_locus.py +++ b/tests/gentropy/dataset/test_study_locus.py @@ -1,4 +1,5 @@ """Test study locus dataset.""" + from __future__ import annotations from typing import Any diff --git a/tests/gentropy/dataset/test_study_locus_overlap.py b/tests/gentropy/dataset/test_study_locus_overlap.py index ca49fc067..53d87226c 100644 --- a/tests/gentropy/dataset/test_study_locus_overlap.py +++ b/tests/gentropy/dataset/test_study_locus_overlap.py @@ -1,4 +1,5 @@ """Test study locus overlap dataset.""" + from __future__ import annotations from gentropy.dataset.study_locus_overlap import StudyLocusOverlap diff --git a/tests/gentropy/dataset/test_study_locus_overlaps.py b/tests/gentropy/dataset/test_study_locus_overlaps.py index 6a812fb39..ee89eec84 100644 --- a/tests/gentropy/dataset/test_study_locus_overlaps.py +++ b/tests/gentropy/dataset/test_study_locus_overlaps.py @@ -1,4 +1,5 @@ """Test colocalisation dataset.""" + from __future__ import annotations from typing import TYPE_CHECKING, Any diff --git a/tests/gentropy/dataset/test_summary_statistics.py b/tests/gentropy/dataset/test_summary_statistics.py index b148994b6..9885181a8 100644 --- a/tests/gentropy/dataset/test_summary_statistics.py +++ b/tests/gentropy/dataset/test_summary_statistics.py @@ -1,4 +1,5 @@ """Test study index dataset.""" + from __future__ import annotations from typing import TYPE_CHECKING diff --git a/tests/gentropy/dataset/test_v2g.py b/tests/gentropy/dataset/test_v2g.py index e53395fe4..24a917508 100644 --- a/tests/gentropy/dataset/test_v2g.py +++ b/tests/gentropy/dataset/test_v2g.py @@ -1,4 +1,5 @@ """Tests V2G dataset.""" + from __future__ import annotations from typing import TYPE_CHECKING diff --git a/tests/gentropy/dataset/test_variant_annotation.py b/tests/gentropy/dataset/test_variant_annotation.py index 563d3c05c..05fa0cd60 100644 --- a/tests/gentropy/dataset/test_variant_annotation.py +++ b/tests/gentropy/dataset/test_variant_annotation.py @@ -1,4 +1,5 @@ """Tests variant annotation dataset.""" + from __future__ import annotations from typing import TYPE_CHECKING diff --git a/tests/gentropy/dataset/test_variant_index.py b/tests/gentropy/dataset/test_variant_index.py index c79a04092..a41db3031 100644 --- a/tests/gentropy/dataset/test_variant_index.py +++ b/tests/gentropy/dataset/test_variant_index.py @@ -1,4 +1,5 @@ """Tests on variant index generation.""" + from __future__ import annotations from typing import TYPE_CHECKING diff --git a/tests/gentropy/datasource/gwas_catalog/test_gwas_catalog_study_splitter.py b/tests/gentropy/datasource/gwas_catalog/test_gwas_catalog_study_splitter.py index 2955cee91..58bcb53c8 100644 --- a/tests/gentropy/datasource/gwas_catalog/test_gwas_catalog_study_splitter.py +++ b/tests/gentropy/datasource/gwas_catalog/test_gwas_catalog_study_splitter.py @@ -1,4 +1,5 @@ """Tests GWAS Catalog study splitter.""" + from __future__ import annotations from typing import TYPE_CHECKING, Any diff --git a/tests/gentropy/datasource/intervals/test_andersson.py b/tests/gentropy/datasource/intervals/test_andersson.py index b7283597b..09204967d 100644 --- a/tests/gentropy/datasource/intervals/test_andersson.py +++ b/tests/gentropy/datasource/intervals/test_andersson.py @@ -1,4 +1,5 @@ """Test Andersson Intervals.""" + from __future__ import annotations import pytest diff --git a/tests/gentropy/datasource/intervals/test_javierre.py b/tests/gentropy/datasource/intervals/test_javierre.py index be8c528e2..a6a74e94e 100644 --- a/tests/gentropy/datasource/intervals/test_javierre.py +++ b/tests/gentropy/datasource/intervals/test_javierre.py @@ -1,4 +1,5 @@ """Test JavierreIntervals.""" + from __future__ import annotations import pytest diff --git a/tests/gentropy/datasource/intervals/test_jung.py b/tests/gentropy/datasource/intervals/test_jung.py index 81506ae55..44062f680 100644 --- a/tests/gentropy/datasource/intervals/test_jung.py +++ b/tests/gentropy/datasource/intervals/test_jung.py @@ -1,4 +1,5 @@ """Test Jung Intervals.""" + from __future__ import annotations import pytest diff --git a/tests/gentropy/datasource/intervals/test_thurman.py b/tests/gentropy/datasource/intervals/test_thurman.py index f89c9d3da..853adb380 100644 --- a/tests/gentropy/datasource/intervals/test_thurman.py +++ b/tests/gentropy/datasource/intervals/test_thurman.py @@ -1,4 +1,5 @@ """Test Thurman.""" + from __future__ import annotations import pytest diff --git a/tests/gentropy/datasource/open_targets/test_l2g_gold_standard.py b/tests/gentropy/datasource/open_targets/test_l2g_gold_standard.py index 448e2a50c..0690781f5 100644 --- a/tests/gentropy/datasource/open_targets/test_l2g_gold_standard.py +++ b/tests/gentropy/datasource/open_targets/test_l2g_gold_standard.py @@ -1,4 +1,5 @@ """Test Open Targets L2G gold standards data source.""" + from __future__ import annotations from typing import TYPE_CHECKING diff --git a/tests/gentropy/datasource/open_targets/test_target.py b/tests/gentropy/datasource/open_targets/test_target.py index 33bb6ddc9..c0a92fcd7 100644 --- a/tests/gentropy/datasource/open_targets/test_target.py +++ b/tests/gentropy/datasource/open_targets/test_target.py @@ -1,4 +1,5 @@ """Test Open Targets target data source.""" + from __future__ import annotations from gentropy.dataset.gene_index import GeneIndex diff --git a/tests/gentropy/docs/test_applying_methods.py b/tests/gentropy/docs/test_applying_methods.py index 255752f46..cbfdb9155 100644 --- a/tests/gentropy/docs/test_applying_methods.py +++ b/tests/gentropy/docs/test_applying_methods.py @@ -1,4 +1,5 @@ """Testing applying methods docs.""" + from typing import Any import pytest diff --git a/tests/gentropy/docs/test_create_dataset.py b/tests/gentropy/docs/test_create_dataset.py index 663254753..2daae0c6a 100644 --- a/tests/gentropy/docs/test_create_dataset.py +++ b/tests/gentropy/docs/test_create_dataset.py @@ -1,4 +1,5 @@ """Testing creating dataset docs.""" + from typing import Any import pytest diff --git a/tests/gentropy/docs/test_creating_spark_session.py b/tests/gentropy/docs/test_creating_spark_session.py index 6e1cf1ca5..197d22d56 100644 --- a/tests/gentropy/docs/test_creating_spark_session.py +++ b/tests/gentropy/docs/test_creating_spark_session.py @@ -1,4 +1,5 @@ """Testing creating spark session docs.""" + from gentropy.common.session import Session from docs.src_snippets.howto.python_api.a_creating_spark_session import ( diff --git a/tests/gentropy/docs/test_inspect_dataset.py b/tests/gentropy/docs/test_inspect_dataset.py index daefa9793..38e258158 100644 --- a/tests/gentropy/docs/test_inspect_dataset.py +++ b/tests/gentropy/docs/test_inspect_dataset.py @@ -1,4 +1,5 @@ """Testing inspecting dataset docs.""" + from gentropy.dataset.summary_statistics import SummaryStatistics from pyspark.sql.types import StructType diff --git a/tests/gentropy/method/test_window_based_clumping.py b/tests/gentropy/method/test_window_based_clumping.py index 59bf0277a..03546df9d 100644 --- a/tests/gentropy/method/test_window_based_clumping.py +++ b/tests/gentropy/method/test_window_based_clumping.py @@ -1,4 +1,5 @@ """Test window-based clumping.""" + from __future__ import annotations from typing import TYPE_CHECKING diff --git a/tests/gentropy/step/test_clump_step.py b/tests/gentropy/step/test_clump_step.py index 701afc950..ab40de901 100644 --- a/tests/gentropy/step/test_clump_step.py +++ b/tests/gentropy/step/test_clump_step.py @@ -1,4 +1,5 @@ """Test clump step.""" + from __future__ import annotations import tempfile diff --git a/tests/gentropy/test_cli.py b/tests/gentropy/test_cli.py index 92effa840..5675713ce 100644 --- a/tests/gentropy/test_cli.py +++ b/tests/gentropy/test_cli.py @@ -1,4 +1,5 @@ """Test the command-line interface (CLI).""" + from unittest.mock import patch import pytest diff --git a/tests/gentropy/test_schemas.py b/tests/gentropy/test_schemas.py index 768a3d4df..417eb4657 100644 --- a/tests/gentropy/test_schemas.py +++ b/tests/gentropy/test_schemas.py @@ -1,4 +1,5 @@ """Tests on spark schemas.""" + from __future__ import annotations import json diff --git a/tests/gentropy/test_spark_helpers.py b/tests/gentropy/test_spark_helpers.py index 76abcbe56..a3790c62e 100644 --- a/tests/gentropy/test_spark_helpers.py +++ b/tests/gentropy/test_spark_helpers.py @@ -1,4 +1,5 @@ """Tests on helper spark functions.""" + from __future__ import annotations from typing import TYPE_CHECKING, Any