diff --git a/ufpy/__init__.py b/ufpy/__init__.py index 57ce48c..1af4da7 100644 --- a/ufpy/__init__.py +++ b/ufpy/__init__.py @@ -8,15 +8,12 @@ # Typing package __typ_version__ = '0.1' -from ufpy import typ from ufpy.typ import * # Path package __path_version__ = '0.1' -from ufpy import path from ufpy.path import * # GitHub package __github_version__ = '0.1' -from ufpy import github -from ufpy.github import UGithubDownloader, download_file, download_folder, download_repo +from ufpy.github import * diff --git a/ufpy/github/download.py b/ufpy/github/download.py index acd9543..5b21646 100644 --- a/ufpy/github/download.py +++ b/ufpy/github/download.py @@ -35,7 +35,7 @@ def repo(repo: str, download_path: str, branch_name: str = 'main'): gd.download_repo() -def format_paths(*paths: str | list[str]) -> list[str] | list[list[str]] | list[str | list[str]] | str: +def format_paths(*paths: str | list[str]) -> list[str] | list[list[str]]: new_paths = [] for path in paths: if isinstance(path, list): diff --git a/ufpy/path/files.py b/ufpy/path/files.py index 33dc3e8..11c2c52 100644 --- a/ufpy/path/files.py +++ b/ufpy/path/files.py @@ -15,21 +15,20 @@ def __init__( self.__encoding = encoding def __enter__(self): - directory = '/'.join(self.__path.split('/')[:-1]) - if not directory: - directory = '\\'.join(self.__path.split('\\')[:-1]) + directory = '/'.join(self.__path.split('/')[:-1]) or '\\'.join(self.__path.split('\\')[:-1]) - if not os.path.exists(directory): - os.makedirs(directory) + os.makedirs(directory, exist_ok=True) self.__f = open(file=self.__path, mode=self.__mode, encoding=self.__encoding) return self def __exit__(self, exc_type, exc_val, exc_tb): - self.__f.close() + if not self.__f.closed: + self.__f.close() def __del__(self): - self.__f.close() + if not self.__f.closed: + self.__f.close() def write(self, data: AnyStr): self.__f.write(data)