Skip to content
Snippets Groups Projects
Commit acbb8cf5 authored by NolanB's avatar NolanB
Browse files

update code and modif the path of SAMPLES_DIR and tests

parent a4da0845
No related branches found
No related tags found
1 merge request!265Only use files when computing model archive hash
Pipeline #79870 passed
......@@ -50,23 +50,15 @@ def create_archive(path: DirPath) -> Tuple[Path, Hash, FileSize, Hash]:
# Create an uncompressed tar archive with all the needed files
# Files hierarchy ifs kept in the archive.
file_list = []
with tarfile.open(path_to_tar_archive, "w") as tar:
for p in path.glob("**/*"):
x = p.relative_to(path)
tar.add(p, arcname=x, recursive=False)
if p.is_dir():
continue
file_list.append(p)
with tarfile.open(path_to_tar_archive, "w") as tar:
tar.add(path)
file_list = [member for member in tar.getnames() if os.path.isfile(member)]
# Sort by path
file_list.sort()
# Compute hash of the files
for file_path in file_list:
print("BOOM PATH", file_path)
with open(file_path, "rb") as file_data:
for chunk in iter(lambda: file_data.read(CHUNK_SIZE), b""):
content_hasher.update(chunk)
......@@ -102,7 +94,6 @@ class TrainingMixin(object):
model_id: str,
tag: Optional[str] = None,
description: Optional[str] = None,
use_parent_folder=False,
):
"""
This method creates a model archive and its associated hash,
......
......@@ -26,7 +26,7 @@ from arkindex_worker.worker import BaseWorker, ElementsWorker
from arkindex_worker.worker.transcription import TextOrientation
FIXTURES_DIR = Path(__file__).resolve().parent / "data"
SAMPLES_DIR = Path(__file__).resolve().parent / "samples"
SAMPLES_DIR = Path("tests") / "samples"
__yaml_cache = {}
......
......@@ -58,7 +58,7 @@ def test_create_archive_with_subfolder(model_file_dir_with_subfolder):
assert (
hash == "e2fa86cefc33b24502ad4151a638dd29"
), "Hash was not properly computed"
assert 300 < size < 1200
assert 300 < size < 1500
assert not os.path.exists(zst_archive_path), "Auto removal failed"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment