Skip to content

Commit

Permalink
More pylint placating.
Browse files Browse the repository at this point in the history
Removed nearly all pylint complaints.  Updated readme with info about
using tox.
  • Loading branch information
lyda committed Jun 10, 2012
1 parent de5bd1a commit 54a7e85
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .pylintrc
Expand Up @@ -28,7 +28,7 @@ argument-rgx=[a-z_][a-z0-9_]{2,30}$
# Note: s/2/1/ to allow two char var names.
variable-rgx=[a-z_][a-z0-9_]{1,30}$
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
good-names=i,j,k,ex,f,fn,a,b,Run,_
good-names=i,j,k,ex,f,fn,Run,_,ms
bad-names=foo,bar,baz,toto,tutu,tata
no-docstring-rgx=__.*__

Expand All @@ -53,7 +53,7 @@ generated-members=REQUEST,acl_users,aq_parent

[VARIABLES]
init-import=no
dummy-variables-rgx=_|dummy
dummy-variables-rgx=_|dummy|unused
additional-builtins=

[CLASSES]
Expand Down
5 changes: 4 additions & 1 deletion README.rst
Expand Up @@ -36,8 +36,10 @@ Contributions
=============
Contributions are welcome! Please add unit tests for new features
or bug fixes. To run all the unit tests run ``./setup.py test``.
If you have `tox`_ installed, just run ``tox``.

Unit tests are run on `Travis`_ for all supported python versions.
Note that tests are run on `Travis`_ for all supported python
versions whenever the tree on github is pushed to.

TODO
====
Expand All @@ -59,6 +61,7 @@ Credits
- `Maciej Blizinski`_: Potential use in opencsw pushed move to python.
- `Ville Skyttä`_: Sped up wordification, editor-friendly reporting.

.. _`tox`: http://pypi.python.org/pypi/tox
.. _`Travis`: http://travis-ci.org/#!/lyda/misspell-check
.. _`Kevin Lyda`: https://github.com/lyda
.. _`myint`: https://github.com/myint
Expand Down
19 changes: 10 additions & 9 deletions misspellings
@@ -1,4 +1,5 @@
#!/usr/bin/python
"""Check files against a list of commonly misspelled words."""

# For Python 2.5
from __future__ import with_statement
Expand All @@ -15,11 +16,13 @@ class Suggestions(object):
self.last_suggestions = {}

def _get_a_line(self, filename, lineno):
"""Read a specific line from a file."""
# Perhaps caching this would be nice, but assuming not an insane
# number of misspellings.
return open(filename, 'r').readlines()[lineno - 1].rstrip()

def get_suggestion(self, filename, lineno, word, suggestions):
"""Show line from file, a misspelled word and request replacement."""
if word not in self.last_suggestions:
self.last_suggestions[word] = suggestions[0]
line = self._get_a_line(filename, lineno)
Expand All @@ -35,6 +38,7 @@ class Suggestions(object):


def print_file_context(fn, target_line_num, context=5):
"""Show a line from a file in context."""
line_num = 1
start_line = target_line_num - context
end_line = target_line_num + context
Expand All @@ -48,14 +52,8 @@ def print_file_context(fn, target_line_num, context=5):
line_num += 1


def cmp_rev_line(a, b):
file_cmp = cmp(a[0], b[0])
if file_cmp == 0:
return cmp(b[1], a[1])
return file_cmp


def parse_file_list(filename):
"""Show a line from a file in context."""
f = sys.stdin
try:
if filename != '-':
Expand All @@ -69,11 +67,13 @@ def parse_file_list(filename):


def esc_sed(raw_text):
"""Escape chars for a sed command on a shell command line."""
return raw_text.replace('"', '\\"').replace('/', '\\/')


def esc_file(raw_text):
return raw_text.replace('"', '\\"')
"""Escape chars for a file name on a shell command line."""
return raw_text.replace('\'', '\'"\'"\'')


# Output routines.
Expand Down Expand Up @@ -114,6 +114,7 @@ def output_sed_script(ms, parser, opts):


def main():
"""main function."""
parser = optparse.OptionParser(
usage='Usage: misspellings [-f file_list] [files]',
description='Checks files for common spelling mistakes.',
Expand Down Expand Up @@ -150,7 +151,7 @@ def main():
ms = misspellings.Misspellings(files=files,
misspelling_file=opts.ms_file)
if opts.dump_ms:
for word, correction in ms.dumpMisspellingList():
for word, correction in ms.dump_misspelling_list():
print('%s %s' % (word, correction))
if not opts.interactive:
if not opts.script_output:
Expand Down
10 changes: 8 additions & 2 deletions misspellings_lib.py
@@ -1,7 +1,12 @@
"""Misspellings module.
Take a list of files, check them against a list of misspelled words.
"""

# For Python 2.5
from __future__ import with_statement

from collections import defaultdict

import os
import re
import sys
Expand Down Expand Up @@ -99,7 +104,8 @@ def suggestions(self, word):
set(self._misspelling_dict.get(word.lower(), [])))
return [self._same_case(source=word, destination=w) for w in suggestions]

def dumpMisspellingList(self):
def dump_misspelling_list(self):
"""Returns a list of misspelled words and corrections."""
results = []
for bad_word in sorted(self._misspelling_dict.keys()):
for correction in self._misspelling_dict[bad_word]:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_class.py
Expand Up @@ -37,15 +37,15 @@ def testGoodMSList(self):
with open(misspelling_file) as msf:
for unused_line in msf:

This comment has been minimized.

Copy link
@myint

myint Jun 10, 2012

Contributor

Typically in Python, the idiom is to use a single underscore as variable name to indicate that it isn't be used.

This comment has been minimized.

Copy link
@myint

myint Jun 10, 2012

Contributor

Though, considering the ".pylintrc" file, you might already know this.

This comment has been minimized.

Copy link
@lyda

lyda Jun 10, 2012

Author Owner

I didn't. However work's style guide calls for unused_ as a prefix so I just tend to use that. The pylintrc by default had dummy and _ as prefixes. The dummy one seemed obvious, but I wasn't sure how common the _ prefix was. To be honest I like that better. The unused_ and dummy prefixes seem too wordy.

lines += 1
self.assertEqual(len(ms.dumpMisspellingList()), lines)
self.assertEqual(len(ms.dump_misspelling_list()), lines)

def testExampleSameAsDefault(self):
dms = misspellings.Misspellings()
ems = misspellings.Misspellings(
misspelling_file=os.path.join(BASE_PATH, 'example_msl.txt'))
# wc -l example_msl.txt
default_msl = dms.dumpMisspellingList()
example_msl = ems.dumpMisspellingList()
default_msl = dms.dump_misspelling_list()
example_msl = ems.dump_misspelling_list()
for fn, msl in (('msl_ex', example_msl), ('msl_de', default_msl)):
f = open(os.path.join(LOG_PATH,
'testExampleSameAsDefault.%s.tmp' % fn), 'w')
Expand Down

0 comments on commit 54a7e85

Please sign in to comment.