python_cq.rst 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. Python code quality
  3. ===================
  4. U-Boot has about 60k lines of Python code, mainly in the following areas:
  5. - tests
  6. - pytest hooks
  7. - patman patch submission tool
  8. - buildman build / analysis tool
  9. - dtoc devicetree-to-C tool
  10. - binman firmware packaging tool
  11. `PEP 8`_ is used for the code style, with the single quote (') used by default for
  12. strings and double quote for doc strings. All non-trivial functions should be
  13. commented.
  14. Pylint is used to help check this code and keep a consistent code style. The
  15. build system tracks the current 'score' of the source code and detects
  16. regressions in any module.
  17. To run this locally you should use this version of pylint::
  18. # pylint --version
  19. pylint 2.11.1
  20. astroid 2.8.6
  21. Python 3.8.10 (default, Sep 28 2021, 16:10:42)
  22. [GCC 9.3.0]
  23. You should be able to select and this install other required tools with::
  24. pip install pylint==2.11.1
  25. pip install -r test/py/requirements.txt
  26. pip install asteval pyopenssl
  27. Note that if your distribution is a year or two old, you make need to use `pip3`
  28. instead.
  29. To configure pylint, make sure it has docparams enabled, e.g. with::
  30. echo "[MASTER]" >> .pylintrc
  31. echo "load-plugins=pylint.extensions.docparams" >> .pylintrc
  32. Once everything is ready, use this to check the code::
  33. make pylint
  34. This creates a directory called `pylint.out` which contains the pylint output
  35. for each Python file in U-Boot. It also creates a summary file called
  36. `pylint.cur` which shows the pylint score for each module::
  37. _testing 0.83
  38. atf_bl31 -6.00
  39. atf_fip 0.49
  40. binman.cbfs_util 7.70
  41. binman.cbfs_util_test 9.19
  42. binman.cmdline 7.73
  43. binman.control 4.39
  44. binman.elf 6.42
  45. binman.elf_test 5.41
  46. ...
  47. This file is in alphabetical order. The build system compares the score of each
  48. module to `scripts/pylint.base` (which must also be sorted and have exactly the
  49. same modules in it) and reports any files where the score has dropped. Use
  50. pylint to check what is wrong and fix up the code before you send out your
  51. patches.
  52. New or removed files results in an error which can be resolved by updating the
  53. `scripts/pylint.base` file to add/remove lines for those files, e.g.::
  54. meld pylint.cur scripts/pylint.base
  55. If the pylint version is updated in CI, this may result in needing to regenerate
  56. `scripts/pylint.base`.
  57. .. _`PEP 8`: https://www.python.org/dev/peps/pep-0008/