Skip to content

Commit 133ab83

Browse files
committed
Include checker name in cache key and tidy up some code.
1 parent a96e11a commit 133ab83

File tree

9 files changed

+139
-191
lines changed

9 files changed

+139
-191
lines changed

atr/attestable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import aiofiles.os
2525
import pydantic
2626

27-
import atr.hashing as hashing
27+
import atr.hashes as hashes
2828
import atr.log as log
2929
import atr.models.attestable as models
3030
import atr.util as util
@@ -130,7 +130,7 @@ async def paths_to_hashes_and_sizes(directory: pathlib.Path) -> tuple[dict[str,
130130
if "\\" in path_key:
131131
# TODO: We should centralise this, and forbid some other characters too
132132
raise ValueError(f"Backslash in path is forbidden: {path_key}")
133-
path_to_hash[path_key] = await hashing.compute_file_hash(full_path)
133+
path_to_hash[path_key] = await hashes.compute_file_hash(full_path)
134134
path_to_size[path_key] = (await aiofiles.os.stat(full_path)).st_size
135135
return path_to_hash, path_to_size
136136

atr/docs/tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ In `atr/tasks/checks` you will find several modules that perform these check tas
4141
In `atr/tasks/__init__.py` you will see imports for existing modules where you can add an import for new check task, for example:
4242

4343
```python
44-
import atr.tasks.checks.file_hash as file_hash
44+
import atr.tasks.checks.hashing as file_hash
4545
import atr.tasks.checks.license as license
4646
```
4747

File renamed without changes.

atr/merge.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import aiofiles.os
2525

2626
import atr.attestable as attestable
27+
import atr.hashes as hashes
2728
import atr.util as util
2829

2930
if TYPE_CHECKING:
@@ -131,7 +132,7 @@ async def _add_from_prior(
131132
if (prior_hashes is not None) and (path in prior_hashes):
132133
n_hashes[path] = prior_hashes[path]
133134
else:
134-
n_hashes[path] = await attestable.compute_file_hash(target)
135+
n_hashes[path] = await hashes.compute_file_hash(target)
135136
stat_result = await aiofiles.os.stat(target)
136137
n_sizes[path] = stat_result.st_size
137138
return prior_hashes
@@ -211,7 +212,7 @@ async def _merge_all_present(
211212
if (prior_hashes is not None) and (path in prior_hashes):
212213
p_hash = prior_hashes[path]
213214
else:
214-
p_hash = await attestable.compute_file_hash(prior_dir / path)
215+
p_hash = await hashes.compute_file_hash(prior_dir / path)
215216
if p_hash != b_hash:
216217
# Case 11 via hash: base and new have the same content but prior differs
217218
return await _replace_with_prior(
@@ -250,7 +251,7 @@ async def _replace_with_prior(
250251
if (prior_hashes is not None) and (path in prior_hashes):
251252
n_hashes[path] = prior_hashes[path]
252253
else:
253-
n_hashes[path] = await attestable.compute_file_hash(file_path)
254+
n_hashes[path] = await hashes.compute_file_hash(file_path)
254255
stat_result = await aiofiles.os.stat(file_path)
255256
n_sizes[path] = stat_result.st_size
256257
return prior_hashes

atr/storage/readers/checks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from typing import TYPE_CHECKING
2323

2424
import atr.db as db
25-
import atr.hashing as hashing
25+
import atr.hashes as hashes
2626
import atr.models.sql as sql
2727
import atr.storage as storage
2828
import atr.storage.types as types
@@ -55,9 +55,9 @@ async def _filter_check_results_by_hash(
5555
extra_arg_names = []
5656
extra_args = checks.resolve_extra_args(extra_arg_names, release)
5757
cache_key = await checks.resolve_cache_key(
58-
policy_keys, release, release.latest_revision_number, extra_args, file=rel_path.name
58+
cr.checker, policy_keys, release, release.latest_revision_number, extra_args, file=rel_path.name
5959
)
60-
input_hash_by_module[module_path] = hashing.compute_dict_hash(cache_key) if cache_key else None
60+
input_hash_by_module[module_path] = hashes.compute_dict_hash(cache_key) if cache_key else None
6161

6262
if cr.inputs_hash == input_hash_by_module[module_path]:
6363
filtered_check_results.append(cr)

0 commit comments

Comments
 (0)