-
Notifications
You must be signed in to change notification settings - Fork 753
Fix normalize_paths to allow whitespace #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1155,10 +1155,13 @@ def normalize_paths(value, parent=os.curdir): | |
|
|
||
| Return a list of absolute paths. | ||
| """ | ||
| if not value or isinstance(value, list): | ||
| if not value: | ||
| return [] | ||
| if isinstance(value, list): | ||
| return value | ||
| paths = [] | ||
| for path in value.split(','): | ||
| path = path.strip() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the fix for issue #339. It strips whitespace before and after the path before doing further processing. |
||
| if '/' in path: | ||
| path = os.path.abspath(os.path.join(parent, path)) | ||
| paths.append(path.rstrip('/')) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/usr/bin/env python | ||
| # -*- coding: utf-8 -*- | ||
| import os | ||
| import unittest | ||
|
|
||
| import pep8 | ||
|
|
||
|
|
||
| class UtilTestCase(unittest.TestCase): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I called this UtilTestCase figuring this is a good place to test some of the other functions in |
||
| def test_normalize_paths(self): | ||
| cwd = os.getcwd() | ||
|
|
||
| self.assertEquals(pep8.normalize_paths(''), []) | ||
| self.assertEquals(pep8.normalize_paths(['foo']), ['foo']) | ||
| self.assertEquals(pep8.normalize_paths('foo'), ['foo']) | ||
| self.assertEquals(pep8.normalize_paths('foo,bar'), ['foo', 'bar']) | ||
| self.assertEquals(pep8.normalize_paths('/foo/bar,baz/../bat'), | ||
| ['/foo/bar', cwd + '/bat']) | ||
| self.assertEquals(pep8.normalize_paths(".pyc,\n build/*"), | ||
| ['.pyc', cwd + '/build/*']) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split this up because
if not valuecould be any falsey value and the docstring states that this function returns a list, thus it should return an empty list in these cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @willkg, I'd be interested to hear what your case was where this was failing for you. I'm tempted to update this to the following to handle the case where it isn't a list or a string coming in. Alternatively, perhaps it would be better to raise a ValueError at that point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a preference one way or the other. I changed this code because the docstring says it returns a list, but the code was just returning falsey values. I don't have a preference for my version or your version or even changing it to raise a ValueError.