From ba0b029158bd20cf25e6e234052ef217ee5656ea Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Mon, 16 Sep 2024 11:42:37 -0400 Subject: [PATCH] chore: Update ruff lint configuration --- .../coherent/milestone_status.py | 4 +-- ...ocurement_method_vs_number_of_tenderers.py | 4 +-- .../reference/contract_in_awards.py | 4 +-- .../resource_level/reference/parties.py | 4 +-- manage.py | 20 ++++--------- pelican/util/checks.py | 4 +-- pelican/util/currency_converter.py | 8 ++--- pelican/util/services.py | 20 ++++--------- pyproject.toml | 30 ++++++++----------- time_variance/checks/ocid.py | 4 +-- workers/check/data_item.py | 4 +-- workers/check/dataset.py | 4 +-- workers/check/time_based.py | 4 +-- workers/extract/dataset_filter.py | 4 +-- workers/extract/kingfisher_process.py | 4 +-- workers/report.py | 4 +-- workers/wipe.py | 4 +-- 17 files changed, 38 insertions(+), 92 deletions(-) diff --git a/contracting_process/resource_level/coherent/milestone_status.py b/contracting_process/resource_level/coherent/milestone_status.py index 91ca15e8..2db531fb 100644 --- a/contracting_process/resource_level/coherent/milestone_status.py +++ b/contracting_process/resource_level/coherent/milestone_status.py @@ -1,6 +1,4 @@ -""" -If a milestone's ``status`` is unmet ('scheduled' or 'notMet'), then its ``dateMet`` is blank. -""" +"""If a milestone's ``status`` is unmet ('scheduled' or 'notMet'), then its ``dateMet`` is blank.""" from pelican.util.checks import complete_result_resource, get_empty_result_resource from pelican.util.getter import deep_get, get_values diff --git a/contracting_process/resource_level/coherent/procurement_method_vs_number_of_tenderers.py b/contracting_process/resource_level/coherent/procurement_method_vs_number_of_tenderers.py index 5a0e314f..84df4556 100644 --- a/contracting_process/resource_level/coherent/procurement_method_vs_number_of_tenderers.py +++ b/contracting_process/resource_level/coherent/procurement_method_vs_number_of_tenderers.py @@ -1,6 +1,4 @@ -""" -If the ``tender.procurementMethod`` is 'direct', then the ``tender.numberOfTenderers`` is at most 1. -""" +"""If the ``tender.procurementMethod`` is 'direct', then the ``tender.numberOfTenderers`` is at most 1.""" from pelican.util.checks import complete_result_resource_pass_fail, get_empty_result_resource from pelican.util.getter import deep_get diff --git a/contracting_process/resource_level/reference/contract_in_awards.py b/contracting_process/resource_level/reference/contract_in_awards.py index 3b24c059..82c181b1 100644 --- a/contracting_process/resource_level/reference/contract_in_awards.py +++ b/contracting_process/resource_level/reference/contract_in_awards.py @@ -1,6 +1,4 @@ -""" -Each contract's ``awardID`` is present and matches the ``id`` of exactly one award. -""" +"""Each contract's ``awardID`` is present and matches the ``id`` of exactly one award.""" from collections import Counter diff --git a/contracting_process/resource_level/reference/parties.py b/contracting_process/resource_level/reference/parties.py index 636043b0..8d22b36d 100644 --- a/contracting_process/resource_level/reference/parties.py +++ b/contracting_process/resource_level/reference/parties.py @@ -1,6 +1,4 @@ -""" -Each referencing ``id`` is present and matches the ``id`` of exactly one party. -""" +"""Each referencing ``id`` is present and matches the ``id`` of exactly one party.""" from collections import Counter diff --git a/manage.py b/manage.py index 0e0d9511..ee320518 100755 --- a/manage.py +++ b/manage.py @@ -12,9 +12,7 @@ def cli(): @cli.command() def update_exchange_rates(): - """ - Update the exchange rates. - """ + """Update the exchange rates.""" if settings.FIXER_IO_API_KEY: exchange_rates_db.update_from_fixer_io() @@ -25,9 +23,7 @@ def update_exchange_rates(): @click.option("--previous-dataset", type=int, help="ID of previous dataset for time-based checks.") @click.option("--sample", type=int, help="Number of compiled releases to import.") def add(name, collection_id, previous_dataset, sample): - """ - Create a dataset. - """ + """Create a dataset.""" message = {"name": name, "collection_id": collection_id, "ancestor_id": previous_dataset, "max_items": sample} publish(message, "ocds_kingfisher_extractor_init") @@ -37,9 +33,7 @@ def add(name, collection_id, previous_dataset, sample): @click.option("--include-filtered", is_flag=True, help="Remove its filtered datasets.") @click.option("--force", is_flag=True, help="Forcefully remove the dataset.") def remove(dataset_id, include_filtered, force): - """ - Delete a dataset. - """ + """Delete a dataset.""" cursor = get_cursor() cursor.execute("SELECT EXISTS (SELECT 1 FROM dataset WHERE id = %(id)s)", {"id": dataset_id}) @@ -179,17 +173,13 @@ def remove(dataset_id, include_filtered, force): @cli.group() def dev(): - """ - Commands for administrators and developers of Pelican backend. - """ + """Commands for administrators and developers of Pelican backend.""" @dev.command() @click.argument("dataset_id", type=int) def restart_dataset_check(dataset_id): - """ - Restart the dataset check if the check.dataset worker failed. - """ + """Restart the dataset check if the check.dataset worker failed.""" update_dataset_state(dataset_id, Phase.CONTRACTING_PROCESS, State.OK) commit() diff --git a/pelican/util/checks.py b/pelican/util/checks.py index b5101955..8b700194 100644 --- a/pelican/util/checks.py +++ b/pelican/util/checks.py @@ -52,9 +52,7 @@ def get_empty_result_time_based(version: float = 1.0) -> dict[str, Any]: def get_empty_result_time_based_scope() -> dict[str, Any]: - """ - Initialize a time-based check result accumulator. - """ + """Initialize a time-based check result accumulator.""" return { "total_count": 0, "coverage_count": 0, diff --git a/pelican/util/currency_converter.py b/pelican/util/currency_converter.py index 05dc63a4..ecfff5ee 100644 --- a/pelican/util/currency_converter.py +++ b/pelican/util/currency_converter.py @@ -69,9 +69,7 @@ def import_data(data: list[tuple[datetime.date, dict[str, float]]]) -> None: def interpolation_closest(currency, start_date, end_date): - """ - start_date and end_date are exclusive. - """ + """start_date and end_date are exclusive.""" start_date_rate = rates[start_date][currency] end_date_rate = rates[end_date][currency] @@ -102,9 +100,7 @@ def interpolation_closest(currency, start_date, end_date): def interpolation_linear(currency, start_date, end_date): - """ - start_date and end_date are exclusive. - """ + """start_date and end_date are exclusive.""" start_date_rate = rates[start_date][currency] end_date_rate = rates[end_date][currency] diff --git a/pelican/util/services.py b/pelican/util/services.py index 5936cbcb..1740a0a3 100644 --- a/pelican/util/services.py +++ b/pelican/util/services.py @@ -49,17 +49,13 @@ def decode(body: bytes, content_type: str | None) -> Any: def consume(*args: Any, prefetch_count=1, **kwargs: Any) -> None: - """ - Consume messages from RabbitMQ. - """ + """Consume messages from RabbitMQ.""" client = AsyncConsumer(*args, prefetch_count=prefetch_count, **kwargs, **YAPW_KWARGS) client.start() def publish(*args: Any, **kwargs: Any) -> None: - """ - Publish a message to RabbitMQ. - """ + """Publish a message to RabbitMQ.""" client = Blocking(**YAPW_KWARGS) try: client.publish(*args, **kwargs) @@ -78,9 +74,7 @@ def dumps(self, obj): def get_cursor(name="") -> psycopg2.extensions.cursor: - """ - Connect to the database, if needed, and return a database cursor. - """ + """Connect to the database, if needed, and return a database cursor.""" global db_connected, db_connection, db_cursor_idx # noqa: PLW0603 if not db_connected: db_connection = psycopg2.connect(settings.DATABASE_URL) @@ -99,16 +93,12 @@ def get_cursor(name="") -> psycopg2.extensions.cursor: def commit() -> None: - """ - Commit the transaction. - """ + """Commit the transaction.""" db_connection.commit() def rollback() -> None: - """ - Rollback the transaction. - """ + """Rollback the transaction.""" db_connection.rollback() diff --git a/pyproject.toml b/pyproject.toml index a04e6af1..dfbe5470 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,28 +9,24 @@ target-version = "py311" [tool.ruff.lint] select = ["ALL"] ignore = [ - "ANN", "COM", "EM", - # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules - "W191", "D206", "Q000", "Q001", "Q002", "Q003", "ISC001", - "D203", "D212", # ignore incompatible rules - "D200", # documentation preferences - "C901", "PLR091", # complexity preferences - "D1", # docstrings - "PTH", # pathlib - "ARG001", # yapw callbacks - "DTZ001", "DTZ007", # allow naive datetimes from JSON data - "PLR2004", # magic values + "ANN", "C901", "COM812", "D203", "D212", "D415", "EM", "PERF203", "PLR091", "Q000", + "ARG001", # pika + "D1", + "DTZ", + "PLR2004", # magic + "PTH", + "D200", # https://github.com/astral-sh/ruff/issues/6269 ] [tool.ruff.lint.flake8-builtins] builtins-ignorelist = ["copyright"] +[tool.ruff.lint.flake8-unused-arguments] +ignore-variadic-names = true + [tool.ruff.lint.per-file-ignores] -"docs/conf.py" = ["INP001"] # no __init__.py file +"docs/conf.py" = ["D100", "INP001"] "tests/*" = [ - "D", # docstring - "PLR2004", # Magic value used - "PT009", # unittest asserts - "RUF012", # unittest attributes - "S101", # assert + "ARG001", "D", "FBT003", "INP001", "PLR2004", "S", "TRY003", + "RUF012", # examples ] diff --git a/time_variance/checks/ocid.py b/time_variance/checks/ocid.py index 2d1fb679..475d6b02 100644 --- a/time_variance/checks/ocid.py +++ b/time_variance/checks/ocid.py @@ -1,6 +1,4 @@ -""" -All OCIDs in an older collection of a data source are present in this newer collection of the same source. -""" +"""All OCIDs in an older collection of a data source are present in this newer collection of the same source.""" version = 1.0 diff --git a/workers/check/data_item.py b/workers/check/data_item.py index d16cc86b..4e617e6f 100644 --- a/workers/check/data_item.py +++ b/workers/check/data_item.py @@ -13,9 +13,7 @@ @click.command() def start(): - """ - Perform the field-level and compiled release-level checks. - """ + """Perform the field-level and compiled release-level checks.""" bootstrap() consume(on_message_callback=callback, queue=consume_routing_key, prefetch_count=multiprocessing.cpu_count()) diff --git a/workers/check/dataset.py b/workers/check/dataset.py index 8f802911..77538510 100644 --- a/workers/check/dataset.py +++ b/workers/check/dataset.py @@ -25,9 +25,7 @@ @click.command() def start(): - """ - Perform the dataset-level checks. - """ + """Perform the dataset-level checks.""" bootstrap() consume(on_message_callback=callback, queue=consume_routing_key) diff --git a/workers/check/time_based.py b/workers/check/time_based.py index cf897938..4dab677a 100644 --- a/workers/check/time_based.py +++ b/workers/check/time_based.py @@ -11,9 +11,7 @@ @click.command() def start(): - """ - Perform the time-based checks. - """ + """Perform the time-based checks.""" consume(on_message_callback=callback, queue=consume_routing_key) diff --git a/workers/extract/dataset_filter.py b/workers/extract/dataset_filter.py index b7660967..964bc1fe 100644 --- a/workers/extract/dataset_filter.py +++ b/workers/extract/dataset_filter.py @@ -14,9 +14,7 @@ @click.command() def start(): - """ - Create filtered datasets. - """ + """Create filtered datasets.""" consume(on_message_callback=callback, queue=consume_routing_key) diff --git a/workers/extract/kingfisher_process.py b/workers/extract/kingfisher_process.py index 4e3bdccf..047dc1ce 100644 --- a/workers/extract/kingfisher_process.py +++ b/workers/extract/kingfisher_process.py @@ -16,9 +16,7 @@ @click.command() def start(): - """ - Extract collections from Kingfisher Process. - """ + """Extract collections from Kingfisher Process.""" consume(on_message_callback=callback, queue=consume_routing_key) diff --git a/workers/report.py b/workers/report.py index d71bbc1a..effb0874 100644 --- a/workers/report.py +++ b/workers/report.py @@ -16,9 +16,7 @@ @click.command() def start(): - """ - Create reports, pick examples, and update dataset metadata. - """ + """Create reports, pick examples, and update dataset metadata.""" consume( on_message_callback=callback, queue=consume_routing_key, diff --git a/workers/wipe.py b/workers/wipe.py index 1b0e5b86..9f76da53 100644 --- a/workers/wipe.py +++ b/workers/wipe.py @@ -8,9 +8,7 @@ @click.command() def start(): - """ - Delete datasets. - """ + """Delete datasets.""" consume(on_message_callback=callback, queue=consume_routing_key)