mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-29 18:46:52 +00:00
Check for both os.path.sep and os.path.altsep
When normalizing paths, we want to handle the following cases: - Someone is using a Windows-style path on Windows - Someone is using a Unix style path on Unix - Someone is using a Unix style path on Windows os.path.sep will handle the native directory separator character while os.path.altsep (when set) will handle alternate separators. Further, os.path.abspath does the right thing on Windows when handed a Unix-style path. Related to #175
This commit is contained in:
parent
a8753b3ff9
commit
473106fee1
1 changed files with 7 additions and 4 deletions
|
|
@ -53,12 +53,15 @@ def normalize_path(path, parent=os.curdir):
|
|||
:rtype:
|
||||
str
|
||||
"""
|
||||
# NOTE(sigmavirus24): Using os.path.sep allows for Windows paths to
|
||||
# be specified and work appropriately.
|
||||
# NOTE(sigmavirus24): Using os.path.sep and os.path.altsep allow for
|
||||
# Windows compatibility with both Windows-style paths (c:\\foo\bar) and
|
||||
# Unix style paths (/foo/bar).
|
||||
separator = os.path.sep
|
||||
if separator in path:
|
||||
# NOTE(sigmavirus24): os.path.altsep may be None
|
||||
alternate_separator = os.path.altsep or ''
|
||||
if separator in path or alternate_separator in path:
|
||||
path = os.path.abspath(os.path.join(parent, path))
|
||||
return path.rstrip(separator)
|
||||
return path.rstrip(separator + alternate_separator)
|
||||
|
||||
|
||||
def stdin_get_value():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue