diff --git a/cylc/flow/exceptions.py b/cylc/flow/exceptions.py index 2540d74c422..286bf6800e1 100644 --- a/cylc/flow/exceptions.py +++ b/cylc/flow/exceptions.py @@ -15,7 +15,7 @@ # along with this program. If not, see . """Exceptions for "expected" errors.""" - +import errno from typing import Callable, Iterable, NoReturn, Tuple, Type @@ -106,7 +106,7 @@ def handle_rmtree_err( ) -> NoReturn: """Error handler for shutil.rmtree.""" exc = excinfo[1] - if isinstance(exc, OSError) and exc.errno == 39: + if isinstance(exc, OSError) and exc.errno == errno.ENOTEMPTY: # "Directory not empty", likely due to filesystem lag raise FileRemovalError(exc) raise exc diff --git a/cylc/flow/pathutil.py b/cylc/flow/pathutil.py index 1d98a9a1a96..a30f9ad86a7 100644 --- a/cylc/flow/pathutil.py +++ b/cylc/flow/pathutil.py @@ -32,7 +32,7 @@ # Note: do not import this elsewhere, as it might bypass unit test # monkeypatching: -_CYLC_RUN_DIR = '$HOME/cylc-run' +_CYLC_RUN_DIR = os.path.join('$HOME', 'cylc-run') def expand_path(*args: Union[Path, str]) -> str: @@ -297,11 +297,11 @@ def parse_rm_dirs(rm_dirs: Iterable[str]) -> Set[str]: part = part.strip() if not part: continue - is_dir = part.endswith('/') + is_dir = part.endswith(os.sep) part = os.path.normpath(part) if os.path.isabs(part): raise UserInputError("--rm option cannot take absolute paths") - if part == '.' or part.startswith('../'): + if part == '.' or part.startswith(f'..{os.sep}'): raise UserInputError( "--rm option cannot take paths that point to the " "run directory or above" @@ -309,7 +309,7 @@ def parse_rm_dirs(rm_dirs: Iterable[str]) -> Set[str]: if is_dir: # Preserve trailing slash to ensure it only matches dirs, # not files, when globbing - part += '/' + part += os.sep result.add(part) return result @@ -333,7 +333,7 @@ def is_relative_to(path1: Union[Path, str], path2: Union[Path, str]) -> bool: # In future, we can just use pathlib.Path.is_relative_to() # when Python 3.9 becomes the minimum supported version try: - Path(path1).relative_to(path2) + Path(os.path.normpath(path1)).relative_to(os.path.normpath(path2)) except ValueError: return False return True diff --git a/cylc/flow/workflow_files.py b/cylc/flow/workflow_files.py index d8f275ee33c..16df503336d 100644 --- a/cylc/flow/workflow_files.py +++ b/cylc/flow/workflow_files.py @@ -1041,7 +1041,7 @@ def _check_child_dirs(path: Union[Path, str], depth_count: int = 1): reg_path: Union[Path, str] = os.path.normpath(run_dir) parent_dir = os.path.dirname(reg_path) - while parent_dir not in ['', '/']: + while parent_dir not in ['', os.sep]: if is_valid_run_dir(parent_dir): raise WorkflowFilesError( exc_msg.format(parent_dir, get_cylc_run_abs_path(parent_dir))