Skip to content
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

Check errors don't exist as valid words in the aspell dictionary #1142

Merged
merged 53 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
33fd11a
Check errors don't exist as valid words in the aspell dictionary
peternewman May 29, 2019
3c7c2f0
Install aspell on Travis
peternewman May 29, 2019
16611d5
Add some missing packages
peternewman May 29, 2019
1d20546
Remove a virtual package
peternewman May 29, 2019
2317fc7
Just install the version of aspell-python we need
peternewman May 29, 2019
f3a3dc8
Keep flake8 happy
peternewman May 29, 2019
61f2611
Switch to warnings and count them, so we can see all the aspell error…
peternewman May 29, 2019
24fa1c0
Handle different encoding of the word and aspell
peternewman May 29, 2019
540e7be
Try and fix the encoding conversion
peternewman May 29, 2019
640931d
Find out the encoding type
peternewman May 29, 2019
752cd32
Don't assert on number of warnings
peternewman May 29, 2019
649ef77
Don't record warnings for now
peternewman May 29, 2019
4964b55
Warn on all the encoding options
peternewman May 29, 2019
ce36d7d
pprint the encoding
peternewman May 29, 2019
9460271
More warning work
peternewman May 30, 2019
6a1c2db
Use the actual encoding type
peternewman May 30, 2019
7949042
Correct the logic
peternewman May 30, 2019
1e5aaf4
Merge pull request #1201 from codespell-project/master
peternewman Jul 23, 2019
374bd5e
ENH: Multi dict support
larsoner Apr 3, 2020
42a25d6
Merge remote-tracking branch 'upstream/master' into peternewman-aspel…
larsoner Apr 3, 2020
f9ad400
FIX: Fixes after merge
larsoner Apr 4, 2020
4028e9b
FIX: Better error check
larsoner Apr 4, 2020
37de969
FIX: More thorough testing, locations
larsoner Apr 4, 2020
66cc8a5
FIX: Try newer aspell
larsoner Apr 4, 2020
1e339e1
Merge remote-tracking branch 'upstream/master' into peternewman-aspel…
larsoner Apr 5, 2020
cd2f804
FIX: Move to new dict
larsoner Apr 5, 2020
77beee5
Merge remote-tracking branch 'upstream/master' into peternewman-aspel…
larsoner Apr 5, 2020
11ed549
Merge remote-tracking branch 'upstream/master' into peternewman-aspel…
larsoner Apr 5, 2020
4ededb2
FIX: Move
larsoner Apr 5, 2020
0862327
FIX: Restore removals from #1181
larsoner Apr 5, 2020
2872b6b
FIX: One from #1362
larsoner Apr 5, 2020
1a09d03
Add rare chack->check, cheque,
peternewman Apr 5, 2020
dd4fa4d
Minor tidy of some dictionary check code
peternewman Apr 5, 2020
a84a3cc
Add some more suggestions.
peternewman Apr 5, 2020
045ef64
Fix the whitespace
peternewman Apr 5, 2020
010943a
Really fix the whitespace
peternewman Apr 5, 2020
1ecea00
FIX: Refactor requirement
larsoner Apr 5, 2020
257f641
Log an error when aspell not found and not required
peternewman Apr 6, 2020
3dc7da9
Fix the error logging
peternewman Apr 6, 2020
ce393dc
Test all variants of present and missing from aspell
peternewman Apr 6, 2020
9978312
Undo some tuple tidying
peternewman Apr 6, 2020
da71b63
Fix the true/false values used
peternewman Apr 6, 2020
13f462f
Skip some flake8 tests
peternewman Apr 6, 2020
967f401
Fix the test cases
peternewman Apr 6, 2020
e434b81
Correct the not in aspell test and fix some test cases
peternewman Apr 6, 2020
06b0251
Remove a duplicate test
peternewman Apr 6, 2020
6b21c8c
Use a test word that isn't a typo
peternewman Apr 6, 2020
437efea
Set the ideal aspell detection logic for each dictionary
peternewman Apr 6, 2020
6de3cb1
Be more realistic given the size of the dictionary
peternewman Apr 6, 2020
f7d0a64
Fix a flake8 error
peternewman Apr 6, 2020
f5ece88
Fix another line length error
peternewman Apr 6, 2020
ea4be8e
FIX: Move
larsoner Apr 6, 2020
a4a69f5
FIX: Make visible, simplify
larsoner Apr 6, 2020
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
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# for it to be on multiple physical lines, so long as you remember: - There
# can't be any leading "-"s - All newlines will be removed, so use ";"s

dist: bionic
language: python
cache: pip
python:
Expand All @@ -12,6 +13,14 @@ python:
- 3.6
- 3.7
- 3.8
env:
REQUIRE_ASPELL=true

addons:
apt:
packages:
- libaspell-dev
- aspell-en

before_install:
- source tools/travis_tools.sh
Expand All @@ -22,6 +31,8 @@ before_install:
- python --version # just to check
- pip install -U pip wheel # upgrade to latest pip find 3.5 wheels; wheel to avoid errors
- retry pip install pytest pytest-cov flake8 coverage codecov chardet setuptools docutils
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then retry pip install aspell-python-py2; fi
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "3" ]; then retry pip install aspell-python-py3; fi
- cd $SRC_DIR

install:
Expand Down
64 changes: 52 additions & 12 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@

# Users might want to link this file into /usr/local/bin, so we resolve the
# symbolic link path to the real path if necessary.
default_dictionary = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'data', 'dictionary.txt')
_data_root = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data')
_builtin_dictionaries = ( # name, desc, name, err in aspell, correction in aspell # noqa: E501
# The aspell tests here aren't the ideal state, but the None's are realistic
# for obscure words
('clear', 'for unambiguous errors', '', False, None),
('rare', 'for rare but valid words', '_rare', None, None),
('informal', 'for informal words', '_informal', True, True),
('code', 'for words common to code and/or mathematics', '_code', None, None), # noqa: E501
('names', 'for valid proper names that might be typos', '_names', None, None), # noqa: E501
('en-GB_to_en-US', 'for corrections from en-GB to en-US', '_en-GB_to_en-US', True, True), # noqa: E501
)
_builtin_default = 'clear,rare'

# OPTIONS:
#
Expand Down Expand Up @@ -216,11 +226,21 @@ def parse_options(args):
help='write changes in place if possible')

parser.add_argument('-D', '--dictionary',
action='append', metavar='FILE',
action='append',
help='Custom dictionary file that contains spelling '
'corrections. If this flag is not specified or '
'equals "-" then the default dictionary is used. '
'This option can be specified multiple times.')
builtin_opts = ', '.join(
'%r %s' % (d[0], d[1]) for d in _builtin_dictionaries)
parser.add_argument('--builtin',
dest='builtin', default=_builtin_default,
metavar='BUILTIN-LIST',
help='Comma-separated list of builtin dictionaries '
'to include (when "-D -" or no "-D" is passed). '
'Current options are:\n%s. The default is '
'"--builtin %s".'
% (builtin_opts, _builtin_default))
parser.add_argument('-I', '--ignore-words',
action='append', metavar='FILE',
help='File that contains words which will be ignored '
Expand Down Expand Up @@ -603,7 +623,7 @@ def main(*args):
ignore_words_files = options.ignore_words or []
ignore_words = set()
for ignore_words_file in ignore_words_files:
if not os.path.exists(ignore_words_file):
if not os.path.isfile(ignore_words_file):
print('ERROR: cannot find ignore-words file: %s' %
ignore_words_file, file=sys.stderr)
parser.print_help()
Expand All @@ -615,16 +635,36 @@ def main(*args):
for word in comma_separated_words.split(','):
ignore_words.add(word.strip())

dictionaries = options.dictionary or [default_dictionary]
misspellings = dict()
if options.dictionary:
dictionaries = options.dictionary
else:
dictionaries = ['-']
use_dictionaries = list()
for dictionary in dictionaries:
if dictionary == "-":
dictionary = default_dictionary
if not os.path.exists(dictionary):
print('ERROR: cannot find dictionary file: %s' % dictionary,
file=sys.stderr)
parser.print_help()
return 1
# figure out which builtin dictionaries to use
peternewman marked this conversation as resolved.
Show resolved Hide resolved
use = sorted(set(options.builtin.split(',')))
for u in use:
for builtin in _builtin_dictionaries:
if builtin[0] == u:
use_dictionaries.append(
os.path.join(_data_root, 'dictionary%s.txt'
% (builtin[2],)))
break
else:
print('ERROR: Unknown builtin dictionary: %s' % (u,),
file=sys.stderr)
parser.print_help()
return 1
else:
if not os.path.isfile(dictionary):
peternewman marked this conversation as resolved.
Show resolved Hide resolved
print('ERROR: cannot find dictionary file: %s' % dictionary,
file=sys.stderr)
parser.print_help()
return 1
use_dictionaries.append(dictionary)
misspellings = dict()
for dictionary in use_dictionaries:
build_dict(dictionary, misspellings, ignore_words)
colors = TermColors()
if not options.colors or sys.platform == 'win32':
Expand Down
Loading