Skip to content

Commit 70c5220

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24766: lint: convert spellchecking lint test to python
4685463 doc: Update lint test docs (Fabian Jahr) 77f98df lint: convert spell check lint test to python (Fabian Jahr) Pull request description: The new python version should produce the exact same output as the bash version but be easier to maintain. ACKs for top commit: MarcoFalke: cr ACK 4685463 Tree-SHA512: 242b802b750b42b299b93d1de4bcf17d92ad0a633d31894145d8590782a1db1041de59a283f133a4f75898d95444eb3c842005a6aa5cb919543625addad596d8
2 parents d3ff026 + 4685463 commit 70c5220

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

test/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ Use the `-v` option for verbose output.
310310
| [`lint-python.sh`](lint/lint-python.sh) | [pyzmq](https://github.com/zeromq/pyzmq)
311311
| [`lint-python-dead-code.py`](lint/lint-python-dead-code.py) | [vulture](https://github.com/jendrikseipp/vulture)
312312
| [`lint-shell.sh`](lint/lint-shell.sh) | [ShellCheck](https://github.com/koalaman/shellcheck)
313-
| [`lint-spelling.sh`](lint/lint-spelling.sh) | [codespell](https://github.com/codespell-project/codespell)
313+
| [`lint-spelling.py`](lint/lint-spelling.py) | [codespell](https://github.com/codespell-project/codespell)
314314

315315
In use versions and install instructions are available in the [CI setup](../ci/lint/04_install.sh).
316316

@@ -321,7 +321,7 @@ Please be aware that on Linux distributions all dependencies are usually availab
321321
Individual tests can be run by directly calling the test script, e.g.:
322322

323323
```
324-
test/lint/lint-files.sh
324+
test/lint/lint-files.py
325325
```
326326

327327
You can run all the shell-based lint tests by running:

test/lint/lint-spelling.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (c) 2022 The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
7+
"""
8+
Warn in case of spelling errors.
9+
Note: Will exit successfully regardless of spelling errors.
10+
"""
11+
12+
from subprocess import check_output, STDOUT, CalledProcessError
13+
14+
IGNORE_WORDS_FILE = 'test/lint/spelling.ignore-words.txt'
15+
FILES_ARGS = ['git', 'ls-files', '--', ":(exclude)build-aux/m4/", ":(exclude)contrib/seeds/*.txt", ":(exclude)depends/", ":(exclude)doc/release-notes/", ":(exclude)src/leveldb/", ":(exclude)src/crc32c/", ":(exclude)src/qt/locale/", ":(exclude)src/qt/*.qrc", ":(exclude)src/secp256k1/", ":(exclude)src/minisketch/", ":(exclude)src/univalue/", ":(exclude)contrib/builder-keys/keys.txt", ":(exclude)contrib/guix/patches"]
16+
17+
18+
def check_codespell_install():
19+
try:
20+
check_output(["codespell", "--version"])
21+
except FileNotFoundError:
22+
print("Skipping spell check linting since codespell is not installed.")
23+
exit(0)
24+
25+
26+
def main():
27+
check_codespell_install()
28+
29+
files = check_output(FILES_ARGS).decode("utf-8").splitlines()
30+
codespell_args = ['codespell', '--check-filenames', '--disable-colors', '--quiet-level=7', '--ignore-words={}'.format(IGNORE_WORDS_FILE)] + files
31+
32+
try:
33+
check_output(codespell_args, stderr=STDOUT)
34+
except CalledProcessError as e:
35+
print(e.output.decode("utf-8"), end="")
36+
print('^ Warning: codespell identified likely spelling errors. Any false positives? Add them to the list of ignored words in {}'.format(IGNORE_WORDS_FILE))
37+
38+
39+
if __name__ == "__main__":
40+
main()

test/lint/lint-spelling.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)