Skip to content

Commit

Permalink
style: add ruff updates (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson authored Feb 1, 2024
1 parent cefa1ac commit dd61a2e
Show file tree
Hide file tree
Showing 41 changed files with 821 additions and 842 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.1.6
rev: v0.1.14
hooks:
- id: ruff-format
- id: ruff
Expand Down
64 changes: 52 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dynamic = ["version"]
[project.optional-dependencies]
etl = ["disease-normalizer[etl]~=0.4.0.dev0", "owlready2", "rdflib", "wikibaseintegrator>=0.12.0", "wags-tails"]
test = ["pytest", "pytest-cov", "pytest-mock"]
dev = ["pre-commit", "ruff>=0.1.2", "lxml", "xmlformatter", "mypy", "types-pyyaml"]
dev = ["pre-commit", "ruff>=0.1.14", "lxml", "xmlformatter", "mypy", "types-pyyaml"]

[project.urls]
Homepage = "https://github.com/cancervariants/therapy-normalization"
Expand Down Expand Up @@ -76,15 +76,49 @@ ignore_missing_imports = true

[tool.ruff]
src = ["src"]
# pycodestyle (E, W)
# Pyflakes (F)
# flake8-annotations (ANN)
# pydocstyle (D)
# pep8-naming (N)
# isort (I)
select = ["E", "W", "F", "ANN", "D", "N", "I"]
fixable = ["I", "F401"]

select = [
"F", # https://docs.astral.sh/ruff/rules/#pyflakes-f
"E", "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"I", # https://docs.astral.sh/ruff/rules/#isort-i
"N", # https://docs.astral.sh/ruff/rules/#pep8-naming-n
"D", # https://docs.astral.sh/ruff/rules/#pydocstyle-d
"UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up
"ANN", # https://docs.astral.sh/ruff/rules/#flake8-annotations-ann
"ASYNC", # https://docs.astral.sh/ruff/rules/#flake8-async-async
"S", # https://docs.astral.sh/ruff/rules/#flake8-bandit-s
"B", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
"A", # https://docs.astral.sh/ruff/rules/#flake8-builtins-a
"C4", # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
"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
"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
"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
"SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
"PGH", # https://docs.astral.sh/ruff/rules/#pygrep-hooks-pgh
"RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
]
fixable = [
"I",
"F401",
"D",
"UP",
"ANN",
"B",
"C4",
"G",
"PIE",
"PT",
"RSE",
"SIM",
"RUF"
]
# ANN101 - missing-type-self
# ANN003 - missing-type-kwargs
# D203 - one-blank-line-before-class
Expand All @@ -99,12 +133,14 @@ fixable = ["I", "F401"]
# E117 - over-indented*
# E501 - line-too-long*
# W191 - tab-indentation*
# PGH003 - blanket-type-ignore
# *ignored for compatibility with formatter
ignore = [
"ANN101", "ANN003",
"D203", "D205", "D206", "D213", "D300", "D400", "D415",
"E111", "E114", "E117", "E501",
"W191"
"W191",
"PGH003",
]

[tool.ruff.per-file-ignores]
Expand All @@ -113,5 +149,9 @@ ignore = [
# ANN201 - Missing type annotation
# ANN102 - missing-type-cls
# N805 - invalid-first-argument-name-for-method
"tests/*" = ["ANN001", "ANN102", "ANN2"]
# S101 - assert
# B011 - assert-false
# RUF001 - ambiguous-unicode-character-string
"tests/*" = ["ANN001", "ANN102", "ANN2", "S101", "B011"]
"tests/unit/test_emit_warnings.py" = ["RUF001"]
"src/therapy/schemas.py" = ["ANN001", "ANN201", "N805"]
8 changes: 4 additions & 4 deletions src/therapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
APP_ROOT: Path = Path(__file__).resolve().parents[0]


from therapy.schemas import ( # noqa: E402, I100, I202
from therapy.schemas import ( # noqa: E402
NamespacePrefix,
RefType,
SourceName,
Expand All @@ -29,7 +29,7 @@
PREFIX_LOOKUP = {
v.value: SourceName[k].value
for k, v in NamespacePrefix.__members__.items()
if k in SourceName.__members__.keys()
if k in SourceName.__members__
}

# Namespace LUI patterns. Use for namespace inference.
Expand All @@ -43,7 +43,7 @@
)

# Sources that we import directly
XREF_SOURCES = {source for source in SourceName.__members__}
XREF_SOURCES = set(SourceName.__members__)

# Sources that are found in data from imported sources
ASSOC_WITH_SOURCES = {source for source in NamespacePrefix.__members__} - XREF_SOURCES
ASSOC_WITH_SOURCES = set(NamespacePrefix.__members__) - XREF_SOURCES
10 changes: 6 additions & 4 deletions src/therapy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _load_source(
f"Encountered ModuleNotFoundError attempting to import {e.name}. Are ETL dependencies installed?"
)
click.get_current_context().exit()
SourceClass = eval(name.value) # noqa: N806
SourceClass = eval(name.value) # noqa: N806 PGH001 S307

source = SourceClass(database=db, silent=False)
try:
Expand Down Expand Up @@ -177,7 +177,7 @@ def _update_normalizer(
:param use_existing: if True, use most recent local version of source data instead of
fetching from remote
"""
processed_ids: List[str] = list()
processed_ids: List[str] = []
for n in sources:
delete_time = _delete_source(n, db)
_load_source(n, db, delete_time, processed_ids, use_existing)
Expand Down Expand Up @@ -255,12 +255,14 @@ def update_normalizer_db(
sources_split = sources.lower().split()

if len(sources_split) == 0:
raise Exception("Must enter 1 or more source names to update")
msg = "Must enter 1 or more source names to update"
raise Exception(msg)

non_sources = set(sources_split) - set(SOURCES)

if len(non_sources) != 0:
raise Exception(f"Not valid source(s): {non_sources}")
msg = f"Not valid source(s): {non_sources}"
raise Exception(msg)

parsed_source_names = {SourceName(SOURCES[s]) for s in sources_split}
if (
Expand Down
10 changes: 4 additions & 6 deletions src/therapy/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@ def _check_delete_okay() -> bool:
"""
if environ.get(AWS_ENV_VAR_NAME) == AwsEnvName.PRODUCTION:
if environ.get(SKIP_AWS_DB_ENV_NAME) == "true":
raise DatabaseWriteError(
f"Must unset {SKIP_AWS_DB_ENV_NAME} env variable to enable drop_db()"
)
msg = f"Must unset {SKIP_AWS_DB_ENV_NAME} env variable to enable drop_db()"
raise DatabaseWriteError(msg)
return click.confirm("Are you sure you want to delete existing data?")
else:
return True
return True

@abc.abstractmethod
def drop_db(self) -> None:
Expand Down Expand Up @@ -347,7 +345,7 @@ def create_db(
else:
if db_url:
endpoint_url = db_url
elif "THERAPY_NORM_DB_URL" in environ.keys():
elif "THERAPY_NORM_DB_URL" in environ:
endpoint_url = environ["THERAPY_NORM_DB_URL"]
else:
endpoint_url = "http://localhost:8000"
Expand Down
Loading

0 comments on commit dd61a2e

Please sign in to comment.