Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit bd49933

Browse files
oczkoissesambhav
andauthored
Fix match option to only consider basename when given a path argument (#550)
Co-authored-by: Sambhav Kothari <[email protected]>
1 parent 1011866 commit bd49933

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

docs/release_notes.rst

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ New Features
1515
* Add support for Python 3.10 (#554).
1616
* Replace D10X errors with D419 if docstring exists but is empty (#559).
1717

18+
Bug Fixes
19+
20+
* Fix ``--match`` option to only consider filename when matching full paths (#550).
21+
1822
6.1.1 - May 17th, 2021
1923
---------------------------
2024

src/pydocstyle/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def _get_property_decorators(conf):
288288
# Skip any dirs that do not match match_dir
289289
dirs[:] = [d for d in dirs if match_dir(d)]
290290

291-
for filename in filenames:
291+
for filename in map(os.path.basename, filenames):
292292
if match(filename):
293293
full_path = os.path.join(root, filename)
294294
yield (
@@ -302,7 +302,7 @@ def _get_property_decorators(conf):
302302
match, _ = _get_matches(config)
303303
ignore_decorators = _get_ignore_decorators(config)
304304
property_decorators = _get_property_decorators(config)
305-
if match(name):
305+
if match(os.path.basename(name)):
306306
yield (
307307
name,
308308
list(config.checked_codes),

src/tests/test_integration.py

+22
Original file line numberDiff line numberDiff line change
@@ -1489,3 +1489,25 @@ def test_comment_with_noqa_plus_docstring_file(env):
14891489
out, _, code = env.invoke()
14901490
assert '' == out
14911491
assert code == 0
1492+
1493+
1494+
def test_match_considers_basenames_for_path_args(env):
1495+
"""Test that `match` option only considers basenames for path arguments.
1496+
1497+
The test environment consists of a single empty module `test_a.py`. The
1498+
match option is set to a pattern that ignores test_ prefixed .py filenames.
1499+
When pydocstyle is invoked with full path to `test_a.py`, we expect it to
1500+
succeed since match option will match against just the file name and not
1501+
full path.
1502+
"""
1503+
# Ignore .py files prefixed with 'test_'
1504+
env.write_config(select='D100', match='(?!test_).+.py')
1505+
1506+
# Create an empty module (violates D100)
1507+
with env.open('test_a.py', 'wt') as test:
1508+
test.write('')
1509+
1510+
# env.invoke calls pydocstyle with full path to test_a.py
1511+
out, _, code = env.invoke(target='test_a.py')
1512+
assert '' == out
1513+
assert code == 0

0 commit comments

Comments
 (0)