Skip to content

Commit

Permalink
style: update ruff to 0.5.0 (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
korikuzma authored Jul 15, 2024
1 parent 96de0c9 commit 7001b31
Show file tree
Hide file tree
Showing 37 changed files with 203 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
hooks:
- id: ruff-format
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ matplotlib = "*"
lxml = "*"
xmlformatter = "*"
psycopg = {version = "*", extras=["binary"]}
ruff = "*"
ruff = "==0.5.0"
httpx = "*"

[packages]
Expand Down
35 changes: 29 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dynamic = ["version"]
pg = ["psycopg[binary]", "requests"]
etl = ["owlready2==0.40", "rdflib", "wags-tails>=0.1.2", "fastobo", "tqdm"]
test = ["pytest>=6.0", "pytest-cov", "httpx"]
dev = ["pre-commit", "ruff==0.2.0", "lxml", "xmlformatter"]
dev = ["pre-commit", "ruff==0.5.0", "lxml", "xmlformatter"]
docs = [
"sphinx==6.1.3",
"sphinx-autodoc-typehints==1.22.0",
Expand Down Expand Up @@ -103,16 +103,22 @@ 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
"G", # https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
"INP", # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp
"PIE", # https://docs.astral.sh/ruff/rules/#flake8-pie-pie
"T20", # https://docs.astral.sh/ruff/rules/#flake8-print-t20
"PT", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
"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 = [
Expand All @@ -123,15 +129,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*
Expand All @@ -144,21 +154,34 @@ fixable = [
# E117 - over-indented*
# E501 - line-too-long*
# W191 - tab-indentation*
# 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"
"W191",
"S321",
]

[tool.ruff.lint.per-file-ignores]
# ANN001 - missing-type-function-argument
# ANN2 - missing-return-type
# ANN102 - missing-type-cls
# F401 - unused-import
# N805 - invalid-first-argument-name-for-method
# S101 - assert
# RUF001 - ambiguous-unicode-character-string
"tests/*" = ["ANN001", "ANN2", "ANN102", "S101"]
# D100 - undocumented-public-module
# D103 - undocumented-public-function
# I001 - unsorted-imports
# INP001 - implicit-namespace-package
# ARG001 - unused-function-argument
# SLF001 - private-member-acces
"tests/*" = ["ANN001", "ANN2", "ANN102", "S101", "INP001", "SLF001", "ARG001"]
"*__init__.py" = ["F401"]
"tests/unit/test_emit_warnings.py" = ["RUF001"]
"src/disease/schemas.py" = ["ANN201", "N805", "ANN001"]
"docs/source/conf.py" = ["D100", "I001", "D103", "ANN201", "ANN001"]

[tool.ruff.format]
docstring-code-format = true
3 changes: 2 additions & 1 deletion src/disease/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""The VICC library for normalizing diseases."""

from pathlib import Path

from .version import __version__ # noqa: F401
from .version import __version__

APP_ROOT = Path(__file__).resolve().parents[0]

Expand Down
9 changes: 5 additions & 4 deletions src/disease/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Provides a CLI util to make updates to normalizer database."""

import logging
import os
from collections.abc import Collection
from pathlib import Path
from timeit import default_timer as timer
from typing import Collection, List, Optional, Set

import click

Expand Down Expand Up @@ -61,7 +62,7 @@ def check_db(db_url: str, verbose: bool = False) -> None:
@click.command()
@click.option("--data_url", help="URL to data dump")
@click.option("--db_url", help="URL endpoint for the application database.")
def update_from_remote(data_url: Optional[str], db_url: str) -> None:
def update_from_remote(data_url: str | None, db_url: str) -> None:
"""Update data from remotely-hosted DB dump. By default, fetches from latest
available dump on VICC S3 bucket; specific URLs can be provided instead by
command line option or DISEASE_NORM_REMOTE_DB_URL environment variable.
Expand Down Expand Up @@ -170,7 +171,7 @@ def _load_source(
n: SourceName,
db: AbstractDatabase,
delete_time: float,
processed_ids: List[str],
processed_ids: list[str],
from_local: bool,
) -> None:
"""Load individual source data.
Expand Down Expand Up @@ -225,7 +226,7 @@ def _delete_normalized_data(database: AbstractDatabase) -> None:
click.echo(f"Deleted normalized records in {delete_time:.5f} seconds.")


def _load_merge(db: AbstractDatabase, processed_ids: Set[str]) -> None:
def _load_merge(db: AbstractDatabase, processed_ids: set[str]) -> None:
"""Load merged concepts
:param db: database instance
Expand Down
1 change: 1 addition & 0 deletions src/disease/database/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provide database clients."""

from .database import (
AWS_ENV_VAR_NAME,
AbstractDatabase,
Expand Down
28 changes: 14 additions & 14 deletions src/disease/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
:py:meth:`~disease.database.database.create_db` is the recommended way to create a
database connection.
"""

import abc
import sys
from collections.abc import Generator
from enum import Enum
from os import environ
from pathlib import Path
from typing import Any, Dict, Generator, List, Optional, Set, Union
from typing import Any

import click

Expand All @@ -36,7 +38,7 @@ class AbstractDatabase(abc.ABC):
"""Define a database interface."""

@abc.abstractmethod
def __init__(self, db_url: Optional[str] = None, **db_args) -> None:
def __init__(self, db_url: str | None = None, **db_args) -> None:
"""Initialize database instance.
Generally, implementing classes should be able to construct a connection by
Expand All @@ -49,7 +51,7 @@ def __init__(self, db_url: Optional[str] = None, **db_args) -> None:
"""

@abc.abstractmethod
def list_tables(self) -> List[str]:
def list_tables(self) -> list[str]:
"""Return names of tables in database.
:return: Table names in database
Expand Down Expand Up @@ -106,9 +108,7 @@ def initialize_db(self) -> None:
"""

@abc.abstractmethod
def get_source_metadata(
self, src_name: Union[str, SourceName]
) -> Optional[SourceMeta]:
def get_source_metadata(self, src_name: str | SourceName) -> SourceMeta | None:
"""Get license, versioning, data lookup, etc information for a source.
:param src_name: name of the source to get data for
Expand All @@ -118,7 +118,7 @@ def get_source_metadata(
@abc.abstractmethod
def get_record_by_id(
self, concept_id: str, case_sensitive: bool = True, merge: bool = False
) -> Optional[Dict]:
) -> dict | None:
"""Fetch record corresponding to provided concept ID
:param concept_id: concept ID for record
Expand All @@ -130,7 +130,7 @@ def get_record_by_id(
"""

@abc.abstractmethod
def get_refs_by_type(self, search_term: str, ref_type: RefType) -> List[str]:
def get_refs_by_type(self, search_term: str, ref_type: RefType) -> list[str]:
"""Retrieve concept IDs for records matching the user's query. Other methods
are responsible for actually retrieving full records.
Expand All @@ -140,15 +140,15 @@ def get_refs_by_type(self, search_term: str, ref_type: RefType) -> List[str]:
"""

@abc.abstractmethod
def get_all_concept_ids(self, source: Optional[SourceName] = None) -> Set[str]:
def get_all_concept_ids(self, source: SourceName | None = None) -> set[str]:
"""Retrieve all available concept IDs for use in generating normalized records.
:param source: optionally, just get all IDs for a specific source
:return: Set of concept IDs as strings.
"""

@abc.abstractmethod
def get_all_records(self, record_type: RecordType) -> Generator[Dict, None, None]:
def get_all_records(self, record_type: RecordType) -> Generator[dict, None, None]:
"""Retrieve all source or normalized records. Either return all source records,
or all records that qualify as "normalized" (i.e., merged groups + source
records that are otherwise ungrouped).
Expand Down Expand Up @@ -176,15 +176,15 @@ def add_source_metadata(self, src_name: SourceName, meta: SourceMeta) -> None:
"""

@abc.abstractmethod
def add_record(self, record: Dict, src_name: SourceName) -> None:
def add_record(self, record: dict, src_name: SourceName) -> None:
"""Add new record to database.
:param record: record to upload
:param src_name: name of source for record.
"""

@abc.abstractmethod
def add_merged_record(self, record: Dict) -> None:
def add_merged_record(self, record: dict) -> None:
"""Add merged record to database.
:param record: merged record to add
Expand Down Expand Up @@ -228,7 +228,7 @@ def close_connection(self) -> None:
"""Perform any manual connection closure procedures if necessary."""

@abc.abstractmethod
def load_from_remote(self, url: Optional[str] = None) -> None:
def load_from_remote(self, url: str | None = None) -> None:
"""Load DB from remote dump. Warning: Deletes all existing data.
:param url: remote location to retrieve gzipped dump file from
Expand Down Expand Up @@ -276,7 +276,7 @@ def confirm_aws_db_use(env_name: str) -> None:


def create_db(
db_url: Optional[str] = None, aws_instance: bool = False
db_url: str | None = None, aws_instance: bool = False
) -> AbstractDatabase:
"""Database factory method. Checks environment variables and provided parameters
and creates a DB instance.
Expand Down
Loading

0 comments on commit 7001b31

Please sign in to comment.