From f26c4e87a6a4ce09527ade4bdb0cf1fd8dd3f078 Mon Sep 17 00:00:00 2001 From: Matthieu Barba Date: Thu, 4 Jul 2024 15:03:28 +0100 Subject: [PATCH 1/3] Add ruff rules --- pyproject.toml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index c98ad0ca5..b49aaa31a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -173,6 +173,17 @@ disable = [ max-attributes = 12 max-branches = 15 +[tool.ruff] +line-length = 110 +show-fixes = true + +[tool.ruff.format] +docstring-code-format = true + +[tool.ruff.lint.per-file-ignores] +# Ignore `F403` (unable to detect undefined names) in all `__init__.py` files +"__init__.py" = ["F403"] + [tool.mypy] mypy_path = "src/python" explicit_package_bases = true From be407adf775ac3d26b7b643cb713dd732ee91e54 Mon Sep 17 00:00:00 2001 From: Matthieu Barba Date: Thu, 4 Jul 2024 15:03:42 +0100 Subject: [PATCH 2/3] Fix ruff checks --- src/python/ensembl/brc4/runnable/seqregion_parser.py | 1 - src/python/ensembl/io/genomio/assembly/download.py | 2 +- src/python/ensembl/io/genomio/genome_metadata/prepare.py | 8 ++++---- src/python/ensembl/io/genomio/genome_stats/dump.py | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/python/ensembl/brc4/runnable/seqregion_parser.py b/src/python/ensembl/brc4/runnable/seqregion_parser.py index 5ebb8fe69..f70e0992a 100644 --- a/src/python/ensembl/brc4/runnable/seqregion_parser.py +++ b/src/python/ensembl/brc4/runnable/seqregion_parser.py @@ -16,7 +16,6 @@ from pathlib import Path import re -import gzip import csv from typing import Any, Dict, Tuple diff --git a/src/python/ensembl/io/genomio/assembly/download.py b/src/python/ensembl/io/genomio/assembly/download.py index 8d98b2740..80faf4dac 100644 --- a/src/python/ensembl/io/genomio/assembly/download.py +++ b/src/python/ensembl/io/genomio/assembly/download.py @@ -194,7 +194,7 @@ def _download_file( """ has_md5 = True expected_sum = "" - if not ftp_file in md5_sums: + if ftp_file not in md5_sums: logging.warning(f" File not in the md5 checksums: {ftp_file}") has_md5 = False else: diff --git a/src/python/ensembl/io/genomio/genome_metadata/prepare.py b/src/python/ensembl/io/genomio/genome_metadata/prepare.py index fb9f051d8..c7eaca1fd 100644 --- a/src/python/ensembl/io/genomio/genome_metadata/prepare.py +++ b/src/python/ensembl/io/genomio/genome_metadata/prepare.py @@ -92,7 +92,7 @@ def add_provider(genome_metadata: Dict, ncbi_data: Dict) -> None: # Add assembly provider (if missing) assembly = genome_metadata["assembly"] - if (not "provider_name" in assembly) and (not "provider_url" in assembly): + if ("provider_name" not in assembly) and ("provider_url" not in assembly): assembly["provider_name"] = provider["assembly"]["provider_name"] assembly["provider_url"] = f'{provider["assembly"]["provider_url"]}/{accession}' @@ -111,7 +111,7 @@ def add_assembly_version(genome_data: Dict) -> None: genome_data: Genome information of assembly, accession and annotation. """ assembly = genome_data["assembly"] - if not "version" in assembly: + if "version" not in assembly: accession = assembly["accession"] version = accession.partition(".")[2] if version: @@ -128,9 +128,9 @@ def add_genebuild_metadata(genome_data: Dict) -> None: """ genebuild = genome_data.setdefault("genebuild", {}) current_date = datetime.date.today().isoformat() - if not "version" in genebuild: + if "version" not in genebuild: genebuild["version"] = current_date - if not "start_date" in genebuild: + if "start_date" not in genebuild: genebuild["start_date"] = current_date diff --git a/src/python/ensembl/io/genomio/genome_stats/dump.py b/src/python/ensembl/io/genomio/genome_stats/dump.py index 28a14b936..5951e0e7a 100644 --- a/src/python/ensembl/io/genomio/genome_stats/dump.py +++ b/src/python/ensembl/io/genomio/genome_stats/dump.py @@ -104,7 +104,7 @@ def get_feature_stats(self, table: Any) -> Dict[str, int]: totals_st = select(func.count(table.stable_id)) (total,) = session.execute(totals_st).one() # pylint: disable-next=singleton-comparison - no_desc_st = select(func.count(table.stable_id)).filter(table.description == None) + no_desc_st = select(func.count(table.stable_id)).filter(table.description is None) (no_desc,) = session.execute(no_desc_st).one() xref_desc_st = select(func.count(table.stable_id)).where(table.description.like("%[Source:%")) (xref_desc,) = session.execute(xref_desc_st).one() From 4fe02ce80f3e3692a18f36300f9193ad59494379 Mon Sep 17 00:00:00 2001 From: Matthieu Barba Date: Thu, 4 Jul 2024 15:10:41 +0100 Subject: [PATCH 3/3] use .is_(None) instead of == None --- src/python/ensembl/io/genomio/genome_stats/dump.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/ensembl/io/genomio/genome_stats/dump.py b/src/python/ensembl/io/genomio/genome_stats/dump.py index 5951e0e7a..7bc1ee197 100644 --- a/src/python/ensembl/io/genomio/genome_stats/dump.py +++ b/src/python/ensembl/io/genomio/genome_stats/dump.py @@ -104,7 +104,7 @@ def get_feature_stats(self, table: Any) -> Dict[str, int]: totals_st = select(func.count(table.stable_id)) (total,) = session.execute(totals_st).one() # pylint: disable-next=singleton-comparison - no_desc_st = select(func.count(table.stable_id)).filter(table.description is None) + no_desc_st = select(func.count(table.stable_id)).filter(table.description.is_(None)) (no_desc,) = session.execute(no_desc_st).one() xref_desc_st = select(func.count(table.stable_id)).where(table.description.like("%[Source:%")) (xref_desc,) = session.execute(xref_desc_st).one()