From e7068872d393de26b1338728da3cacb6d2bdd738 Mon Sep 17 00:00:00 2001 From: oczkoisse Date: Sun, 15 Aug 2021 21:26:06 -0700 Subject: [PATCH 1/3] Fix --match to only consider path basename for matching --- src/pydocstyle/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pydocstyle/config.py b/src/pydocstyle/config.py index fe3afb3f..ed00c874 100644 --- a/src/pydocstyle/config.py +++ b/src/pydocstyle/config.py @@ -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 ( @@ -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), From 112e071498ae678186c3e78385392d6a01a1f1db Mon Sep 17 00:00:00 2001 From: oczkoisse Date: Sun, 15 Aug 2021 21:27:51 -0700 Subject: [PATCH 2/3] Add test for --match with path arguments --- src/tests/test_integration.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/tests/test_integration.py b/src/tests/test_integration.py index eb4994ff..85e37893 100644 --- a/src/tests/test_integration.py +++ b/src/tests/test_integration.py @@ -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 From da919fd687beba429d785499e4861b0e7f0002a9 Mon Sep 17 00:00:00 2001 From: oczkoisse Date: Sun, 15 Aug 2021 22:39:07 -0700 Subject: [PATCH 3/3] Add line in release notes --- docs/release_notes.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/release_notes.rst b/docs/release_notes.rst index f3a4c4d5..96ed5601 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -12,6 +12,10 @@ New Features * Add support for `property_decorators` config to ignore D401 +Bug Fixes + +* Fix ``--match`` option to only consider filename when matching full paths (#550). + 6.1.1 - May 17th, 2021 ---------------------------