summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-07-22 22:16:45 +0000
committerIan Cordasco <graffatcolmingov@gmail.com>2016-07-22 22:16:45 +0000
commit698079f87a017dc7170d9c5f14627d71a47b5aba (patch)
treea577be8345803d2c7429517a1dc61e51e15568f8 /src
parenta8753b3ff94bac4adb5763abb7f7f2d2fbc20b19 (diff)
parent4a46412bf6007356775657e4f0bc452564dec2d1 (diff)
downloadflake8-698079f87a017dc7170d9c5f14627d71a47b5aba.tar.gz
Merge branch 'windows-bugs' into 'master'
Check for both os.path.sep and os.path.altsep *Description of changes* 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 See merge request !81
Diffstat (limited to 'src')
-rw-r--r--src/flake8/utils.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/flake8/utils.py b/src/flake8/utils.py
index 7f31f8f..1e1eaa0 100644
--- a/src/flake8/utils.py
+++ b/src/flake8/utils.py
@@ -53,12 +53,16 @@ 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 and
+ 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():