perform path normalization on '.'

This commit is contained in:
Anthony Sottile 2022-01-05 11:44:31 -05:00
parent 7fad9925d2
commit 4cb1dc8c44
2 changed files with 6 additions and 3 deletions

View file

@ -177,13 +177,15 @@ def normalize_path(path: str, parent: str = os.curdir) -> str:
str
"""
# NOTE(sigmavirus24): Using os.path.sep and os.path.altsep allow for
# Windows compatibility with both Windows-style paths (c:\\foo\bar) and
# Windows compatibility with both Windows-style paths (c:\foo\bar) and
# Unix style paths (/foo/bar).
separator = os.path.sep
# NOTE(sigmavirus24): os.path.altsep may be None
alternate_separator = os.path.altsep or ""
if separator in path or (
alternate_separator and alternate_separator in path
if (
path == "."
or separator in path
or (alternate_separator and alternate_separator in path)
):
path = os.path.abspath(os.path.join(parent, path))
return path.rstrip(separator + alternate_separator)

View file

@ -132,6 +132,7 @@ def test_invalid_file_list(value):
"value,expected",
[
("flake8", "flake8"),
(".", os.path.abspath(".")),
("../flake8", os.path.abspath("../flake8")),
("flake8/", os.path.abspath("flake8")),
],