Skip to content

lint: convert spellchecking lint test to python #24766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2022

Conversation

fjahr
Copy link
Contributor

@fjahr fjahr commented Apr 4, 2022

The new python version should produce the exact same output as the bash version but be easier to maintain.

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 4, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #24750 (doc: Add bash dependency of lint tests by fjahr)
  • #24435 (test: Refactor subtree exclusion in lint tests by maxraustin)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@fanquake
Copy link
Member

fanquake commented Apr 5, 2022

Concept ACK - can you rebase now that #24762 has been merged.

@laanwj
Copy link
Member

laanwj commented Apr 5, 2022

Concept ACK, thanks!

@theStack
Copy link
Contributor

theStack commented Apr 5, 2022

Concept ACK

Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

@fjahr fjahr force-pushed the pr24762-spelling branch from 494e991 to 49b0213 Compare April 5, 2022 21:56
@fjahr fjahr force-pushed the pr24762-spelling branch from 49b0213 to 4685463 Compare April 5, 2022 22:19
@fjahr
Copy link
Contributor Author

fjahr commented Apr 5, 2022

Rebased and added the error handling in case codespell is not installed which I had omitted in the last push and also avoided usage of shell=True.

@maflcko
Copy link
Member

maflcko commented Apr 6, 2022

cr ACK 4685463

codespell_args = ['codespell', '--check-filenames', '--disable-colors', '--quiet-level=7', '--ignore-words={}'.format(IGNORE_WORDS_FILE)] + files

try:
check_output(codespell_args, stderr=STDOUT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this print the spelling mistakes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it does but testing on more platforms might be a good idea :)

$ test/lint/lint-spelling.py
configure.ac:364: overriden ==> overridden
configure.ac:860: overriden ==> overridden
src/wallet/coinselection.h:228: Chooose ==> Choose
^ Warning: codespell identified likely spelling errors. Any false positives? Add them to the list of ignored words in test/lint/spelling.ignore-words.txt

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it should. I just missed the print(e.output.decode line below. 🤦‍♂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I guess an alternative would be to use subprocess.check_call and not redirect the output at all or print() it?

@maflcko maflcko merged commit 70c5220 into bitcoin:master Apr 6, 2022
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some nits for your future transpiles, feel free to ignore.

Note: Will exit successfully regardless of spelling errors.
"""

from subprocess import check_output, STDOUT, CalledProcessError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit for future rewrites. I slightly prefer import subprocess and then subprocess.symbol in the code below. It is more verbose but clearer.

from subprocess import check_output, STDOUT, CalledProcessError

IGNORE_WORDS_FILE = 'test/lint/spelling.ignore-words.txt'
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"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Add trailing , and put each token on a newline to make editing and reading easier?

codespell_args = ['codespell', '--check-filenames', '--disable-colors', '--quiet-level=7', '--ignore-words={}'.format(IGNORE_WORDS_FILE)] + files

try:
check_output(codespell_args, stderr=STDOUT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I guess an alternative would be to use subprocess.check_call and not redirect the output at all or print() it?

check_output(codespell_args, stderr=STDOUT)
except CalledProcessError as e:
print(e.output.decode("utf-8"), end="")
print('^ Warning: codespell identified likely spelling errors. Any false positives? Add them to the list of ignored words in {}'.format(IGNORE_WORDS_FILE))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can use f-strings in new code

@laanwj laanwj mentioned this pull request Apr 6, 2022
25 tasks
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 6, 2022
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, working for me on debian.

laanwj added a commit to bitcoin-core/gui that referenced this pull request Apr 18, 2022
47b66ac lint: Convert Python linter to Python (Fabian Jahr)

Pull request description:

  The outputs provided by the Python version should be exactly the same as the ones from the shell version.

  There is small improvement here: Previously only the dependency of `flake9` was checked, now all dependencies are checked before running.

  I also tried to mostly follow the [recommendations here](bitcoin/bitcoin#24766 (review)) but happy to make more changes if there is still room for improvement.

ACKs for top commit:
  laanwj:
    Tested ACK 47b66ac

Tree-SHA512: 1630188e176c1063b8905669b76682b361a858cde6990ab17e51ad4333bf376eab796050cdb9f2967b84f1f74379d9e860c4258561b1964e1a47183c593e5bb4
@bitcoin bitcoin locked and limited conversation to collaborators Apr 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants