Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2566,7 +2566,7 @@ def read_config(options, args, arglist, parser):
print('user configuration: %s' % USER_CONFIG)
config.read(USER_CONFIG)

parent = tail = args and os.path.abspath(os.path.commonprefix(args))
parent = tail = args and os.path.abspath(os.path.commonpath(args))
while tail:
if config.read(os.path.join(parent, fn) for fn in PROJECT_CONFIG):
local_dir = parent
Expand Down
31 changes: 31 additions & 0 deletions tests/test_pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

from pycodestyle import Checker
from pycodestyle import expand_indent
from pycodestyle import get_parser
from pycodestyle import mute_string
from pycodestyle import read_config


@pytest.mark.parametrize(
Expand Down Expand Up @@ -46,3 +48,32 @@ def test_fstring_logical_line():
assert checker.logical_line == "f'xxxxxxxxx{thing}xxxxxxxxx'"
else:
assert checker.logical_line == "f'xxxxxxxxxxxxxxxxxxxxxxxxx'"


def test_read_config_prefix(tmp_path):
tmp_path.joinpath('setup.cfg').write_text('[pycodestyle]\nexclude = root')

adir = tmp_path.joinpath('aaa')
adir.mkdir()
adir.joinpath('setup.cfg').write_text('[pycodestyle]\nexclude = aaa')

bdir = tmp_path.joinpath('aaabbb')
bdir.mkdir()
b_t = bdir.joinpath('t.py')
b_t.touch()
bdir.joinpath('setup.cfg').write_text('[pycodestyle]\nexclude = bbb')

cdir = tmp_path.joinpath('aaaccc')
cdir.mkdir()
c_t = cdir.joinpath('t.py')
c_t.touch()
cdir.joinpath('setup.cfg').write_text('[pycodestyle]\nexclude = ccc')

arglist = [str(b_t), str(c_t)]
parser = get_parser()
parser.add_option('--config')
opts, args = parser.parse_args(arglist)

# `aaa/setup.cfg` should not be read -- it is not passed on cmdline
opts = read_config(opts, args, arglist, parser)
assert opts.exclude == ['root']
Loading