Skip to content

Commit

Permalink
chore: Update ruff lint configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Sep 16, 2024
1 parent 271bda3 commit ba0b029
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 1 addition & 3 deletions contracting_process/resource_level/reference/parties.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
20 changes: 5 additions & 15 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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")

Expand All @@ -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})
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 1 addition & 3 deletions pelican/util/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions pelican/util/currency_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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]

Expand Down
20 changes: 5 additions & 15 deletions pelican/util/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()


Expand Down
30 changes: 13 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
4 changes: 1 addition & 3 deletions time_variance/checks/ocid.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 1 addition & 3 deletions workers/check/data_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
4 changes: 1 addition & 3 deletions workers/check/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions workers/check/time_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 1 addition & 3 deletions workers/extract/dataset_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

@click.command()
def start():
"""
Create filtered datasets.
"""
"""Create filtered datasets."""
consume(on_message_callback=callback, queue=consume_routing_key)


Expand Down
4 changes: 1 addition & 3 deletions workers/extract/kingfisher_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 1 addition & 3 deletions workers/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions workers/wipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

@click.command()
def start():
"""
Delete datasets.
"""
"""Delete datasets."""
consume(on_message_callback=callback, queue=consume_routing_key)


Expand Down

0 comments on commit ba0b029

Please sign in to comment.