From ce0cd5794dae01d7c735bb5b616dce1610ccd068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sat, 5 Feb 2022 18:17:00 +0100 Subject: [PATCH] rework relative paths --- PyTeX/paths/relative_paths.py | 61 ++++++++++++++--------------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/PyTeX/paths/relative_paths.py b/PyTeX/paths/relative_paths.py index 4cc5661..81c8236 100644 --- a/PyTeX/paths/relative_paths.py +++ b/PyTeX/paths/relative_paths.py @@ -5,23 +5,15 @@ from .enums import PyTeXRootDirType import os +class PyTeXPurePath: + pass + + class PyTeXPurePath(PurePath): - def __new__(cls, *args): + def __new__(cls, pytex_root_dir_type: PyTeXRootDirType, *args): if cls is PyTeXPurePath: cls = PyTeXPureWindowsPath if os.name == 'nt' else PyTeXPurePosixPath - - -class PyTeXPurePosixPath(PurePosixPath, PyTeXPurePath): - pass - - -class PyTeXPureWindowsPath(PureWindowsPath, PyTeXPurePath): - pass - - -class PyTeXPath(Path): - def __new__(cls, pytex_root_dir_type: PyTeXRootDirType, *args, **kwargs): - self = super().__new__(cls, *args, **kwargs) + self = cls._from_parts(args) self.__init(pytex_root_dir_type) return self @@ -40,14 +32,14 @@ class PyTeXPath(Path): self._relative_path = self.relative_to( self._root_dir / GlobalPyTeXConfig.wrapper_dir() ) - except ValueError: + except ValueError as e: raise ValueError # TODO def root_dir_type(self) -> PyTeXRootDirType: return self._pytex_root_dir_type @property - def relative_path(self) -> Path: + def relative_path(self) -> PyTeXPurePath: return self._relative_path def __truediv__(self, other): @@ -57,29 +49,24 @@ class PyTeXPath(Path): return super().__truediv__(GlobalPyTeXConfig.wrapper_dir()).__truediv__(other) +class PyTeXPurePosixPath(PurePosixPath, PyTeXPurePath): + pass -class PureRelativePath: - def __init__(self, relative_path: Union[str, PurePath]): - if type(relative_path) == PurePath: - self._relative_path: PurePath = relative_path - else: - self._relative_path: PurePath = PurePath(relative_path) - - @property - def path(self) -> PurePath: - return self._relative_path - - def __eq__(self, other): - return self.path == other.path - - def __str__(self): - return str(self.path) +class PyTeXPureWindowsPath(PureWindowsPath, PyTeXPurePath): + pass -class RelativePath(PureRelativePath, PyTeXPath): - def __init__(self, path: Path, pytex_root_dir: PyTeXRootDirType): - self._absolute_path: Path = path +class PyTeXPath(Path, PyTeXPurePath): + def __new__(cls, pytex_root_dir_type: PyTeXRootDirType, *args, **kwargs): + if cls is PyTeXPath: + cls = PyTeXWindowsPath if os.name == 'nt' else PyTeXPosixPath + return super().__new__(cls, *args, **kwargs) - def absolute_path(self) -> Path: - return self._absolute_path + +class PyTeXPosixPath(PyTeXPath, PyTeXPurePosixPath): + pass + + +class PyTeXWindowsPath(PyTeXPath, PyTeXPureWindowsPath): + pass