-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add cross-platform scripts for spelling and linting
This ensures that tox does not use any platform-specific commands.
- Loading branch information
1 parent
6def732
commit 830e7f7
Showing
6 changed files
with
115 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Create the whitelist.txt file used by the flake8-spellcheck plugin. | ||
We maintain our project dictionaries in separate files for convenience. This | ||
script simply concatenates them into a single file for use by the plugin. | ||
It's equivalent to the bash command: | ||
bash -c 'cat .wordlist.txt .wordlist_python_pytest.txt .wordlist_opcodes.txt > whitelist.txt' | ||
But is written in Python for use in tox to make it cross-platform. | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
|
||
def main(): | ||
""" | ||
Create the whitelist.txt file used by the flake8-spellcheck plugin. | ||
""" | ||
paths = [ | ||
Path(".wordlist.txt"), | ||
Path(".wordlist_python_pytest.txt"), | ||
Path(".wordlist_opcodes.txt"), | ||
] | ||
with open("whitelist.txt", "w") as whitelist: | ||
for path in paths: | ||
with open(path) as wordlist: | ||
whitelist.write(wordlist.read()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
Lint the markdown in ./README.md and ./docs/ using the external command | ||
markdownlint-cli2. | ||
This script's purpose is: | ||
1. Run the external command markdownlint-cli2 as a subprocess if it's | ||
installed, if not fail silently. The aim is to avoid disruption to | ||
external contributors who may not even be working on the docs. | ||
2. Keep tox cross-platform by not insisting on any external commands | ||
(including bash). | ||
""" | ||
|
||
import shutil | ||
import subprocess | ||
import sys | ||
|
||
|
||
def main(): | ||
""" | ||
Run markdownlint-cli2 as a subprocess if it's installed, if not fail silently. | ||
""" | ||
markdownlint = shutil.which("markdownlint-cli2") | ||
if not markdownlint: | ||
# Note: There's an additional step in test.yaml to run markdownlint-cli2 in github actions | ||
print("********* Install 'markdownlint-cli2' to enable markdown linting *********") | ||
sys.exit(0) | ||
|
||
command = ["node", str(markdownlint), "./docs/**/*.md", "./README.md"] | ||
sys.exit(subprocess.run(command).returncode) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Spellcheck the markdown in ./README.md and ./docs/ using the pyspelling | ||
package. | ||
Pyspelling requires aspell as an external dependency. This script's purpose | ||
is to: | ||
1. Run pyspelling if aspell is installed, if not fail silently. The aim is to | ||
avoid disruption to external contributors who may not even be working on | ||
the docs. | ||
2. Keep tox cross-platform by not insisting on any external commands (including | ||
bash). | ||
""" | ||
|
||
import os | ||
import shutil | ||
import sys | ||
|
||
from pyspelling import __main__ as pyspelling_main # type: ignore | ||
|
||
|
||
def main(): | ||
""" | ||
Run pyspelling if aspell is installed, if not fail silently. | ||
""" | ||
if not shutil.which("aspell"): | ||
print("aspell not installed, skipping spellcheck.") | ||
if os.environ.get("GITHUB_ACTIONS"): | ||
sys.exit(1) | ||
else: | ||
print("********* Install 'aspell' and 'aspell-en' to enable spellcheck *********") | ||
sys.exit(0) | ||
|
||
sys.exit(pyspelling_main.main()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters