[azure-pylint-guidelines-checker] pylint checkers not picking up full pkg path when path extension __init__.py is missing
- Dominant language
- C#
- Stars
- 135
- Forks
- 260
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 143
Description
It seems like the pylint checkers are not picking up the full package path when the path extension __init__.py file is missing. I'm not sure fully certain whether this is specific to the azure checkers or the general ones, but I believe it applies to the azure checkers based on what I'm seeing.
When I run the linter with `pylint-guidelines-checker` specified on azure pkgs, the length of `linter.reporter.messages` is different b/w the whl (which doesn't include __init__.py extension files) and the src/sdist (both of which include __init__.py extension files). This causes issues with azure-core specifically, b/c the checkers that should be ignoring "azure.core" are not b/c they haven't picked up the path correctly.
Note: When I manually add in the __init__.py file to the extracted whl directory under `azure`, the length of messages is the same across all pkg types.
Versions:
* azure-pylint-guidelines==0.5.6
* pylint==3.3.6
* astroid==3.3.8
To repro:
1. Create a .pylintrc file:
```
[MASTER]
ignore-patterns=test_*,conftest,setup
reports=no
load-plugins=pylint_guidelines_checker
# PYLINT DIRECTORY IGNORE LIST
ignore=_vendor,_generated,samples,examples,test,tests,doc,.tox,build,dist
[MESSAGES CONTROL]
# Ignore ALL standard pylint checks.
disable=invalid-name,disallowed-name,empty-docstring,unneeded-not,missing-module-docstring,missing-class-docstring,missing-function-docstring,singleton-comparison,unidiomatic-typecheck,non-ascii-name,consider-using-enumerate,consider-iterating-dictionary,bad-classmethod-argument,bad-mcs-method-argument,bad-mcs-classmethod-argument,single-string-used-for-slots,consider-using-dict-items,use-maxsplit-arg,use-sequence-for-iteration,consider-using-f-string,line-too-long,too-many-lines,trailing-whitespace,missing-final-newline,trailing-newlines,multiple-statements,superfluous-parens,mixed-line-endings,unexpected-line-ending-format,wrong-spelling-in-comment,wrong-spelling-in-docstring,invalid-characters-in-docstring,multiple-imports,wrong-import-order,ungrouped-imports,wrong-import-position,useless-import-alias,import-outside-toplevel,use-implicit-booleaness-not-len,use-implicit-booleaness-not-comparison,syntax-error,unrecognized-inline-option,bad-option-value,bad-plugin-value,bad-configuration-specification,init-is-generator,return-in-init,function-redefined,not-in-loop,return-outside-function,yield-outside-function,nonexistent-operator,duplicate-argument-name,abstract-class-instantiated,bad-reversed-sequence,too-many-star-expressions,invalid-star-assignment-target,star-needs-assignment-target,nonlocal-and-global,nonlocal-without-binding,used-prior-global-declaration,misplaced-format-function,method-hidden,access-member-before-definition,no-method-argument,no-self-argument,invalid-slots-object,assigning-non-slot,invalid-slots,inherit-non-class,inconsistent-mro,duplicate-bases,class-variable-slots-conflict,invalid-class-object,non-iterator-returned,unexpected-special-method-signature,invalid-length-returned,invalid-bool-returned,invalid-index-returned,invalid-repr-returned,invalid-str-returned,invalid-bytes-returned,invalid-hash-returned,invalid-length-hint-returned,invalid-format-returned,invalid-getnewargs-returned,invalid-getnewargs-ex-returned,import-error,relative-beyond-top-level,used-before-assignment,undefined-variable,undefined-all-variable,invalid-all-object,invalid-all-format,no-name-in-module,unpacking-non-sequence,bad-except-order,raising-bad-type,bad-exception-context,misplaced-bare-raise,raising-non-exception,notimplemented-raised,catching-non-exception,bad-super-call,no-member,not-callable,assignment-from-no-return,no-value-for-parameter,too-many-function-args,unexpected-keyword-arg,redundant-keyword-arg,missing-kwoa,invalid-sequence-index,invalid-slice-index,assignment-from-none,not-context-manager,invalid-unary-operand-type,unsupported-binary-operation,repeated-keyword,not-an-iterable,not-a-mapping,unsupported-membership-test,unsubscriptable-object,unsupported-assignment-operation,unsupported-delete-operation,invalid-metaclass,unhashable-dict-key,dict-iter-missing-items,await-outside-async,logging-unsupported-format,logging-format-truncated,logging-too-many-args,logging-too-few-args,bad-format-character,truncated-format-string,mixed-format-string,format-needs-mapping,missing-format-string-key,too-many-format-args,too-few-format-args,bad-string-format-type,bad-str-strip-call,invalid-envvar-value,yield-inside-async-function,not-async-context-manager,fatal,astroid-error,parse-error,config-parse-error,method-check-failed,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,use-symbolic-message-instead,c-extension-no-member,literal-comparison,comparison-with-itself,no-self-use,no-classmethod-decorator,no-staticmethod-decorator,useless-object-inheritance,property-with-parameters,cyclic-import,consider-using-from-import,duplicate-code,too-many-ancestors,too-many-instance-attributes,too-few-public-methods,too-many-public-methods,too-many-return-statements,too-many-branches,too-many-arguments,too-many-locals,too-many-statements,too-many-boolean-expressions,consider-merging-isinstance,too-many-nested-blocks,simplifiable-if-statement,redefined-argument-from-local,no-else-return,consider-using-ternary,trailing-comma-tuple,stop-iteration-return,simplify-boolean-expression,inconsistent-return-statements,useless-return,consider-swap-variables,consider-using-join,consider-using-in,consider-using-get,chained-comparison,consider-using-dict-comprehension,consider-using-set-comprehension,simplifiable-if-expression,no-else-raise,unnecessary-comprehension,consider-using-sys-exit,no-else-break,no-else-continue,super-with-arguments,simplifiable-condition,condition-evals-to-constant,consider-using-generator,use-a-generator,consider-using-min-builtin,consider-using-max-builtin,consider-using-with,unnecessary-dict-index-lookup,use-list-literal,use-dict-literal,unreachable,dangerous-default-value,pointless-statement,pointless-string-statement,expression-not-assigned,unnecessary-pass,unnecessary-lambda,duplicate-key,assign-to-new-keyword,useless-else-on-loop,exec-used,eval-used,confusing-with-statement,using-constant-test,missing-parentheses-for-call-in-test,self-assigning-variable,redeclared-assigned-name,assert-on-string-literal,comparison-with-callable,lost-exception,nan-comparison,assert-on-tuple,attribute-defined-outside-init,bad-staticmethod-argument,protected-access,arguments-differ,signature-differs,abstract-method,super-init-not-called,no-init,non-parent-init-called,useless-super-delegation,invalid-overridden-method,arguments-renamed,unused-private-member,overridden-final-method,subclassed-final-class,unnecessary-semicolon,bad-indentation,wildcard-import,deprecated-module,reimported,import-self,preferred-module,misplaced-future,fixme,global-variable-undefined,global-variable-not-assigned,global-statement,global-at-module-level,unused-import,unused-variable,unused-argument,unused-wildcard-import,redefined-outer-name,redefined-builtin,undefined-loop-variable,unbalanced-tuple-unpacking,cell-var-from-loop,possibly-unused-variable,self-cls-assignment,bare-except,broad-except,duplicate-except,try-except-raise,raise-missing-from,binary-op-exception,raising-format-tuple,wrong-exception-operation,keyword-arg-before-vararg,arguments-out-of-order,non-str-assignment-to-dunder-name,isinstance-second-argument-not-valid-type,logging-not-lazy,logging-format-interpolation,logging-fstring-interpolation,bad-format-string-key,unused-format-string-key,bad-format-string,missing-format-argument-key,unused-format-string-argument,format-combined-specification,missing-format-attribute,invalid-format-index,duplicate-string-formatting-argument,f-string-without-interpolation,format-string-without-interpolation,anomalous-backslash-in-string,anomalous-unicode-escape-in-string,implicit-str-concat,inconsistent-quotes,redundant-u-string-prefix,bad-open-mode,redundant-unittest-assert,deprecated-method,bad-thread-instantiation,shallow-copy-environ,invalid-envvar-default,subprocess-popen-preexec-fn,subprocess-run-check,deprecated-argument,deprecated-class,deprecated-decorator,unspecified-encoding,forgotten-debug-statement,using-f-string-in-unsupported-version,using-final-decorator-in-unsupported-version,useless-with-lock,return-arg-in-generator,continue-in-finally,boolean-datetime,unnecessary-lambda-assignment,unnecessary-ellipsis
```
2. Run the following script:
```py
import os
import tempfile
import zipfile
import tarfile
from pylint.lint import Run
def extract_whl(file_path, temp_dir):
with zipfile.ZipFile(file_path, 'r') as zip_ref:
zip_ref.extractall(temp_dir)
def extract_sdist(file_path, temp_dir):
with tarfile.open(file_path, 'r:gz') as tar_ref:
tar_ref.extractall(temp_dir)
def run_linter(path, rcfile_path):
params = f"{path} -f json --recursive=y --rcfile {rcfile_path}".split(" ")
messages = Run(params, exit=False).linter.reporter.messages
return messages
def compare_messages(messages_whl, messages_sdist):
return messages_whl == messages_sdist
# Example usage
whl_file_path = 'azure_core-1.33.0-py3-none-any.whl'
sdist_file_path = 'azure_core-1.33.0.tar.gz'
rcfile_path = '.pylintrc'
with tempfile.TemporaryDirectory() as temp_dir_whl, tempfile.TemporaryDirectory() as temp_dir_sdist:
extract_whl(whl_file_path, temp_dir_whl)
extract_sdist(sdist_file_path, temp_dir_sdist)
messages_whl = run_linter(temp_dir_whl, rcfile_path)
messages_sdist = run_linter(temp_dir_sdist, rcfile_path)
print(f'whl msgs len: {len(messages_whl)}')
print(f'sdist msgs len: {len(messages_sdist)}')
are_same = compare_messages(messages_whl, messages_sdist)
print(f"Are the linter messages the same? {are_same}")
```
Contributor guide
Assessment
This issue has not been assessed yet.