mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 07:14:18 +00:00
Merge pull request #1508 from asottile/normalize_dot
perform path normalization on '.'
This commit is contained in:
commit
8c7b8bb2ab
2 changed files with 6 additions and 3 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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")),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue