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

Fix match option to only consider basename when given a path argument #550

Merged
merged 5 commits into from Dec 30, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/release_notes.rst
Expand Up @@ -15,6 +15,10 @@ New Features
* Add support for Python 3.10 (#554).
* Replace D10X errors with D419 if docstring exists but is empty (#559).

Bug Fixes

* Fix ``--match`` option to only consider filename when matching full paths (#550).
samj1912 marked this conversation as resolved.
Show resolved Hide resolved

6.1.1 - May 17th, 2021
---------------------------

Expand Down
4 changes: 2 additions & 2 deletions src/pydocstyle/config.py
Expand Up @@ -288,7 +288,7 @@ def _get_property_decorators(conf):
# Skip any dirs that do not match match_dir
dirs[:] = [d for d in dirs if match_dir(d)]

for filename in filenames:
for filename in map(os.path.basename, filenames):
if match(filename):
samj1912 marked this conversation as resolved.
Show resolved Hide resolved
full_path = os.path.join(root, filename)
yield (
Expand All @@ -302,7 +302,7 @@ def _get_property_decorators(conf):
match, _ = _get_matches(config)
ignore_decorators = _get_ignore_decorators(config)
property_decorators = _get_property_decorators(config)
if match(name):
if match(os.path.basename(name)):
samj1912 marked this conversation as resolved.
Show resolved Hide resolved
yield (
name,
list(config.checked_codes),
Expand Down
22 changes: 22 additions & 0 deletions src/tests/test_integration.py
Expand Up @@ -1489,3 +1489,25 @@ def test_comment_with_noqa_plus_docstring_file(env):
out, _, code = env.invoke()
assert '' == out
assert code == 0


def test_match_considers_basenames_for_path_args(env):
"""Test that `match` option only considers basenames for path arguments.

The test environment consists of a single empty module `test_a.py`. The
match option is set to a pattern that ignores test_ prefixed .py filenames.
When pydocstyle is invoked with full path to `test_a.py`, we expect it to
succeed since match option will match against just the file name and not
full path.
"""
# Ignore .py files prefixed with 'test_'
env.write_config(select='D100', match='(?!test_).+.py')

# Create an empty module (violates D100)
with env.open('test_a.py', 'wt') as test:
test.write('')

# env.invoke calls pydocstyle with full path to test_a.py
out, _, code = env.invoke(target='test_a.py')
assert '' == out
assert code == 0