diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cc13b6c..865a394 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -22,10 +22,10 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Set up Python 3.11 + - name: Set up Python 3.12 uses: actions/setup-python@v4 with: - python-version: "3.11" + python-version: "3.12" - name: Build package run: | python -m pip install twine build diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index f55ee52..2dfa207 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -17,10 +17,10 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Set up Python 3.11 + - name: Set up Python 3.12 uses: actions/setup-python@v4 with: - python-version: 3.11 + python-version: "3.12" - name: set PY run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV - uses: actions/cache@v3 @@ -40,10 +40,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Python 3.9 + - name: Set up Python 3.12 uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: "3.12" cache: 'pip' - name: Install dependencies run: | diff --git a/README.md b/README.md index 0cce75f..7a46672 100644 --- a/README.md +++ b/README.md @@ -78,3 +78,6 @@ used the pyenchant package and its default dictionary. The pyenchant package requires an underlying C library, which is not available on all platforms. PySpellChecker is a pure Python package and works on all platforms with no additional dependencies. + +The `--bibtex` option adds words from citation keys to the dictionary and +requires bibtexparser 2.x. diff --git a/comment_spell_check/utils/bibtex_loader.py b/comment_spell_check/utils/bibtex_loader.py index 3373f78..07d4920 100644 --- a/comment_spell_check/utils/bibtex_loader.py +++ b/comment_spell_check/utils/bibtex_loader.py @@ -28,12 +28,10 @@ def add_bibtex(spell: spellchecker.SpellChecker, filename: str): word_list = [] - with open(filename, "rt", encoding="utf-8") as biblatex_file: - bib_database = bibtexparser.load(biblatex_file) + bib_database = bibtexparser.parse_file(filename) + for entry in bib_database.entries: + words = split_bibtex_name(entry.key) + word_list.extend(words) - for k in bib_database.get_entry_dict().keys(): - words = split_bibtex_name(k) - word_list.extend(words) - - logger.info("Words: %s", word_list) - spell.word_frequency.load_words(word_list) + logger.info("Words: %s", word_list) + spell.word_frequency.load_words(word_list) diff --git a/conda-env.txt b/conda-env.txt index 761114b..25518cd 100644 --- a/conda-env.txt +++ b/conda-env.txt @@ -1,34 +1,7 @@ -# This file may be used to create an environment using: -# $ conda create --name --file -# platform: osx-64 -@EXPLICIT -https://conda.anaconda.org/conda-forge/osx-64/ca-certificates-2019.9.11-hecc5488_0.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/jpeg-9b-he5867d9_2.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/libcxxabi-4.0.1-hcfea43d_1.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/xz-5.2.4-h1de35cc_4.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/zlib-1.2.11-h1de35cc_3.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/libcxx-4.0.1-hcfea43d_1.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/libpng-1.6.37-ha441bb4_0.tar.bz2 -https://conda.anaconda.org/conda-forge/osx-64/openssl-1.1.1c-h01d97ff_0.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/tk-8.6.8-ha441bb4_0.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/zstd-1.3.7-h5bba6e5_0.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/libffi-3.2.1-h475c297_4.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/libtiff-4.0.10-hcb84e12_2.tar.bz2 -https://conda.anaconda.org/conda-forge/osx-64/llvm-openmp-8.0.1-h770b8ee_0.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/ncurses-6.1-h0a44026_1.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/libedit-3.1.20181209-hb402a30_0.tar.bz2 -https://conda.anaconda.org/conda-forge/osx-64/libgfortran-4.0.0-2.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/readline-7.0-h1de35cc_5.tar.bz2 -https://conda.anaconda.org/conda-forge/osx-64/libopenblas-0.3.7-h4bb4525_1.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/sqlite-3.29.0-ha441bb4_0.tar.bz2 -https://conda.anaconda.org/conda-forge/osx-64/libblas-3.8.0-12_openblas.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/python-3.7.4-h359304d_1.tar.bz2 -https://conda.anaconda.org/conda-forge/osx-64/certifi-2019.9.11-py37_0.tar.bz2 -https://conda.anaconda.org/conda-forge/osx-64/libcblas-3.8.0-12_openblas.tar.bz2 -https://conda.anaconda.org/conda-forge/osx-64/liblapack-3.8.0-12_openblas.tar.bz2 -https://conda.anaconda.org/simpleitk/label/dev/osx-64/simpleitk-1.2rc1-py37h0a44026_0.tar.bz2 -https://conda.anaconda.org/conda-forge/osx-64/numpy-1.17.2-py37h6b0580a_0.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/setuptools-41.0.1-py37_0.tar.bz2 -https://conda.anaconda.org/conda-forge/osx-64/itk-5.0.1-py37_0.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/wheel-0.33.4-py37_0.tar.bz2 -https://repo.anaconda.com/pkgs/main/osx-64/pip-19.2.2-py37_0.tar.bz2 +# Create the environment with: +# conda create --name --file --override-channels \ +# --channel conda-forge --platform osx-64 +# Then run this in the activated environment: +# python -m pip install itk SimpleITK +python=3.12 +pip diff --git a/pyproject.toml b/pyproject.toml index 51ade0b..6bba9ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,9 +10,10 @@ authors = [ description = "A script to automatically spell checks comments of a codebase." readme = "README.md" license = {file = "LICENSE"} -requires-python = ">=3.8" +requires-python = ">=3.12" classifiers = [ "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.12", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", ] diff --git a/requirements.txt b/requirements.txt index c10f7a2..b59dd38 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ comment_parser pyspellchecker -bibtexparser +bibtexparser>=2.0,<3 requests diff --git a/tests/test_comment_spell_check.py b/tests/test_comment_spell_check.py index ae6121f..7bab1fd 100644 --- a/tests/test_comment_spell_check.py +++ b/tests/test_comment_spell_check.py @@ -20,6 +20,11 @@ import unittest import subprocess +from pathlib import Path + +from spellchecker import SpellChecker + +from comment_spell_check.utils.bibtex_loader import add_bibtex class TestCommentSpellCheck(unittest.TestCase): @@ -105,6 +110,15 @@ def test_bibtex(self): ) self.assertEqual(runresult.returncode, 0, runresult.stdout) + def test_bibtex_citation_keys_added_to_dictionary(self): + spell = SpellChecker() + citation_words = {"lowekamp", "yaniv", "simpleitk", "yushkevich"} + self.assertEqual(spell.unknown(citation_words), citation_words) + bibtex_file = Path(__file__).with_name("itk.bib") + add_bibtex(spell, str(bibtex_file)) + + self.assertEqual(spell.unknown(citation_words), set()) + def test_url(self): """URL test""" url = (