Skip to content

Commit

Permalink
ignore file to ignore words
Browse files Browse the repository at this point in the history
  • Loading branch information
gokulprathin8 committed Mar 27, 2024
1 parent f12593b commit 0c2133b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/qaqc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ jobs:
run: |
python .github/workflows/ensure_clean_notebooks.py
# NOTE: this isn't a comprehensive spellcheck, just common typos
- name: Spellcheck
if: always()
uses: codespell-project/actions-codespell@master
with:
check_filenames: true
check_hidden: true
skip: .git,.github/workflows/qaqc.yaml
ignore_words_list: slippy,hist,NAM,gage
- name: Install pyspellchecker
run: |
pip install pyspellchecker
- name: Custom Spellcheck with Ignore List
run: python .github/workflows/spellcheck.py

# borrowed from https://github.com/ProjectPythia/pythia-foundations/blob/main/.github/workflows/link-checker.yaml
- name: Disable Notebook Execution Before Linkcheck
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/spellcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from spellchecker import SpellChecker
import nbformat
import os
import sys # Import sys for exiting with a non-zero status code

def spell_check_notebook(filepath, ignore_words):
spell = SpellChecker()
spell.word_frequency.load_words(ignore_words)

has_errors = False # Flag to track if there are any spelling errors

with open(filepath, 'r', encoding='utf-8') as f:
nb = nbformat.read(f, as_version=4)

for cell in nb.cells:
if cell.cell_type == 'markdown':
text = cell.source
misspelled = spell.unknown(text.split())
if misspelled:
if not has_errors: # Print the header once per file
print(f"Misspelled words in {filepath}:")
has_errors = True
for word in misspelled:
print(f"- {word}")
if has_errors:
print("\n") # Print a newline for readability between files
return True # Return True to indicate spelling errors were found
return False

def spell_check_directory(directory, ignore_words):
error_found = False
for subdir, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.ipynb'):
filepath = os.path.join(subdir, file)
if spell_check_notebook(filepath, ignore_words):
error_found = True # Error found in at least one file

if error_found:
sys.exit(1) # Exit with a non-zero status code to indicate failure

if __name__ == "__main__":
ignore_list = ['slippy', 'hist', 'NAM', 'gage'] # Adjust your ignore list as needed
spell_check_directory('.', ignore_list)

0 comments on commit 0c2133b

Please sign in to comment.