Skip to content

Commit

Permalink
chore: Run ruff check .
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Sep 14, 2024
1 parent 295b9eb commit ea305fe
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion dataset/unique/tender_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_result(scope):

for tender_id, items in scope.items():
# Pick the "main" item that others repeat, at random.
item = random.choice(items)
item = random.choice(items) # noqa: S311
sample = {"tender_id": tender_id, "ocid": item["ocid"], "item_id": item["item_id"], "all_items": items}
repetitions = len(items)
if repetitions == 1:
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Compiled release-level checks
Dataset-level checks
No results for ``add_item\((?!\w+, \w+(\[\w+\])?, \w+( \+ \d+)?\))``
Time-based checks
No results for ``\b(filter|evaluate)\((?!\w+, \w+, \w+, \w+, \w+\))``
No results for ``\b(applicable|evaluate)\((?!\w+, \w+, \w+, \w+, \w+\))``

Any exceptions to the above must be moved to the global scope, or manually validated.

Expand Down
8 changes: 4 additions & 4 deletions docs/tasks/checks/time-based.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ Time-based
:start-after: definitions
:end-at: phase_stable

Each check is an object (usually a module) that has two attributes: ``filter`` and ``evaluate``.
Each check is an object (usually a module) that has two attributes: ``applicable`` and ``evaluate``.

Pairs of items with the same ocid are read in batches from the dataset and its ancestor. Each item is passed to the ``filter`` function, which:
Pairs of items with the same ocid are read in batches from the dataset and its ancestor. Each item is passed to the ``applicable`` function, which:

#. Accepts five arguments: an accumulator, an ancestor's item and its ID, and a dataset's item and its ID
#. Returns whether the check can be calculated against the pair of items (for example, if both are present)

If ``filter`` returns ``True``, and if the new item is present, then the ``evaluate`` function:
If ``applicable`` returns ``True``, and if the new item is present, then the ``evaluate`` function:

#. Accepts five arguments, like ``filter``
#. Accepts five arguments, like ``applicable``
#. Determines whether the check passes
#. Returns the accumulator, and whether the check passes

Expand Down
12 changes: 9 additions & 3 deletions pelican/util/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def complete_result_resource(


def complete_result_resource_pass_fail(
result: dict[str, Any], passed: bool, meta: dict[str, Any] | None = None
result: dict[str, Any],
passed: bool, # noqa: FBT001
meta: dict[str, Any] | None = None,
) -> dict[str, Any]:
"""
Build a compiled release-level check result, for a pass-fail check.
Expand Down Expand Up @@ -239,7 +241,11 @@ def _empty_field_result(name: str, version: float = 1.0) -> dict[str, Any]:


def _prepare_field_result(
obj: dict[str, Any], passed: bool, value: Any, reason: str, return_value: Callable[[Any], Any] | None = None
obj: dict[str, Any],
passed: bool, # noqa: FBT001
value: Any,
reason: str,
return_value: Callable[[Any], Any] | None = None,
) -> dict[str, Any]:
obj["result"] = passed
if not passed:
Expand All @@ -265,7 +271,7 @@ def process(self, value: Any) -> None:
if self.index < self._limit:
self.sample.append(value)
else:
r = random.randint(0, self.index)
r = random.randint(0, self.index) # noqa: S311
if r < self._limit:
self.sample[r] = value

Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ ignore = [
"C901", "PLR091", # complexity preferences
"D1", # docstrings
"PTH", # pathlib
"A001", # filter function
"ARG001", # yapw callbacks
"DTZ001", "DTZ007", # allow naive datetimes from JSON data
"FBT001", # bool argument
"PLR2004", # magic values
"PLW0603", # db globals
"S311", # random
]

[tool.ruff.lint.flake8-builtins]
Expand Down
8 changes: 4 additions & 4 deletions tests/dataset/distribution/test_value_repetition.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def test_undefined():
tender_value_repetition = value_repetition.ModuleType("tender")

scope = {}
for id, item in enumerate(items_test_undefined_multiple):
scope = tender_value_repetition.add_item(scope, item, id)
for item_id, item in enumerate(items_test_undefined_multiple):
scope = tender_value_repetition.add_item(scope, item, item_id)
result = tender_value_repetition.get_result(scope)
assert result["result"] is None
assert result["value"] is None
Expand Down Expand Up @@ -73,8 +73,8 @@ def test_failed():
awards_value_repetition = value_repetition.ModuleType("awards")

scope = {}
for id, item in enumerate(items_test_failed):
scope = awards_value_repetition.add_item(scope, item, id)
for item_id, item in enumerate(items_test_failed):
scope = awards_value_repetition.add_item(scope, item, item_id)
result = awards_value_repetition.get_result(scope)
assert result["result"] is False
assert result["value"] == 10.2
Expand Down
6 changes: 3 additions & 3 deletions tests/time_based/test_ocid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
}


def test_filter():
def test_applicable():
scope = get_empty_result_time_based_scope()
result = ocid.filter(scope, ancestor, 1, new_item, 1024)
result = ocid.applicable(scope, ancestor, 1, new_item, 1024)
assert result is True

result = ocid.filter(scope, ancestor, 1, None, None)
result = ocid.applicable(scope, ancestor, 1, None, None)
assert result is True


Expand Down
8 changes: 4 additions & 4 deletions tests/time_based/test_phase_stable.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
}


def test_filter():
def test_applicable():
scope = get_empty_result_time_based_scope()
assert phase_stable.filter(scope, ancestor_empty, 1, None, None) is True
assert phase_stable.filter(scope, ancestor_tender, 1, None, None) is True
assert phase_stable.filter(scope, ancestor_planning, 1, None, None) is True
assert phase_stable.applicable(scope, ancestor_empty, 1, None, None) is True
assert phase_stable.applicable(scope, ancestor_tender, 1, None, None) is True
assert phase_stable.applicable(scope, ancestor_planning, 1, None, None) is True


def test_evaluate_tender():
Expand Down
10 changes: 5 additions & 5 deletions tests/time_based/test_tender_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def test_evaluate():
ancestor_title_1 = {"ocid": "4", "tender": {"title": "title"}}


def test_filter():
def test_applicable():
scope = get_empty_result_time_based_scope()
assert tender_title.filter(scope, ancestor_no_title_1, 1, None, None) is False
assert tender_title.filter(scope, ancestor_no_title_2, 1, None, None) is False
assert tender_title.filter(scope, ancestor_no_title_3, 1, None, None) is False
assert tender_title.filter(scope, ancestor_title_1, 1, None, None) is True
assert tender_title.applicable(scope, ancestor_no_title_1, 1, None, None) is False
assert tender_title.applicable(scope, ancestor_no_title_2, 1, None, None) is False
assert tender_title.applicable(scope, ancestor_no_title_3, 1, None, None) is False
assert tender_title.applicable(scope, ancestor_title_1, 1, None, None) is True
4 changes: 2 additions & 2 deletions time_variance/checks/ocid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
version = 1.0


def filter(scope, item, item_id, new_item, new_item_id):
def applicable(scope, item, item_id, new_item, new_item_id):
return True


def evaluate(scope, item, item_id, new_item, new_item_id):
# `time_variance/processor.py` currently tests whether `new_item` is truthy before calling `evaluate`, and the
# `filter` function above tests whether `item` is truthy, such that this function will always return `True`.
# `applicable` function above tests whether `item` is truthy, such that this function will always return `True`.
# Nonetheless, the code is preserved in case the logic in `time_variance/processor.py` is changed.
return scope, bool(new_item)
2 changes: 1 addition & 1 deletion time_variance/checks/phase_stable.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
version = 1.0


def filter(scope, item, item_id, new_item, new_item_id):
def applicable(scope, item, item_id, new_item, new_item_id):
return True


Expand Down
2 changes: 1 addition & 1 deletion time_variance/checks/tender_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _get_title(item):
return None


def filter(scope, item, item_id, new_item, new_item_id):
def applicable(scope, item, item_id, new_item, new_item_id):
return bool(_get_title(item))


Expand Down
2 changes: 1 addition & 1 deletion time_variance/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def do_work(dataset_id):
for check_name, check in definitions.items():
scope.setdefault(check_name, get_empty_result_time_based_scope())

if check.filter(scope[check_name], ancestor_item, ancestor_item_id, new_item, new_item_id):
if check.applicable(scope[check_name], ancestor_item, ancestor_item_id, new_item, new_item_id):
scope[check_name]["total_count"] += 1

# Time-based checks report two numbers: "pairs found" and "pairs passed" (as a percentage of
Expand Down

0 comments on commit ea305fe

Please sign in to comment.