Port lint scripts to Python #24783

issue laanwj opened this issue on April 6, 2022
  1. laanwj commented at 11:46 AM on April 6, 2022: member

    To prevent endless issues when running the linters locally (say, on specific versions of bash, or system tools having certain names, or a certain implementation of sed, etc) , as well as for maintainability/reviewability, it's preferred for linter scripts to be written in Python.

    Here is a list of scripts, feel free to pick up any that haven't been ported:

    • test/lint/check-doc.py (added in #7280, was always Python)
    • test/lint/git-subtree-check.sh (in progress in #25039)
    • test/lint/lint-all.sh (ported in #24982)
    • test/lint/lint-assertions.sh (ported in #24856)
    • test/lint/lint-circular-dependencies.sh (ported in #24915)
    • test/lint/lint-cpp.sh (removed in #24785)
    • test/lint/lint-files.py (added in #21740, was always Python)
    • test/lint/lint-format-strings.sh (ported in #24802)
    • test/lint/lint-git-commit-check.sh (ported in #24853)
    • test/lint/lint-include-guards.sh (ported in #24902)
    • test/lint/lint-includes.sh (ported in #24895)
    • test/lint/lint-locale-dependence.sh (ported in #24932)
    • test/lint/lint-logs.sh (ported in #24849)
    • test/lint/lint-python-dead-code.py (ported in #24778)
    • test/lint/lint-python-mutable-default-parameters.sh (ported in #24800)
    • test/lint/lint-python.sh (ported in #24794)
    • test/lint/lint-python-utf8-encoding.sh (ported in #24916)
    • test/lint/lint-qt.sh (removed in #24790)
    • test/lint/lint-shell-locale.sh (ported in #24929)
    • test/lint/lint-shell.sh (ported in #24840)
    • test/lint/lint-spelling.py (ported in #24766)
    • test/lint/lint-submodule.sh (ported in #24803)
    • test/lint/lint-tests.sh (ported in #24815)
    • test/lint/lint-whitespace.sh (ported in #24844)
    • test/lint/run-lint-format-strings.py (added in #13705, was always Python)

    Although I try to keep this post up to date, before starting on a linter, please first do a github search in PRs to see if a PR for that already exists.

    Guidelines

    • Don't forget to update test/README.md when the name of a script changes.
    • Avoid shell=true on subprocess calls. Remember that the point here is to avoid shell ambiguities.
    • If possible, avoid calling out to subprocesses at all and use what Python APIs provide (say, grep sed awk sha256sum). An exception if this would introduce further dependencies that need to be installed. These are OK to use subprocess for:
      • git subcommands including git grepโ€”the alternative would be to require an extra dependency on a Python git module, also, git can be assumed to be the same implementation everywhere
      • Other scripts in the source tree.
      • External linters (vulture, codespell, etc) that provide only a command-based interface.
    • Some further recommendations about Python usage here: #24766#pullrequestreview-932953476

    Useful skills:

    • Python
    • Being able to read shell script

    Want to work on this issue?

    For guidance on contributing, please read CONTRIBUTING.md before opening your pull request.

  2. laanwj added the label Tests on Apr 6, 2022
  3. laanwj added the label good first issue on Apr 6, 2022
  4. arslan-raza-143 cross-referenced this on Apr 6, 2022 from issue Convert discovery processors into entity providers by Rugvip
  5. bitcoin deleted a comment on Apr 7, 2022
  6. Eunoia1729 commented at 6:27 AM on April 7, 2022: contributor

    Picking lint-format-strings.sh to start with.

  7. fanquake cross-referenced this on Apr 7, 2022 from issue tests: commit-script-check.sh - use gsed if exists by RandyMcMillan
  8. laanwj commented at 11:56 AM on April 7, 2022: member

    Picking lint-format-strings.sh to start with.

    Thanks! It should be a fairly straightforward one, as it already calls into a Python script, run-lint-format-strings.py, to do the brunt of the work. Could turn that into a module instead of subprocess. Mostlyt a matter of replacing the grep with Python code.

  9. KevinMusgrave commented at 3:59 PM on April 7, 2022: contributor

    I'll try lint-python-mutable-default-parameters.sh

  10. KevinMusgrave cross-referenced this on Apr 7, 2022 from issue lint: convert lint-python-mutable-default-parameters.sh to Python by KevinMusgrave
  11. Eunoia1729 cross-referenced this on Apr 7, 2022 from issue lint: convert format strings linter test to python by Eunoia1729
  12. Eunoia1729 cross-referenced this on Apr 7, 2022 from issue lint: convert submodule linter test to Python by Eunoia1729
  13. MarcoFalke commented at 8:05 AM on April 8, 2022: member

    Reminder that review is more important than porting, so I encourage and recommend that anyone who opened a pull request to port to also review at least one other port pull request.

  14. Kvaciral commented at 1:33 PM on April 8, 2022: contributor

    I'd like to port lint-whitespace.sh

  15. KevinMusgrave commented at 10:03 PM on April 9, 2022: contributor

    I'll do lint-tests.sh

  16. KevinMusgrave cross-referenced this on Apr 9, 2022 from issue lint: convert lint-tests.sh to python by KevinMusgrave
  17. Eunoia1729 commented at 4:33 AM on April 10, 2022: contributor

    Picking lint-shell-locale.sh next

  18. whiteh0rse commented at 10:15 PM on April 10, 2022: contributor

    I'll give a stab at test/lint/lint-shell.sh.

  19. MarcoFalke referenced this in commit 22e3b6f4d5 on Apr 11, 2022
  20. sidhujag referenced this in commit 50195ebdc9 on Apr 11, 2022
  21. MarcoFalke commented at 7:31 AM on April 13, 2022: member

    Also, if you port a script, make sure to test that a failure looks similar before and after the change. Ideally, leave a comment with the output copy-pasted or a screenshot in the pull request.

  22. Kvaciral cross-referenced this on Apr 13, 2022 from issue lint: Convert lint-whitespace.sh to Python by Kvaciral
  23. Kvaciral cross-referenced this on Apr 14, 2022 from issue lint: Convert lint-logs.sh to Python by Kvaciral
  24. Kvaciral commented at 1:41 AM on April 14, 2022: contributor

    Giving a port of /test/lint/lint-git-commit-check.sh a go next..

  25. Kvaciral cross-referenced this on Apr 14, 2022 from issue lint: Convert lint-git-commit-check.sh to Python by Kvaciral
  26. MarcoFalke referenced this in commit d0f7493b6c on Apr 14, 2022
  27. hiagopdutra commented at 7:28 PM on April 14, 2022: contributor

    I'll port the test/lint/lint-assertions.sh

  28. hiagopdutra cross-referenced this on Apr 14, 2022 from issue lint: Converting lint-assertions.sh to lint-assertions.py by hiagopdutra
  29. laanwj cross-referenced this on Apr 15, 2022 from issue Subtree exclude mess in linters and update scripts by laanwj
  30. Kvaciral commented at 1:42 PM on April 15, 2022: contributor

    Working on a port of /test/lint/lint-includes.sh now..

  31. Kvaciral cross-referenced this on Apr 16, 2022 from issue lint: Convert lint-includes.sh to Python by Kvaciral
  32. brunoerg cross-referenced this on Apr 17, 2022 from issue test: Convert non-wallet tests to use our python MiniWallet by MarcoFalke
  33. anibilthare commented at 4:12 PM on April 17, 2022: none

    Since python 3.5, run() API is available in subprocess module. In a situation where one can use both the APIs run() and check_output() is there a preference to one over the other? Backward compatibility maybe?

  34. brydinh commented at 4:24 PM on April 17, 2022: contributor

    Giving test/lint/lint-include-guards.sh a shot.

  35. brydinh cross-referenced this on Apr 17, 2022 from issue lint: Convert lint-include-guards.sh to Python by brydinh
  36. akankshakashyap cross-referenced this on Apr 18, 2022 from issue lint: ported lint-test.sh to lint-test.py by akankshakashyap
  37. laanwj commented at 1:29 PM on April 18, 2022: member

    Since python 3.5, run() API is available in subprocess module. In a situation where one can use both the APIs run() and check_output() is there a preference to one over the other? Backward compatibility maybe?

    It's fine to use either imo. But the general tendency I'm seeing is that check_output is used in the linters when stdout is needed. run is more flexible, and also allows for other combinations of settings.

  38. laanwj commented at 1:57 PM on April 18, 2022: member

    Although I try to keep the OP up to date, before starting on a linter, please first do a github search in PRs to see if a PR for that already exists.

  39. laanwj referenced this in commit 3059d4dd72 on Apr 18, 2022
  40. laanwj referenced this in commit 5fdf37e14b on Apr 18, 2022
  41. Smlep commented at 9:48 PM on April 18, 2022: contributor

    Hey ๐Ÿ‘‹ I'll port test/lint/lint-circular-dependencies.sh

    Edit: done (https://github.com/bitcoin/bitcoin/pull/24915)

  42. Smlep cross-referenced this on Apr 18, 2022 from issue lint: Convert lint-circular-dependencies.sh to Python by Smlep
  43. Kvaciral cross-referenced this on Apr 19, 2022 from issue lint: Convert lint-python-utf8-encoding.sh to Python by Kvaciral
  44. sidhujag referenced this in commit d100a1c133 on Apr 19, 2022
  45. Kvaciral commented at 12:02 PM on April 19, 2022: contributor

    I'll be working on the port of lint-locale-depence.sh next..

  46. Eunoia1729 cross-referenced this on Apr 20, 2022 from issue lint: convert shell locale linter test to Python by Eunoia1729
  47. MarcoFalke referenced this in commit fc99f8c09e on Apr 20, 2022
  48. laanwj commented at 12:49 PM on April 20, 2022: member

    I've removed commit-script-check.sh from the list as it's a) not a linter b) messes with the git tree c) intentionally invokes shell script, so there's little to pythonize about it unless we change scripted-diffs to use Python, which is way outside scope of this issue.

  49. MarcoFalke commented at 12:57 PM on April 20, 2022: member

    Not sure what the status of "extended-lint" is. Can this be removed?

  50. laanwj commented at 1:21 PM on April 20, 2022: member

    Not sure what the status of "extended-lint" is. Can this be removed?

    Good point. It doesn't seem to be invoked as part of the CI at all?

    I guess the cppcheck linter can be part of the normal lints, or removed completely? I'm a bit confused. I would have assumed it was still active as of #20530, when the cppcheck version was upgraded. But also looks like fa2941bbf47a8a6b79b8db4a87e1aedcf6a29a5e already removed it from the CI in 2019.

    Anyhow, removed from the list, there's no point in wasting anyone's time porting it if it's probably going away.

  51. MarcoFalke commented at 1:25 PM on April 20, 2022: member

    I don't have access to logs at this point, but I am assuming I removed it because it was failing.

  52. Kvaciral cross-referenced this on Apr 20, 2022 from issue lint: Convert lint-locale-dependence.sh to Python by Kvaciral
  53. goldeneagle3636 commented at 12:57 AM on April 21, 2022: none

    I'd like to convert test/lint/git-subtree-check.sh.

  54. laanwj referenced this in commit 2513499348 on Apr 21, 2022
  55. sidhujag referenced this in commit 57d8585eac on Apr 22, 2022
  56. laanwj referenced this in commit 7134327be5 on Apr 25, 2022
  57. laanwj referenced this in commit c90b42bcdb on Apr 25, 2022
  58. laanwj referenced this in commit 8b686776ef on Apr 25, 2022
  59. laanwj referenced this in commit 777b89b300 on Apr 25, 2022
  60. laanwj referenced this in commit 0342ae1d39 on Apr 25, 2022
  61. laanwj referenced this in commit 9eedbe98c8 on Apr 25, 2022
  62. laanwj referenced this in commit 16fa967d3c on Apr 25, 2022
  63. laanwj referenced this in commit 1e7db37e76 on Apr 25, 2022
  64. laanwj commented at 5:50 PM on April 25, 2022: member

    Looks like we're almost done here!

  65. hiagopdutra commented at 6:14 PM on April 25, 2022: contributor

    I'll convert the test/lint/lint-all.sh to finish it!

  66. hiagopdutra cross-referenced this on Apr 25, 2022 from issue tests: Port `lint-all.sh` to `lint-all.py` by hiagopdutra
  67. sidhujag referenced this in commit 03867261ad on Apr 26, 2022
  68. sidhujag referenced this in commit ea3961c0ac on Apr 26, 2022
  69. sidhujag referenced this in commit d4371f17a5 on Apr 26, 2022
  70. sidhujag referenced this in commit 80390805ab on Apr 26, 2022
  71. laanwj referenced this in commit 85aea18ae6 on Apr 28, 2022
  72. jacobpfickes cross-referenced this on Apr 30, 2022 from issue lint: convert git-subtree-check.sh to Python by jacobpfickes
  73. laanwj removed the label good first issue on May 9, 2022
  74. laanwj commented at 9:23 AM on May 9, 2022: member

    I'm going to close this issue. The test/lint/git-subtree-check.sh port is still under review, but all the linters have been ported and merged, so there's no need for this issue to attract attention anymore.

    Thanks everyone for the help!

  75. laanwj closed this on May 9, 2022

  76. hebasto cross-referenced this on Aug 10, 2022 from issue build: Add CMake-based build system by hebasto
  77. PulpCattel cross-referenced this on Dec 29, 2022 from issue Apply all current ShellCheck suggestions and add `lint-shell.sh` by kristapsk
  78. bitcoin locked this on May 9, 2023
Labels
Linked (view graph)
#7280 [travis] Fail when documentation is outdated#13705 build: Add format string linter#17413 Subtree exclude mess in linters and update scripts#20078 test: Convert non-wallet tests to use our python MiniWallet#21740 test: add new python linter to check file names and permissions#24159 tests: commit-script-check.sh - use gsed if exists#24766 lint: convert spellchecking lint test to python#24778 lint: Convert Python dead code linter test to Python#24785 lint: remove boost::bind lint#24790 lint: remove qt SIGNAL/SLOT lint#24794 lint: Convert Python linter to Python#24800 lint: convert lint-python-mutable-default-parameters.sh to Python#24802 lint: convert format strings linter test to python#24803 lint: convert submodule linter test to Python#24815 lint: convert lint-tests.sh to python#24840 test: port 'lint-shell.sh' to python#24844 lint: Convert lint-whitespace.sh to Python#24849 lint: Convert lint-logs.sh to Python#24853 lint: Convert lint-git-commit-check.sh to Python#24856 lint: Converting lint-assertions.sh to lint-assertions.py#24895 lint: Convert lint-includes.sh to Python#24902 lint: Convert lint-include-guards.sh to Python#24905 lint: ported lint-test.sh to lint-test.py#24915 lint: Convert lint-circular-dependencies.sh to Python#24916 lint: Convert lint-python-utf8-encoding.sh to Python#24929 lint: convert shell locale linter test to Python#24932 lint: Convert lint-locale-dependence.sh to Python#24982 tests: Port `lint-all.sh` to `lint-all.py`#25039 lint: convert git-subtree-check.sh to Python#25797 build: Add CMake-based build system

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:53 UTC