Skip to content

Commit

Permalink
fix: avoid circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mfacchinelli committed Aug 30, 2024
1 parent 55e0838 commit 49a8d22
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
5 changes: 0 additions & 5 deletions src/imap_mag/appUtils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import hashlib
import logging
from pathlib import Path
from typing import Optional
Expand Down Expand Up @@ -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."""

Expand Down
11 changes: 8 additions & 3 deletions src/imap_mag/outputManager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
import hashlib
import logging
import shutil
import typing
Expand All @@ -7,8 +8,6 @@

import typer

from .appUtils import generate_hash


class IFileMetadataProvider(abc.ABC):
"""Interface for metadata providers."""
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion tests/testUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 49a8d22

Please sign in to comment.