@@ -41,11 +41,10 @@ def _check_saving_path(path_to_file, verbose=False, print_prefix="", state_verb=
4141 >>> from pyhelpers.store import _check_saving_path
4242 >>> from pyhelpers.dirs import cd
4343 >>> path_to_file = cd()
44- >>> try:
45- ... _check_saving_path(path_to_file, verbose=True)
46- ... except AssertionError as e:
47- ... print(e)
48- The input for `path_to_file` may not be a file path.
44+ >>> _check_saving_path(path_to_file, verbose=True)
45+ Traceback (most recent call last):
46+ ...
47+ AssertionError: The input for `path_to_file` may not be a file path.
4948 >>> path_to_file = "pyhelpers.pdf"
5049 >>> _check_saving_path(path_to_file, verbose=True); print("Passed.")
5150 Saving "pyhelpers.pdf" ... Passed.
@@ -63,17 +62,11 @@ def _check_saving_path(path_to_file, verbose=False, print_prefix="", state_verb=
6362 abs_path_to_file = pathlib .Path (path_to_file ).absolute ()
6463 assert not abs_path_to_file .is_dir (), "The input for `path_to_file` may not be a file path."
6564
66- filename = pathlib .Path (abs_path_to_file ).name if abs_path_to_file .suffix else ""
67-
6865 try :
69- rel_dir_path = pathlib .Path ( os . path . relpath ( abs_path_to_file . parent ))
66+ rel_dir_path = abs_path_to_file . parent . relative_to ( pathlib .Path . cwd ( ))
7067
71- if rel_dir_path .is_relative_to ("." ):
72- pass
73- elif rel_dir_path == rel_dir_path .parent :
68+ if rel_dir_path .is_relative_to ("." ) and rel_dir_path == rel_dir_path .parent :
7469 rel_dir_path = abs_path_to_file .parent
75- else : # In case the specified path does not exist
76- os .makedirs (abs_path_to_file .parent , exist_ok = True )
7770
7871 except ValueError :
7972 if verbose == 2 :
@@ -83,13 +76,17 @@ def _check_saving_path(path_to_file, verbose=False, print_prefix="", state_verb=
8376
8477 rel_dir_path = abs_path_to_file .parent
8578
79+ rel_dir_path .mkdir (parents = True , exist_ok = True ) # In case the specified path does not exist
80+
81+ filename = abs_path_to_file .name if abs_path_to_file .suffix else ""
82+
8683 if verbose :
87- if os .path .exists (abs_path_to_file ):
84+ if os .path .isfile (abs_path_to_file ):
8885 state_verb , state_prep = "Updating" , "at"
8986
9087 end = print_end if print_end else "\n "
9188
92- if (rel_dir_path == rel_dir_path .parent and
89+ if (rel_dir_path == rel_dir_path .parent or rel_dir_path == abs_path_to_file . parent ) and (
9390 rel_dir_path .absolute ().drive == pathlib .Path .cwd ().drive ):
9491 msg = f'{ print_prefix } { state_verb } "{ filename } "{ print_suffix } '
9592 print (msg , end = end )
0 commit comments