From 1ef85c45e520687e076fb6e133e1a586125189f5 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 23 Apr 2020 17:38:41 +0000 Subject: [PATCH] Switch Transform to PurePath --- PFERD/organizer.py | 8 ++++---- PFERD/transform.py | 9 ++++----- PFERD/utils.py | 8 ++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/PFERD/organizer.py b/PFERD/organizer.py index 20c507a..47c9bc6 100644 --- a/PFERD/organizer.py +++ b/PFERD/organizer.py @@ -6,7 +6,7 @@ A organizer is bound to a single directory. import filecmp import logging import shutil -from pathlib import Path +from pathlib import Path, PurePath from typing import List, Set from .location import Location @@ -31,7 +31,7 @@ class Organizer(Location): # Keep the root dir self.mark(path) - def accept_file(self, src: Path, dst: Path) -> None: + def accept_file(self, src: Path, dst: PurePath) -> None: """Move a file to this organizer and mark it.""" src_absolute = src.resolve() dst_absolute = self.resolve(dst) @@ -73,9 +73,9 @@ class Organizer(Location): self.mark(dst) - def mark(self, path: Path) -> None: + def mark(self, path: PurePath) -> None: """Mark a file as used so it will not get cleaned up.""" - absolute_path = self.path.joinpath(path).resolve() + absolute_path = self.resolve(path) self._known_files.add(absolute_path) LOGGER.debug("Tracked %s", absolute_path) diff --git a/PFERD/transform.py b/PFERD/transform.py index 5427464..f72c342 100644 --- a/PFERD/transform.py +++ b/PFERD/transform.py @@ -6,11 +6,10 @@ scheme to another. """ from dataclasses import dataclass -from pathlib import Path +from pathlib import PurePath from typing import Callable, List, Optional, TypeVar - -Transform = Callable[[Path], Optional[Path]] +Transform = Callable[[PurePath], Optional[PurePath]] @dataclass @@ -19,14 +18,14 @@ class Transformable: An object that can be transformed by a Transform. """ - path: Path + path: PurePath TF = TypeVar("TF", bound=Transformable) def apply_transform( - transform: Callable[[Path], Optional[Path]], + transform: Transform, transformables: List[TF], ) -> List[TF]: """ diff --git a/PFERD/utils.py b/PFERD/utils.py index d683010..e659e39 100644 --- a/PFERD/utils.py +++ b/PFERD/utils.py @@ -86,7 +86,7 @@ class PrettyLogger: def __init__(self, logger: logging.Logger) -> None: self.logger = logger - def modified_file(self, file_name: Path) -> None: + def modified_file(self, file_name: PurePath) -> None: """ An existing file has changed. """ @@ -95,7 +95,7 @@ class PrettyLogger: f"{Fore.MAGENTA}{Style.BRIGHT}Modified {str(file_name)!r}.{Style.RESET_ALL}" ) - def new_file(self, file_name: Path) -> None: + def new_file(self, file_name: PurePath) -> None: """ A new file has been downloaded. """ @@ -103,14 +103,14 @@ class PrettyLogger: self.logger.info( f"{Fore.GREEN}{Style.BRIGHT}Created {str(file_name)!r}.{Style.RESET_ALL}") - def ignored_file(self, file_name: Path) -> None: + def ignored_file(self, file_name: PurePath) -> None: """ Nothing in particular happened to this file or directory. """ self.logger.info(f"{Style.DIM}Ignored {str(file_name)!r}.{Style.RESET_ALL}") - def filtered_path(self, path: Path, reason: str) -> None: + def filtered_path(self, path: PurePath, reason: str) -> None: """ A crawler filter rejected the given path. """