Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ jobs:
choco install python --version=<< parameters.python-version >> --allow-downgrade -y
python -m pip install --upgrade pip
fi
- run:
name: Install enchant on non windows systems <Linux>
command: |
if [ "$RUNNER_OS" == "linux" ]; then
sudo apt-get update
sudo apt-get install enchant-2
elif [ "$RUNNER_OS" == "macos" ]; then
brew update
brew install enchant
fi
- run:
name: Install dependencies
command: |
Expand Down
16 changes: 1 addition & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,6 @@ jobs:
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
# on windows, the pyenchant package includes enchant
- name: Install enchant on non windows systems
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update
sudo apt-get install enchant-2
elif [ "$RUNNER_OS" == "macOS" ]; then
brew update-reset
brew install enchant
fi
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -81,10 +70,7 @@ jobs:
if: steps.nbl.outputs.any_changed == 'true'
env:
SIMPLE_ITK_MEMORY_CONSTRAINED_ENVIRONMENT: 1
run: | # pyenchant has a problem locating libenchant on macOS-ARM64. setting this environment variable resolves the issue
if [ "$RUNNER_OS" == "macOS" ] && [ "${{ matrix.os }}" != "macos-15-intel" ]; then
export PYENCHANT_LIBRARY_PATH=/opt/homebrew/lib/libenchant-2.dylib
fi
run: |
test_files="${{ steps.nbl.outputs.all_changed_files }}"
# on windows the paths use backslashes, so replace with forward slashes
if [ "$RUNNER_OS" == "Windows" ]; then
Expand Down
16 changes: 1 addition & 15 deletions .github/workflows/scheduled_or_manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,6 @@ jobs:
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
# on windows, the pyenchant package includes enchant
- name: Install enchant on non windows systems
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update
sudo apt-get install enchant-2
elif [ "$RUNNER_OS" == "macOS" ]; then
brew update-reset
brew install enchant
fi
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -78,9 +67,6 @@ jobs:
shell: bash
env:
SIMPLE_ITK_MEMORY_CONSTRAINED_ENVIRONMENT: 1
run: | # pyenchant has a problem locating libenchant on macOS-ARM64. setting this environment variable resolves the issue
if [ "$RUNNER_OS" == "macOS" ] && [ "${{ matrix.os }}" != "macos-15-intel" ]; then
export PYENCHANT_LIBRARY_PATH=/opt/homebrew/lib/libenchant-2.dylib
fi
run: |
pytest -v --tb=short -k "${{matrix.inputs}}" tests/test_notebooks.py::Test_notebooks::test_python_notebook
pytest -v --tb=short tests/test_scripts.py
4 changes: 1 addition & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ verify it before we merge it into the main repository.
We use the [pytest](https://docs.pytest.org) Python testing framework as our test
driver for both the Python and R notebooks. Testing relies on several Python
packages listed in the [requirements_dev.txt](requirements_dev.txt) file. Please
install these packages. Note that we use the pyenchant
spell checker which is only available by using the pip package manager
(no conda). This spell checker relies on the [enchant](https://rrthomas.github.io/enchant/) library (`brew install enchant`, `sudo apt-get install enchant`).
install these packages.

When you add a new notebook, you will need to add it to the relevant list of
notebooks found in the [test_notebooks.py](tests/test_notebooks.py). These
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ black[jupyter]
pytest
markdown
lxml
pyenchant
comment-spell-check
ipython<=8.12
-rPython/requirements.txt
30 changes: 29 additions & 1 deletion tests/additional_dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@

rm
Assoc
phys
Trans
rel
hist
tuples
cc
resize
Med
Phys
Vol
pp
km
resized
workflows
int
compositing
mp
tuple
workaround
mm
res
div
etc
Multi
multi
LabelMapContourOverlay
MergeLabelMapFilter's
ipympl
Expand All @@ -21,7 +49,7 @@ BSplineTransform
BSplineTransformInitializer
BSplineTransformInitializerFilter
Baum
Bérard
Berard
Biancardi
Bimodal
BinaryMorphologicalClosing
Expand Down
52 changes: 22 additions & 30 deletions tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import re
import urllib.request

from enchant.checker import SpellChecker
from enchant.tokenize import Filter, EmailFilter, URLFilter
from enchant import DictWithPWL
from comment_parser.parsers.common import Comment
from comment_spell_check.comment_spell_check import spell_check_comment
from comment_spell_check.utils.create_checker import create_checker

from lxml.html import document_fromstring, etree
from urllib.request import urlopen, URLError, Request
Expand Down Expand Up @@ -250,44 +250,36 @@ def static_analysis(self, path):
print("no broken links")

#######################
# Spell check all markdown cells and comments in code cells using the pyenchant spell checker.
# Spell check all markdown cells and comments in code cells using the
# CommentSpellCheck package.
#######################
no_spelling_mistakes = True
simpleitk_notebooks_dictionary = DictWithPWL(
"en_US",
os.path.join(
os.path.dirname(os.path.abspath(__file__)), "additional_dictionary.txt"
),
)
spell_checker = SpellChecker(
simpleitk_notebooks_dictionary, filters=[EmailFilter, URLFilter]
spell_checker = create_checker(
[
os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"additional_dictionary.txt",
)
]
)
prefixes = ["sitk", "itk", "vtk"]
cells_and_spelling_mistakes = []
for c in nb.cells:
spelling_mistakes = []
if c.cell_type == "markdown":
# Get the text as a string from the html without the markup which is replaced by space.
spell_checker.set_text(
" ".join(
etree.XPath("//text()")(
document_fromstring(markdown.markdown(c.source))
)
text = " ".join(
etree.XPath("//text()")(
document_fromstring(markdown.markdown(c.source))
)
)
elif c.cell_type == "code":
# Get all the comments and concatenate them into a single string separated by newlines.
comment_lines = re.findall("#+.*", c.source)
spell_checker.set_text("\n".join(comment_lines))
for error in spell_checker:
error_message = (
"error: "
+ "'"
+ error.word
+ "', "
+ "suggestions: "
+ str(spell_checker.suggest())
)
spelling_mistakes.append(error_message)
text = "\n".join(re.findall("#+.*", c.source))
else:
continue
# Line number is irrelevant, the whole cell's text is checked as one unit.
mistakes = spell_check_comment(spell_checker, Comment(text, 1), prefixes=prefixes)
spelling_mistakes = ["error: " + mistake for mistake in mistakes]
if spelling_mistakes:
cells_and_spelling_mistakes.append((spelling_mistakes, c.source))
if cells_and_spelling_mistakes:
Expand Down
Loading