Pylint Guide
Overview
This guide illustrates how to modify the .pylintrc file to enable lint exclusions in your repo, eliminating the need to create a Help Desk ticket to add exclusions to your product YAML configuration.
Configuration
The following .pylintrc is an example from the python-world project .
[DESIGN]
[TYPECHECK]
[MASTER]
ignore=tests
disable=missing-function-docstring,
missing-class-docstring,
invalid-name
[MESSAGES CONTROL]
[FORMAT]
max-line-length=100Under the MASTER section of the .pylintrc file, add "ignore=path/file". In the example above, any directories that contain .cache/ and python_packages/ will be excluded from the pylint job.
Generating .pylintrc
# To generate a .pylintrc file, run the following command
pylint --generate-rcfile # This will place the .pylintrc file in the current directory
pylint --generate-rcfile > directory/path/of/your/choice # This will place the .pylintrc file in the directory of your choosingNOTE
Additional switches must be placed in front of --generate-rcfile.
# This is an example pylint generation
pylint --ignore=^.*\/cache\/ --generate-rcfileExamples
This example loosens Pylint’s strictness by ignoring certain folders, disabling docstring and naming warnings, and allowing lines up to 100 characters.
shell[DESIGN] [TYPECHECK] [MASTER] ignore-paths=^.*\.cache\/.*$, ^.*python_packages\/.*$ disable=missing-function-docstring, missing-class-docstring, invalid-name [MESSAGES CONTROL] [FORMAT] max-line-length=100This example configures Pylint to fail on errors, require a minimum score, allow certain short variable names, ignore docstring warnings, and use Django settings for string-based foreign keys.
shell[MASTER] fail-on=E fail-under=7.0 load-plugins=pylint_django py-version=3.8 [MESSAGES CONTROL] disable=missing-module-docstring, missing-class-docstring, missing-function-docstring [REPORTS] output-format=colorized reports=no score=yes [BASIC] good-names=i, j, k, ex, obj, Run, _ [DJANGO FOREIGN KEYS REFERENCED BY STRINGS] django-settings-module=scala_alocacao.settings
Troubleshooting
Missing init.py error
__init__.py:1:0: F0010: error while code parsing: Unable to load file /builds/platform-one/products/widow/widow-python/__init__.py:
[Errno 2] No such file or directory: '/builds/platform-one/products/widow/widow-python/__init__.py' (parse-error)
ERROR: Job failed: command terminated with exit code 1The current pipeline job runs pylint $(pwd). This is a folder-based scan. Pylint will consider this type a package-based scan. The package-based scan expects init.py files.
Review this article on Folder analysis fails if 'init.py' is not present.
If your team cannot add the init.py files, submit a Pipeline Issue ticket with the Help Desk and request the use of a pylint file-based scan.