From 473106fee1ec4fcc9e2dde55c821effcd34e8a97 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Fri, 22 Jul 2016 17:02:12 -0500 Subject: [PATCH 1/2] 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 --- src/flake8/utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/flake8/utils.py b/src/flake8/utils.py index 7f31f8f..f432dac 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -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(): From 4a46412bf6007356775657e4f0bc452564dec2d1 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Fri, 22 Jul 2016 17:12:49 -0500 Subject: [PATCH 2/2] Check for alternate_separator only when truthy In the case where alternate separator is None, we use '' which will always be in any string. We want to skip that case. Also we only run our tests on AppVeyor, not all of our testenvs. --- .appveyor.yml | 2 +- src/flake8/utils.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 4a1d13c..ab4b7e2 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -5,4 +5,4 @@ install: build: off test_script: - - python -m tox + - python -m tox -e py27,py33,py34,py35 diff --git a/src/flake8/utils.py b/src/flake8/utils.py index f432dac..1e1eaa0 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -59,7 +59,8 @@ def normalize_path(path, parent=os.curdir): 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 in path: + 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 + alternate_separator)