From ecada8150592e3f117a582ec4be62389e51aa5a5 Mon Sep 17 00:00:00 2001 From: michaelpacer Date: Mon, 17 Aug 2015 17:38:10 -0700 Subject: [PATCH 01/11] ran stage1 of futurize --- proselint/command_line.py | 6 ++++-- proselint/tools.py | 1 + scripts/insert_demo.py | 5 +++-- tests/_test_mau_a_vs_an.py | 3 ++- tests/test_dfw_uncomparables.py | 3 ++- tests/test_garner_dates.py | 3 ++- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/proselint/command_line.py b/proselint/command_line.py index 41f5cc816..e218ef6e1 100644 --- a/proselint/command_line.py +++ b/proselint/command_line.py @@ -2,11 +2,13 @@ # -*- coding: utf-8 -*- """Command line utility for proselint.""" +from __future__ import print_function +from __future__ import absolute_import 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 diff --git a/proselint/tools.py b/proselint/tools.py index b8d8729f4..6e882ff66 100644 --- a/proselint/tools.py +++ b/proselint/tools.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- """General-purpose tools shared across linting checks.""" +from __future__ import print_function import os import shelve import inspect 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/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 From dcbae62c76edf313e83d79428609641c6181d94f Mon Sep 17 00:00:00 2001 From: michaelpacer Date: Mon, 17 Aug 2015 18:09:22 -0700 Subject: [PATCH 02/11] still more futurizing this time using stage2 --- proselint/command_line.py | 20 ++++++++++++-------- proselint/tools.py | 14 +++++++------- scripts/generate_posts.py | 4 +++- tests/check.py | 1 + 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/proselint/command_line.py b/proselint/command_line.py index e218ef6e1..0c59483bf 100644 --- a/proselint/command_line.py +++ b/proselint/command_line.py @@ -4,6 +4,10 @@ """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 @@ -55,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): @@ -133,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 6e882ff66..0cd9b8437 100644 --- a/proselint/tools.py +++ b/proselint/tools.py @@ -3,6 +3,8 @@ """General-purpose tools shared across linting checks.""" from __future__ import print_function +from __future__ import unicode_literals +from builtins import str import os import shelve import inspect @@ -127,16 +129,14 @@ 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: @@ -183,8 +183,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: @@ -198,7 +198,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/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/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 From 615ce85456f7ddef5479627c1fa8060c3111d802 Mon Sep 17 00:00:00 2001 From: michaelpacer Date: Mon, 17 Aug 2015 18:15:21 -0700 Subject: [PATCH 03/11] added futurizing todo can be recreated with futurize --stage2 ./**/*.py > futurizing.txt --- futurizing_output.txt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 futurizing_output.txt 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() From 5a73eb7fdccfd379118c88ea9e1d6fc5e037da4d Mon Sep 17 00:00:00 2001 From: michaelpacer Date: Mon, 17 Aug 2015 21:58:36 -0700 Subject: [PATCH 04/11] finalized python3 port --- proselint/tools.py | 4 ++-- requirements.txt | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/proselint/tools.py b/proselint/tools.py index 0cd9b8437..6480e7b94 100644 --- a/proselint/tools.py +++ b/proselint/tools.py @@ -40,12 +40,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() 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 From 00ad35b74a9bda2614acf0f392fedf17f4a5cbdb Mon Sep 17 00:00:00 2001 From: michaelpacer Date: Mon, 17 Aug 2015 22:02:51 -0700 Subject: [PATCH 05/11] updated travis to build on python2 and python3 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 76e701599..2498aa8c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: python python: - "2.7" + - "3.3" + - "3.4" install: - pip install -r requirements.txt - pip install LinkChecker From 570e89d231bc772a4a1505460cdb71d10d6a26ce Mon Sep 17 00:00:00 2001 From: michaelpacer Date: Mon, 17 Aug 2015 22:39:53 -0700 Subject: [PATCH 06/11] fixed commented out import statement --- tests/test_strunk_white_eos.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 From 84cf919bac47da1780256a8b3e22ecbb501903a1 Mon Sep 17 00:00:00 2001 From: michaelpacer Date: Mon, 17 Aug 2015 22:45:50 -0700 Subject: [PATCH 07/11] fixed to accord with pep8 --- proselint/tools.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proselint/tools.py b/proselint/tools.py index 6480e7b94..f6248f050 100644 --- a/proselint/tools.py +++ b/proselint/tools.py @@ -129,7 +129,9 @@ 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, str=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 From 896b3d2be443fa978953a0109d2c0ad36aded154 Mon Sep 17 00:00:00 2001 From: michaelpacer Date: Mon, 17 Aug 2015 22:56:06 -0700 Subject: [PATCH 08/11] removed linkchecker so travis will build without support issues --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2498aa8c1..0ced68a1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ python: - "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 @@ -22,7 +21,6 @@ script: - jekyll build - s3_website push - cd .. - - linkchecker 'http://prose.lifelinter.com' - pep8 . - pep257 . --match='.*\.py' after_success: From f2bfccffdfb8e7db35b3dbc0b1d4bcf9070f04f9 Mon Sep 17 00:00:00 2001 From: Jordan Suchow Date: Tue, 18 Aug 2015 02:09:21 -0400 Subject: [PATCH 09/11] Add a Ruby-based link checker --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0ced68a1c..a32bd2c92 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,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 @@ -23,6 +24,7 @@ script: - cd .. - pep8 . - pep257 . --match='.*\.py' + - check-links "http://prose.lifelinter.com" after_success: - coveralls env: From 6ad4ddd08e8869707efa1dfef82f5de53f81d517 Mon Sep 17 00:00:00 2001 From: michaelpacer Date: Mon, 17 Aug 2015 23:15:25 -0700 Subject: [PATCH 10/11] fixed formatting to fulfill annoying pep8 and make travis happy --- proselint/tools.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/proselint/tools.py b/proselint/tools.py index f6248f050..d662931e0 100644 --- a/proselint/tools.py +++ b/proselint/tools.py @@ -129,9 +129,11 @@ 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, - str=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 From 725b7a8c23c9ef960b8a132731928a996eea761a Mon Sep 17 00:00:00 2001 From: Jordan Suchow Date: Tue, 18 Aug 2015 02:45:59 -0400 Subject: [PATCH 11/11] Further appease the linters --- proselint/tools.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/proselint/tools.py b/proselint/tools.py index d662931e0..d9d04297b 100644 --- a/proselint/tools.py +++ b/proselint/tools.py @@ -4,7 +4,6 @@ """General-purpose tools shared across linting checks.""" from __future__ import print_function from __future__ import unicode_literals -from builtins import str import os import shelve import inspect @@ -130,10 +129,9 @@ def preferred_forms_check(text, list, err, msg, ignore_case=True, offset=0): def existence_check(text, list, err, msg, ignore_case=True, - str=False, max_errors=float("inf"), offset=0, - require_padding=True, dotall=False, + 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