Merge pull request #1508 from asottile/normalize_dot

perform path normalization on '.'
This commit is contained in:
Anthony Sottile 2022-01-05 11:52:10 -05:00 committed by GitHub
commit 8c7b8bb2ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 str
""" """
# NOTE(sigmavirus24): Using os.path.sep and os.path.altsep allow for # 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). # Unix style paths (/foo/bar).
separator = os.path.sep separator = os.path.sep
# NOTE(sigmavirus24): os.path.altsep may be None # NOTE(sigmavirus24): os.path.altsep may be None
alternate_separator = os.path.altsep or "" alternate_separator = os.path.altsep or ""
if separator in path or ( if (
alternate_separator and alternate_separator in path path == "."
or separator in path
or (alternate_separator and alternate_separator in path)
): ):
path = os.path.abspath(os.path.join(parent, path)) path = os.path.abspath(os.path.join(parent, path))
return path.rstrip(separator + alternate_separator) return path.rstrip(separator + alternate_separator)

View file

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