Skip to content

Commit

Permalink
Address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Jun 11, 2021
1 parent 6eb3500 commit 82ec437
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cylc/flow/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Exceptions for "expected" errors."""


import errno
from typing import Callable, Iterable, NoReturn, Tuple, Type


Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions cylc/flow/pathutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -297,19 +297,19 @@ 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"
)
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

Expand All @@ -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
2 changes: 1 addition & 1 deletion cylc/flow/workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 82ec437

Please sign in to comment.