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

Python3 #156

Merged
merged 12 commits into from
Aug 18, 2015
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
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
- gem install s3_website
- 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
Expand All @@ -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:
Expand Down
31 changes: 31 additions & 0 deletions futurizing_output.txt
Original file line number Diff line number Diff line change
@@ -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()
26 changes: 16 additions & 10 deletions proselint/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
21 changes: 12 additions & 9 deletions proselint/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion scripts/generate_posts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Generate blog posts from check docstrings."""

from builtins import str
from builtins import range
import os
import ast
import datetime
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions scripts/insert_demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Insert the demo into the codemirror site."""
from __future__ import print_function

import os
import fileinput
Expand Down Expand Up @@ -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=' ')
3 changes: 2 additions & 1 deletion tests/_test_mau_a_vs_an.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
1 change: 1 addition & 0 deletions tests/check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Check that a check is working."""

from past.builtins import basestring
from unittest import TestCase
import os
import codecs
Expand Down
3 changes: 2 additions & 1 deletion tests/test_dfw_uncomparables.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
3 changes: 2 additions & 1 deletion tests/test_garner_dates.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
4 changes: 3 additions & 1 deletion tests/test_strunk_white_eos.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down