Skip to content

Commit

Permalink
Merge branch 'windows-bugs' into 'master'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sigmavirus24 committed Jul 22, 2016
2 parents a8753b3 + 4a46412 commit 698079f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ install:
build: off

test_script:
- python -m tox
- python -m tox -e py27,py33,py34,py35
12 changes: 8 additions & 4 deletions src/flake8/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 698079f

Please sign in to comment.