Skip to content

Commit af91d98

Browse files
committed
Fix usage of in the project config file; issue #247
1 parent 5731082 commit af91d98

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Changelog
1717

1818
* Fix a false positive E124 for hanging indent. (Issue #254)
1919

20+
* Fix behaviour when ``exclude`` is in the configuration file and
21+
the current directory is not the project directory. (Issue #247)
22+
2023

2124
1.4.6 (2013-07-02)
2225
------------------

pep8.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,21 @@ def parse_udiff(diff, patterns=None, parent='.'):
11281128
if rows and filename_match(path, patterns)])
11291129

11301130

1131+
def normalize_paths(value, parent=os.curdir):
1132+
"""Parse a comma-separated list of paths.
1133+
1134+
Return a list of absolute paths.
1135+
"""
1136+
if not value or isinstance(value, list):
1137+
return value
1138+
paths = []
1139+
for path in value.split(','):
1140+
if path.startswith('./'):
1141+
path = os.path.abspath(os.path.join(parent, path))
1142+
paths.append(path.rstrip('/'))
1143+
return paths
1144+
1145+
11311146
def filename_match(filename, patterns, default=True):
11321147
"""
11331148
Check if patterns contains a pattern that matches filename.
@@ -1594,8 +1609,6 @@ def __init__(self, *args, **kwargs):
15941609
if not options.reporter:
15951610
options.reporter = BaseReport if options.quiet else StandardReport
15961611

1597-
for index, value in enumerate(options.exclude):
1598-
options.exclude[index] = value.rstrip('/')
15991612
options.select = tuple(options.select or ())
16001613
if not (options.select or options.ignore or
16011614
options.testsuite or options.doctest) and DEFAULT_IGNORE:
@@ -1675,6 +1688,7 @@ def excluded(self, filename, parent=None):
16751688
return True
16761689
if parent:
16771690
filename = os.path.join(parent, filename)
1691+
filename = os.path.abspath(filename)
16781692
return filename_match(filename, self.options.exclude)
16791693

16801694
def ignore_code(self, code):
@@ -1774,9 +1788,11 @@ def read_config(options, args, arglist, parser):
17741788
print('user configuration: %s' % user_conf)
17751789
config.read(user_conf)
17761790

1791+
local_dir = os.curdir
17771792
parent = tail = args and os.path.abspath(os.path.commonprefix(args))
17781793
while tail:
17791794
if config.read([os.path.join(parent, fn) for fn in PROJECT_CONFIG]):
1795+
local_dir = parent
17801796
if options.verbose:
17811797
print('local configuration: in %s' % parent)
17821798
break
@@ -1804,6 +1820,8 @@ def read_config(options, args, arglist, parser):
18041820
value = config.getint(pep8_section, opt)
18051821
elif opt_type == 'string':
18061822
value = config.get(pep8_section, opt)
1823+
if normalized_opt == 'exclude':
1824+
value = normalize_paths(value, local_dir)
18071825
else:
18081826
assert opt_type in ('store_true', 'store_false')
18091827
value = config.getboolean(pep8_section, opt)
@@ -1851,7 +1869,7 @@ def process_options(arglist=None, parse_argv=False, config_file=None,
18511869
options.reporter = parse_argv and options.quiet == 1 and FileReport
18521870

18531871
options.filename = options.filename and options.filename.split(',')
1854-
options.exclude = options.exclude.split(',')
1872+
options.exclude = normalize_paths(options.exclude)
18551873
options.select = options.select and options.select.split(',')
18561874
options.ignore = options.ignore and options.ignore.split(',')
18571875

0 commit comments

Comments
 (0)