diff --git a/.travis.yml b/.travis.yml index 76e701599..a32bd2c92 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: python python: - "2.7" + - "3.3" + - "3.4" install: - pip install -r requirements.txt - - pip install LinkChecker - gem install jekyll-gist -v '1.2.1' - gem install jekyll - gem install jekyll-sitemap @@ -11,6 +12,7 @@ install: - gem install compass --version 0.12.5 - gem install kramdown - gem install travis + - gem install link-checker before_script: - travis lint -x --skip-completion-check - python scripts/insert_demo.py @@ -20,9 +22,9 @@ script: - jekyll build - s3_website push - cd .. - - linkchecker 'http://prose.lifelinter.com' - pep8 . - pep257 . --match='.*\.py' + - check-links "http://prose.lifelinter.com" after_success: - coveralls env: diff --git a/futurizing_output.txt b/futurizing_output.txt new file mode 100644 index 000000000..b9965240f --- /dev/null +++ b/futurizing_output.txt @@ -0,0 +1,31 @@ +--- ./proselint/command_line.py (original) ++++ ./proselint/command_line.py (refactored) +@@ -59,7 +59,7 @@ + # Extract the checks. + sys.path.append(proselint_path) + checks = [] +- check_names = [key for (key, val) in options["checks"].items() if val] ++ check_names = [key for (key, val) in list(options["checks"].items()) if val] + for check_name in check_names: + module = importlib.import_module("checks." + check_name) + for d in dir(module): +@@ -140,7 +140,7 @@ + input_val = None + while not isinstance(input_val, int): + try: +- input_val = input("# of false alarms? ") ++ input_val = eval(input("# of false alarms? ")) + if input_val == "exit": + return + else: +--- ./proselint/tools.py (original) ++++ ./proselint/tools.py (refactored) +@@ -44,7 +44,7 @@ + + tempargdict = inspect.getcallargs(f, *args, **kwargs) + +- for item in tempargdict.items(): ++ for item in list(tempargdict.items()): + signature += item[1].encode('utf-8') + + key = hashlib.sha256(signature).hexdigest() diff --git a/proselint/command_line.py b/proselint/command_line.py index 41f5cc816..0c59483bf 100644 --- a/proselint/command_line.py +++ b/proselint/command_line.py @@ -2,11 +2,17 @@ # -*- coding: utf-8 -*- """Command line utility for proselint.""" +from __future__ import print_function +from __future__ import absolute_import +from builtins import input +from builtins import str +from builtins import int + import click import os -from tools import line_and_column, is_quoted -import checks as pl +from .tools import line_and_column, is_quoted +from . import checks as pl import pkgutil import codecs import subprocess @@ -53,7 +59,7 @@ def lint(path, debug=False): # Extract the checks. sys.path.append(proselint_path) checks = [] - check_names = [key for key, val in options["checks"].items() if val] + check_names = [key for (key, val) in options["checks"].items() if val] for check_name in check_names: module = importlib.import_module("checks." + check_name) for d in dir(module): @@ -131,16 +137,16 @@ def lintscore(): subprocess.call("{} {}".format("open", fullpath), shell=True) # Ask the scorer how many of the errors were false alarms? - input = None - while not isinstance(input, (int, long)): + input_val = None + while not isinstance(input_val, int): try: - input = raw_input("# of false alarms? ") - if input == "exit": + input_val = input("# of false alarms? ") + if input_val == "exit": return else: - input = int(input) - fp += input - tp += (num_errors - input) + input_val = int(input_val) + fp += input_val + tp += (num_errors - input_val) except: pass diff --git a/proselint/tools.py b/proselint/tools.py index b8d8729f4..d9d04297b 100644 --- a/proselint/tools.py +++ b/proselint/tools.py @@ -2,6 +2,8 @@ # -*- coding: utf-8 -*- """General-purpose tools shared across linting checks.""" +from __future__ import print_function +from __future__ import unicode_literals import os import shelve import inspect @@ -37,12 +39,12 @@ def wrapped(*args, **kwargs): if hasattr(f, '__self__'): args = args[1:] - signature = f.__module__ + '.' + f.__name__ + signature = (f.__module__ + '.' + f.__name__).encode("utf-8") tempargdict = inspect.getcallargs(f, *args, **kwargs) for item in tempargdict.items(): - signature += item[1].encode('utf-8') + signature += item[1].encode("utf-8") key = hashlib.sha256(signature).hexdigest() @@ -126,16 +128,17 @@ def preferred_forms_check(text, list, err, msg, ignore_case=True, offset=0): return errors -def existence_check(text, list, err, msg, ignore_case=True, unicode=False, - max_errors=float("inf"), offset=0, require_padding=True, - dotall=False, excluded_topics=None, join=False): +def existence_check(text, list, err, msg, ignore_case=True, + str=False, max_errors=float("inf"), offset=0, + require_padding=True, dotall=False, + excluded_topics=None, join=False): """Build a checker that blacklists certain words.""" flags = 0 if ignore_case: flags = flags | re.IGNORECASE - if unicode: + if str: flags = flags | re.UNICODE if dotall: @@ -182,8 +185,8 @@ def existence_check(text, list, err, msg, ignore_case=True, unicode=False, def is_quoted(position, text): """Determine if the position in the text falls within a quote.""" def matching(quotemark1, quotemark2): - straight = u'\"\'' - curly = u'“”' + straight = '\"\'' + curly = '“”' if quotemark1 in straight and quotemark2 in straight: return True if quotemark1 in curly and quotemark2 in curly: @@ -197,7 +200,7 @@ def find_ranges(text): start = None ranges = [] seps = " .,:;-\r\n" - quotes = [u'\"', u'“', u'”', u"'"] + quotes = ['\"', '“', '”', "'"] for i, c in enumerate(text + "\n"): if s == 0 and c in quotes and pc in seps: start = i diff --git a/requirements.txt b/requirements.txt index eb1c4bc9a..2691a5d81 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,7 @@ Flask-API==0.6.2 Flask-Cors==2.0.0 Flask-Limiter==0.8 Flask==0.10.1 +future gunicorn==19.3.0 itsdangerous==0.24 Jinja2==2.7.3 diff --git a/scripts/generate_posts.py b/scripts/generate_posts.py index 4e1d879e0..fd8468981 100755 --- a/scripts/generate_posts.py +++ b/scripts/generate_posts.py @@ -1,5 +1,7 @@ """Generate blog posts from check docstrings.""" +from builtins import str +from builtins import range import os import ast import datetime @@ -37,7 +39,7 @@ def is_check(fn): str(datetime.date.today()) + "-" + docstring[0:6] + ".md") # Chop off the first two lines - for i in xrange(2): + for i in range(2): docstring = '\n'.join(docstring.split('\n')[1:]) # Create a new post in the blog. diff --git a/scripts/insert_demo.py b/scripts/insert_demo.py index af42ceb58..b50f5377e 100755 --- a/scripts/insert_demo.py +++ b/scripts/insert_demo.py @@ -1,4 +1,5 @@ """Insert the demo into the codemirror site.""" +from __future__ import print_function import os import fileinput @@ -26,6 +27,6 @@ os.path.join(live_write_path, "index.html"), inplace=True): if "##DEMO_PLACEHOLDER##" in line: - print demo, + print(demo, end=' ') else: - print line, + print(line, end=' ') diff --git a/tests/_test_mau_a_vs_an.py b/tests/_test_mau_a_vs_an.py index 957708209..6460d39ac 100644 --- a/tests/_test_mau_a_vs_an.py +++ b/tests/_test_mau_a_vs_an.py @@ -1,6 +1,7 @@ """Unit tests for MAU101.""" +from __future__ import absolute_import -from check import Check +from .check import Check from proselint.checks.garner import a_vs_an as chk diff --git a/tests/check.py b/tests/check.py index 93eca9b6b..b77167560 100644 --- a/tests/check.py +++ b/tests/check.py @@ -1,5 +1,6 @@ """Check that a check is working.""" +from past.builtins import basestring from unittest import TestCase import os import codecs diff --git a/tests/test_dfw_uncomparables.py b/tests/test_dfw_uncomparables.py index 56c4c6670..9446bc3b4 100644 --- a/tests/test_dfw_uncomparables.py +++ b/tests/test_dfw_uncomparables.py @@ -1,6 +1,7 @@ """Test dfw.uncomparables.""" +from __future__ import absolute_import -from check import Check +from .check import Check from proselint.checks.wallace import uncomparables as chk diff --git a/tests/test_garner_dates.py b/tests/test_garner_dates.py index 5539bd383..e9ee913ee 100644 --- a/tests/test_garner_dates.py +++ b/tests/test_garner_dates.py @@ -1,6 +1,7 @@ """Test garner.dates.""" +from __future__ import absolute_import -from check import Check +from .check import Check from proselint.checks.garner import dates diff --git a/tests/test_strunk_white_eos.py b/tests/test_strunk_white_eos.py index 98a56a539..54e089fae 100644 --- a/tests/test_strunk_white_eos.py +++ b/tests/test_strunk_white_eos.py @@ -1,6 +1,8 @@ """Unit tests for strunk_white_eos.""" +# from __future__ import absolute_import -# from check import Check + +# from .check import Check # from proselint.checks.strunkwhite import elementary_composition as chk