...
 
Commits (2)
......@@ -4,5 +4,6 @@ dist
ld
codespell.egg-info
*.pyc
*.orig
.cache/
.pytest_cache/
- id: codespell
name: codespell
description: Checks for common misspellings in text files.
entry: codespell
language: python
types: [text]
args: []
require_serial: false
additional_dependencies: []
......@@ -6,7 +6,7 @@
language: python
sudo: false
dist: trusty
dist: xenial
cache:
directories:
......@@ -16,20 +16,12 @@ matrix:
include:
- os: linux
python: 2.7
- os: linux
python: 3.3
- os: linux
python: 3.4
- os: linux
python: 3.5
- os: linux
python: 3.6
# OSX commented out for now because it's slow and a bit buggy as of
# 2017/11/15
# - os: osx
# python: 2.7
# - os: osx
# python: 3.6
- os: linux
python: 3.7
before_install:
- source tools/travis_tools.sh
......@@ -39,7 +31,7 @@ before_install:
- source venv/bin/activate
- 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 pytest-sugar flake8 coverage codecov chardet setuptools
- retry pip install pytest pytest-cov flake8 coverage codecov chardet setuptools
- cd $SRC_DIR
install:
......@@ -48,6 +40,7 @@ install:
script:
- codespell --help
- make check-dictionary
- codespell --skip="codespell_lib/tests/test_basic.py,codespell_lib/data/*" codespell_lib/
# this file has an error
- "! codespell codespell_lib/tests/test_basic.py"
- flake8
......
SORT_ARGS := -f
SORT_ARGS := -f -b
PHONY := all check check-dictionary sort-dictionary clean
DICTIONARY := codespell_lib/data/dictionary.txt
PHONY := all check check-dictionary sort-dictionary trim-dictionary clean
all: check-dictionary codespell.1
......@@ -9,13 +11,20 @@ codespell.1: codespell.1.include bin/codespell
sed -i '/\.SS \"Usage/,+2d' codespell.1
check-dictionary:
@if ! LC_ALL=C sort ${SORT_ARGS} -c codespell_lib/data/dictionary.txt; then \
@if ! LC_ALL=C sort ${SORT_ARGS} -c ${DICTIONARY}; then \
echo "Dictionary not sorted. Sort with 'make sort-dictionary'"; \
exit 1; \
fi
@if egrep -n "^\s*$$|\s$$|^\s" ${DICTIONARY}; then \
echo "Dictionary contains leading/trailing whitespace and/or blank lines. Trim with 'make trim-dictionary'"; \
exit 1; \
fi
sort-dictionary:
LC_ALL=C sort ${SORT_ARGS} -u -o codespell_lib/data/dictionary.txt codespell_lib/data/dictionary.txt
LC_ALL=C sort ${SORT_ARGS} -u -o ${DICTIONARY} ${DICTIONARY}
trim-dictionary:
sed -E -i.bak -e 's/^[[:space:]]+//; s/[[:space:]]+$$//; /^$$/d' ${DICTIONARY} && rm ${DICTIONARY}.bak
pypi:
python setup.py sdist register upload
......
......@@ -31,31 +31,37 @@ You can use ``pip`` to install codespell with e.g.::
Usage
-----
For more in depth info please check usage with ``codespell -h``.
For more in depth info please check usage with ``codespell -h``.
Some noteworthy flags::
codespell -w, --write-changes
The -w flag will actually implement the changes recommended by codespell. Not running with ``-w`` flag is the same as with doing a dry run. It is recommended to run this with the ``-i`` or ``--interactive`` flag.::
The -w flag will actually implement the changes recommended by codespell. Not running with ``-w`` flag is the same as with doing a dry run. It is recommended to run this with the ``-i`` or ``--interactive`` flag.::
codespell -I FILE, --ignore-words=FILE
The -I flag can be used to whitelist certain words that are in the ``codespell_lib/data/dictionary.txt``. The format of the whitelist file is one word per line. Invoke using: ``codespell -I path/to/file.txt`` to execute codespell referencing said whitelist. **Important note:** The whitelist passed to ``-I`` is case-sensitive based on how it is listed in ``dictionary.txt``. ::
codespell -L word1,word2,word3,word4
The -L flag can be used to whitelist certain words that are comma-separated placed immediately after it. ::
codespell -S, --skip=
Comma-separated list of files to skip. It accepts globs as well. Examples:
* to skip .eps & .txt files, invoke ``codespell --skip="*.eps,*.txt"``
* to skip directories, invoke ``codespell --skip="./src/3rd-Party,./src/Test"`` ::
* to skip .eps & .txt files, invoke ``codespell --skip="*.eps,*.txt"``
codespell -I FILE, --ignore-words=FILE
* to skip directories, invoke ``codespell --skip="./src/3rd-Party,./src/Test"`` ::
This flag can be used to whitelist certain words that are in the ``codespell_lib/data/dictionary.txt``. The format of the whitelist file is one word per line. Invoke using: ``codespell -I path/to/file.txt`` to execute codespell referencing said whitelist. **Important note:** The whitelist passed to ``-I`` is case-sensitive based on how it is listed in ``dictionary.txt``.
Useful commands::
codespell -d -q 3 --skip="*.po,*.ts,./src/3rdParty,./src/Test"
List all typos found except translation files and some directories. Display them without terminal colors and with a quiet level of 3. ::
| List all typos found except translation files and some directories.
Display them without terminal colors and with a quiet level of 3. ::
codespell -i 3 -w
......@@ -67,9 +73,7 @@ after applying them in projects like Linux Kernel, EFL, oFono among others.
You can provide your own version of the dictionary, but patches for
new/different entries are very welcome.
Does a word you're proposing exist in codespell already? ::
It is possible to test a word against the current dictionary that exists in ``codespell_lib/data/dictionary.txt`` very rapidly via::
Want to know if a word you're proposing exists in codespell already? It is possible to test a word against the current dictionary that exists in ``codespell_lib/data/dictionary.txt`` via::
echo "word" | codespell -
echo "1stword,2ndword" | codespell -
......@@ -130,7 +134,7 @@ Updating
To stay current with codespell developments it is possible to build codespell from GitHub via::
pip install --upgrade git+https://github.com/codespell-project/codespell.github
pip install --upgrade git+https://github.com/codespell-project/codespell.git
**Important Notes:**
......@@ -138,9 +142,19 @@ To stay current with codespell developments it is possible to build codespell fr
pip install --user --upgrade git+https://github.com/codespell-project/codespell.git
* It has been reported that after installing from ``pip``, codespell can't be located. Please check the $PATH variable to see if ``~/.local/bin`` is present. If it isn't then add it to your path.
* If you decide to install via ``pip`` then be sure to remove any previously installed versions of codespell (via you OSs preferred app mananger).
* It has been reported that after installing from ``pip``, codespell can't be located. Please check the $PATH variable to see if ``~/.local/bin`` is present. If it isn't then add it to your path.
* If you decide to install via ``pip`` then be sure to remove any previously installed versions of codespell (via you OSs preferred app mananger).
Updating the dictionary
-----------------------
In the scenario where the user prefers not to follow the development version of codespell yet still opts to benefit from the frequently updated `dictionary.txt` file, we recommend running a simple set of commands to achieve this ::
wget https://raw.githubusercontent.com/codespell-project/codespell/master/codespell_lib/data/dictionary.txt
codespell -D dictionary.txt
The above simply downloads the latest ``dictionary.txt`` file and then by utilizing the -D flag allows the user to specify the freshly downloaded ``dictionary.txt`` as the custom dictionary instead of the default one.
License
-------
......
clone_depth: 50
environment:
global:
PYTHON: "C:\\conda"
CONDA_DEPENDENCIES: "pytest pytest-cov setuptools flake8 coverage chardet"
PIP_DEPENDENCIES: "codecov pytest-sugar"
matrix:
- PYTHON_VERSION: "2.7"
PYTHON_ARCH: "32"
- PYTHON_VERSION: "3.6"
PYTHON_ARCH: "64"
- PYTHON: C:\Python37-x64
PYTHON_VERSION: 3.7
PYTHON_ARCH: 64
- PYTHON: C:\Python27
PYTHON_VERSION: 2.7
PYTHON_ARCH: 32
cache:
# Cache downloaded pip packages and built wheels.
- '%LOCALAPPDATA%\pip\Cache\http'
- '%LOCALAPPDATA%\pip\Cache\wheels'
install:
- "git clone git://github.com/astropy/ci-helpers.git"
- "powershell ci-helpers/appveyor/install-miniconda.ps1"
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
- "activate test"
- "pip install pytest pytest-cov setuptools flake8 coverage chardet codecov"
- "python setup.py develop"
build: false # Not a C# project, build stuff at the test step instead.
......@@ -25,3 +28,10 @@ test_script:
on_success:
- "codecov"
# Remove old or huge cache files to hopefully not exceed the 1GB cache limit.
# (adapted from PyInstaller)
- C:\cygwin\bin\find "%LOCALAPPDATA%\pip" -type f -mtime +360 -delete
- C:\cygwin\bin\find "%LOCALAPPDATA%\pip" -type f -size +10M -delete
- C:\cygwin\bin\find "%LOCALAPPDATA%\pip" -empty -delete
# Show size of cache
- C:\cygwin\bin\du -hs "%LOCALAPPDATA%\pip\Cache"
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
# -*- coding: utf-8 -*-
import os.path as op
import re
def test_dictionary_formatting():
"""Test that all dictionary entries are valid."""
err_dict = dict()
ws = re.compile(r'.*\s.*') # whitespace
comma = re.compile(r'.*,.*') # comma
with open(op.join(op.dirname(__file__), '..', 'data',
'dictionary.txt'), 'rb') as fid:
for line in fid:
err, rep = line.decode('utf-8').split('->')
err = err.lower()
assert err not in err_dict, 'error %r already exists' % err
assert ws.match(err) is None, 'error %r has whitespace' % err
assert comma.match(err) is None, 'error %r has a comma' % err
rep = rep.rstrip('\n')
assert len(rep) > 0, ('error %s: correction %r must be non-empty'
% (err, rep))
assert not re.match(r'^\s.*', rep), ('error %s: correction %r '
'cannot start with whitespace'
% (err, rep))
for (r, msg) in [
(r'^,', 'error %s: correction %r starts with a comma'),
(r'\s,', 'error %s: correction %r contains a whitespace '
'character followed by a comma'),
(r',\s\s', 'error %s: correction %r contains a comma followed '
'by multiple whitespace characters'),
(r',[^ ]', 'error %s: correction %r contains a comma *not* '
'followed by a space')
]:
assert not re.search(r, rep), (msg % (err, rep))
if rep.count(','):
if not rep.endswith(','):
assert 'disabled' in rep.split(',')[-1], \
('currently corrections must end with trailing "," (if'
' multiple corrections are available) or '
'have "disabled" in the comment')
reps = [r.strip() for r in rep.lower().split(',')]
reps = [r for r in reps if len(r)]
err_dict[err] = reps
unique = list()
for r in reps:
if r not in unique:
unique.append(r)
assert reps == unique, 'entries are not (lower-case) unique'
# check for corrections that are errors (but not self replacements)
for err in err_dict:
for r in err_dict[err]:
assert (r not in err_dict) or (r in err_dict[r]), \
('error %s: correction %s is an error itself' % (err, r))