From f466818a95f71b607731507bf35418030fcaa4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Tue, 30 Jun 2020 17:15:50 -0700 Subject: [PATCH] util: remove canon_path() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We've now re-worked the west internals to use pathlib everywhere that platform-specific path magic was previously relying on canon_path() or other os.path-based methods to do comparisons or otherwise canonicalize paths. We can therefore remove canon_path() and consider the internals of path handling hopefully satisfactorily reworked. Any further issues with path handling should be treated as bugs. Fixes: #273 Signed-off-by: Martí Bolívar --- src/west/util.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/west/util.py b/src/west/util.py index 144df66..37d7def 100644 --- a/src/west/util.py +++ b/src/west/util.py @@ -11,10 +11,7 @@ import shlex import textwrap from typing import List, Optional, Union -# What we would eventually like to accept for paths everywhere in -# west's APIs. However, right now, paths are 'str' in a variety of -# places, and we are using west.util.canon_path() to create strings we -# can compare with ==. See #273 on GitHub. +# What west's APIs accept for paths. # # Here, os.PathLike objects should return str from their __fspath__ # methods, not bytes. We could try to do something like the approach @@ -23,18 +20,6 @@ from typing import List, Optional, Union # otherwise, but it doesn't seem worth it. PathType = Union[str, os.PathLike] -def canon_path(path: str) -> str: - '''Returns a canonical version of the path. - - This is currently ``os.path.normcase(os.path.abspath(path))``. The - path separator is converted to os.sep on platforms where that - matters (Windows). - - :param path: path whose canonical name to return; need not - refer to an existing file. - ''' - return os.path.normcase(os.path.abspath(path)) - def escapes_directory(path: PathType, directory: PathType) -> bool: '''Returns True if `path` escapes parent directory `directory`.