From 49a8d22c603efeffd1a759d32cb7edfa02208ad4 Mon Sep 17 00:00:00 2001 From: Michele Facchinelli Date: Fri, 30 Aug 2024 13:49:38 +0000 Subject: [PATCH] fix: avoid circular dependency --- src/imap_mag/appUtils.py | 5 ----- src/imap_mag/outputManager.py | 11 ++++++++--- tests/testUtils.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/imap_mag/appUtils.py b/src/imap_mag/appUtils.py index b6bdf47..b15a050 100644 --- a/src/imap_mag/appUtils.py +++ b/src/imap_mag/appUtils.py @@ -1,4 +1,3 @@ -import hashlib import logging from pathlib import Path from typing import Optional @@ -57,10 +56,6 @@ def convertToDatetime(string: str) -> np.datetime64: raise typer.Abort() -def generate_hash(file: Path) -> str: - return hashlib.md5(file.read_bytes()).hexdigest() - - def getOutputManager(destination: Destination) -> IOutputManager: """Retrieve output manager based on destination.""" diff --git a/src/imap_mag/outputManager.py b/src/imap_mag/outputManager.py index c40e9a8..5a614bd 100644 --- a/src/imap_mag/outputManager.py +++ b/src/imap_mag/outputManager.py @@ -1,4 +1,5 @@ import abc +import hashlib import logging import shutil import typing @@ -7,8 +8,6 @@ import typer -from .appUtils import generate_hash - class IFileMetadataProvider(abc.ABC): """Interface for metadata providers.""" @@ -105,7 +104,9 @@ def add_file( destination_file.parent.mkdir(parents=True, exist_ok=True) if destination_file.exists(): - if generate_hash(destination_file) == generate_hash(original_file): + if self.__generate_hash(destination_file) == self.__generate_hash( + original_file + ): logging.info(f"File {destination_file} already exists and is the same.") return (destination_file, metadata_provider) @@ -142,3 +143,7 @@ def __get_next_available_version( destination_file = self.__assemble_full_path(metadata_provider) return metadata_provider.version + + @staticmethod + def __generate_hash(file: Path) -> str: + return hashlib.md5(file.read_bytes()).hexdigest() diff --git a/tests/testUtils.py b/tests/testUtils.py index 3f2e56b..bdb846d 100644 --- a/tests/testUtils.py +++ b/tests/testUtils.py @@ -67,7 +67,7 @@ def create_serialize_config( return (config, config_file) -def create_test_file(file_path: Path, content: str | None) -> Path: +def create_test_file(file_path: Path, content: str | None = None) -> Path: """Create a file with the given content.""" file_path.unlink(missing_ok=True)