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

Commit

Permalink
Fix match option to only consider basename when given a path argument (
Browse files Browse the repository at this point in the history
…#550)

Co-authored-by: Sambhav Kothari <sambhavs.email@gmail.com>
  • Loading branch information
oczkoisse and samj1912 committed Dec 30, 2021
1 parent 1011866 commit bd49933
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
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).

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):
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)):
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

0 comments on commit bd49933

Please sign in to comment.