Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: update ruff #26

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: mixed-line-ending
args: [ --fix=lf ]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0 # ruff version
rev: v0.8.4 # ruff version
hooks:
- id: ruff-format
- id: ruff
Expand Down
17 changes: 11 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dynamic = ["version"]

[project.optional-dependencies]
tests = ["pytest", "pytest-cov", "requests-mock"]
dev = ["pre-commit>=3.7.1", "ruff==0.5.0"]
dev = ["pre-commit>=3.7.1", "ruff==0.8.4"]


[project.urls]
Expand Down Expand Up @@ -82,10 +82,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
Expand All @@ -104,13 +108,14 @@ fixable = [
"PT",
"RSE",
"SIM",
"PLC",
"PLE",
"TRY",
"PERF",
"FURB",
"RUF"
]
# 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 @@ -124,19 +129,20 @@ 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
# S101 - assert
Expand All @@ -146,7 +152,6 @@ ignore = [
"tests/*" = [
"ANN001",
"ANN2",
"ANN102",
"D100",
"D102",
"D103",
Expand Down
14 changes: 7 additions & 7 deletions src/regbot/fetch/clinical_trials.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _get_dt_object(raw_date: str) -> datetime.datetime:
)
except ValueError as e:
msg = f"Unable to format {raw_date} as YYYY-MM-DD, YYYY-MM, or YYYY"
_logger.error(msg)
_logger.exception(msg)
raise ValueError(msg) from e


Expand Down Expand Up @@ -1011,21 +1011,21 @@ def make_fda_clinical_trials_request(
with requests.get(formatted_url, timeout=30) as r:
try:
r.raise_for_status()
except RequestException as e:
_logger.warning(
except RequestException:
_logger.exception(
"Request to %s returned status code %s", url, r.status_code
)
raise e
raise
raw_data = r.json()
for i, study in enumerate(raw_data.get("studies", [])):
try:
parsed_data = _format_study(study)
except ValueError as e:
except ValueError:
if skip_parsing_failures:
nct_id = _get_id(study, formatted_url, i)
_logger.warning("Failed to parse study %s: %s", nct_id, e)
_logger.exception("Failed to parse study %s", nct_id)
continue
raise e
raise
results.append(parsed_data)

next_page_token = raw_data.get("nextPageToken")
Expand Down
12 changes: 6 additions & 6 deletions src/regbot/fetch/drugsfda.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def _enumify(value: str | None, CandidateEnum: type[Enum]) -> Enum | str | None:
.replace("/", "_")
)
except ValueError:
_logger.error(
_logger.exception(
"Unable to enumify value '%s' into enum '%s'", value, CandidateEnum
)
return value
Expand All @@ -458,15 +458,15 @@ def _intify(value: str) -> int | None:
try:
return int(value)
except ValueError:
_logger.error("Cannot convert value '%s' to int", value)
_logger.exception("Cannot convert value '%s' to int", value)
return None


def _make_datetime(value: str) -> datetime.datetime | None:
try:
return datetime.datetime.strptime(value, "%Y%m%d").replace(tzinfo=datetime.UTC)
except ValueError:
_logger.error("Unable to convert value '%s' to datetime", value)
_logger.exception("Unable to convert value '%s' to datetime", value)
return None


Expand Down Expand Up @@ -654,11 +654,11 @@ def make_drugsatfda_request(
with requests.get(full_url, timeout=30) as r:
try:
r.raise_for_status()
except RequestException as e:
_logger.warning(
except RequestException:
_logger.exception(
"Request to %s returned status code %s", full_url, r.status_code
)
raise e
raise
data = r.json()
results += data["results"]
skip = data["meta"]["results"]["skip"] + len(data["results"])
Expand Down
8 changes: 5 additions & 3 deletions src/regbot/fetch/rxclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ def make_rxclass_request(
with requests.get(url, timeout=30) as r:
try:
r.raise_for_status()
except RequestException as e:
_logger.warning("Request to %s returned status code %s", url, r.status_code)
raise e
except RequestException:
_logger.exception(
"Request to %s returned status code %s", url, r.status_code
)
raise
raw_data = r.json()
if not raw_data:
return []
Expand Down
Loading