Commit c375ae4e authored by Grant Paton-Simpson's avatar Grant Paton-Simpson

Separate lint conf out; remove demo script; bump version

parent 827c0bf1
......@@ -4,7 +4,6 @@ git:
sed -i 's/^test_misc()/# test_misc()/' /home/g/projects/superhelp/tests/*.py
sed -i 's/RECORD_AST = t/RECORD_AST = f/' /home/g/projects/superhelp/superhelp/conf.py
sed -i 's/DEV_MODE = t/DEV_MODE = f/' /home/g/projects/superhelp/superhelp/conf.py
sed -i 's/DO_TEST = f/DO_TEST = t/' /home/g/projects/superhelp/superhelp/conf.py
sed -i 's/DO_HTML = f/DO_HTML = t/' /home/g/projects/superhelp/superhelp/conf.py
sed -i 's/DO_DISPLAYER = f/DO_DISPLAYER = t/' /home/g/projects/superhelp/superhelp/conf.py
git status
......
# https://git.nzoss.org.nz/pyGrant/superhelp
version number: 0.9.12
version number: 0.9.13
author: Grant Paton-Simpson
## Overview
......
......@@ -2,7 +2,7 @@ from setuptools import setup, find_packages # @UnresolvedImport
from codecs import open
from os import path
__version__ = '0.9.12'
__version__ = '0.9.13'
here = path.abspath(path.dirname(__file__))
......
......@@ -5,7 +5,7 @@ from subprocess import run, PIPE
import sys
from ..advisors import snippet_str_advisor
from .. import conf
from .. import conf, lint_conf
from ..utils import get_nice_str_list, get_os_platform, \
layout_comment as layout, make_open_tmp_file
......@@ -59,8 +59,8 @@ def _get_flake8_fpath():
def _get_flake8_results(fpath):
flake8_fpath = _get_flake8_fpath()
args = [flake8_fpath, str(fpath)]
if conf.IGNORED_LINT_RULES:
ignored = ','.join(conf.IGNORED_LINT_RULES)
if lint_conf.IGNORED_LINT_RULES:
ignored = ','.join(lint_conf.IGNORED_LINT_RULES)
args.append(f"--extend-ignore={ignored}")
res = run(args=args, stdout=PIPE)
return res
......@@ -98,7 +98,7 @@ def _get_lint_dets_by_msg_type(lint_regex_dicts):
msg_type = lint_regex_dict[conf.LINT_MSG_TYPE]
msg = lint_regex_dict[conf.LINT_MSG]
try:
msg_dets = conf.CUSTOM_LINT_MSGS[msg_type]
msg_dets = lint_conf.CUSTOM_LINT_MSGS[msg_type]
except KeyError:
pass
else:
......@@ -139,9 +139,9 @@ def _get_msg_lines(lint_dets_by_msg_type):
msg_line = _get_msg_line(msg_lineno_pairs)
msg_lines.append(msg_line)
## add supplementary line?
supplement_configured = msg_type in conf.CUSTOM_LINT_MSGS
supplement_configured = msg_type in lint_conf.CUSTOM_LINT_MSGS
if msg_type not in already_supplemented and supplement_configured:
msg_dets = conf.CUSTOM_LINT_MSGS[msg_type]
msg_dets = lint_conf.CUSTOM_LINT_MSGS[msg_type]
supplement_needed = not msg_dets.replacement
if supplement_needed:
msg_placeholder = _msg_type_to_placeholder(msg_type)
......@@ -157,7 +157,7 @@ def _get_lint_msg(raw_lint_message, msg_level):
"""
msg_type_to_msg_level = {
_msg_type_to_placeholder_key(msg_type): getattr(msg_dets, msg_level)
for msg_type, msg_dets in conf.CUSTOM_LINT_MSGS.items()
for msg_type, msg_dets in lint_conf.CUSTOM_LINT_MSGS.items()
}
lint_msg = raw_lint_message.format(**msg_type_to_msg_level) ## e.g. E501_msg="Line too long", E666_msg='Code is generally evil'
return lint_msg
......@@ -166,7 +166,7 @@ def _get_extra_msg(lint_dets_by_msg_type):
msg_types_used = lint_dets_by_msg_type.keys()
extra_lines = []
for msg_type in msg_types_used:
msgs = conf.CUSTOM_LINT_MSGS.get(msg_type)
msgs = lint_conf.CUSTOM_LINT_MSGS.get(msg_type)
if not msgs:
continue
extra_lines.append(msgs.extra)
......
from collections import namedtuple
import datetime
import logging
......@@ -11,7 +10,6 @@ f = False
RECORD_AST = f ## (f)
DEV_MODE = f ## (f)
DO_TEST = t ## set test snippet as default rather than the larger demo snippet (t)
DO_HTML = t ## set html displayer as default (t)
DO_DISPLAYER = t ## f is only ever used when testing pre-display (t)
INCLUDE_LINTING = t ## f when running unit tests to massively speed them up (otherwise every snippet in tests is linted each time) (t)
......@@ -27,7 +25,6 @@ else:
## When testing user-supplied snippets watch out for the BOM MS inserts via Notepad. AST chokes on it.
## All snippets here should be raw strings (see https://stackoverflow.com/questions/53636723/python-parsing-code-with-new-line-character-in-them-using-ast)
TEST_SNIPPET = r"""
def sorted(*G, **kwargs):
......@@ -40,130 +37,6 @@ sorted(G)
print(G)
"""
DEMO_SNIPPET = r"""
import datetime
from math import pi as π
mixed_keys = {1: 'cat', '1': 'dog'}
mixedTypes = [
datetime.datetime.strptime('2020-02-10', '%Y-%m-%d'),
π, 5, 1.234, 'Noor', False,
]
names = ['Noor', 'Grant', 'Hyeji', 'Vicky', 'Olek', 'Marzena', 'Jess', 'Nicole']
names_lower = [name.lower() for name in names]
name_lengths = []
for name in ['Noor', 'Grant', ]:
name_lengths.append(len(name))
fullName = 'Guido van Rossum'
evens_squared = [x**2 for x in range(1, 6) if x % 2 == 0]
empty = []
myint = 666
myfloat = 6.667
myscinot = 1.23E-7
my_tup = ('alpha', 'beta')
greeting = f"Hi {names[0]}!"
greeting = "Hi " + names[0] + "!"
def powerMe(num, *, power=2):
poweredVal = num ** power
return poweredVal
coord = ('lat', 'lon')
latitude = coord[0]
longitude = coord[1]
demo = (1, 2, 3, 4)
x, yy, zz, aaa = demo
people = set(['Sam', 'Avi', 'Terri', 'Noor'])
no_email = set(['Sam', 'Terri'])
people2email = people - no_email
empty_set = set()
len_word = len(fullName)
if len_word == 1:
status = 'single-letter'
elif len_word < 4:
status = 'short'
elif len_word > 12:
status = 'long'
elif len_word > 20:
status = 'very_long'
# else:
# status = 'typical'
if len('chicken') > 2:
print('cluck!')
phrase = "His age is %i" % 21
fruit = ['banana']
try:
lunch = fruit[100]
except (IndexError, TypeError):
print("No lunch for you!")
except Exception as e:
print(f"Unknown error - details: {e}")
try:
float('boat')
except ValueError:
print("You can't float a boat! Only a number of some sort!")
try:
names[100]
except Exception:
print(names)
sorted_names = sorted(names)
faulty_val = names.sort()
## modified and given more problems and features, from https://stackoverflow.com/questions/61154079/sorting-using-list-built-in-method-and-user-defined-function-sorts-the-list-with
def sorted(*G, **kwargs):
for i in range(len(G)):
for j in range(1,len(G)):
if G[j-1]<G[j]:
G[j-1],G[j]=G[j],G[j-1]
G = [['Ahmad', 3.8], ['Rizwan', 3.68], ['Bilal', 3.9]]
sorted(G)
print(G)
from functools import wraps
def tweet(func):
@wraps(func)
def wrapper(message):
func(message)
print(f"I'm tweeting the message {message}")
return wrapper
@tweet
def say(message):
print(message)
say("sausage!")
def has_docstring():
'''
Hi
'''
pass
def lacks_proper_docstring():
# Not a doc string
pass
def lacks_any_docstring():
666
name = 'Grant'
'''
Ho
'''
def random():
'''
This is line 1
Line 2
Line 3
'''
pass
def camelCase(a, b, c, d, f, *, g):
'''
This is line 1
Line 2
Line 3
'''
pass
"""
PY3_6 = '3.6'
PY3_7 = '3.7'
PY3_8 = '3.8'
......@@ -254,47 +127,6 @@ SNIPPET_FNAME = 'snippet.py'
LINT_MSG_TYPE = 'msg_type'
LINT_MSG = 'msg'
LINT_LINE_NO = 'line_no'
## https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
## https://flake8.pycqa.org/en/latest/user/error-codes.html
IGNORED_LINT_RULES = [
'E128', ## flake8 wants visual alignment on line continuation - I don't - I want standardised alignment on indent multiples of 4 (idea taken from Brandon Rhodes thanks Brandon!)
'E266', 'E262', ## I like ## before comments and # before commented out code (idea copied off Tom Eastman - thanks Tom!)
'E305', ## for classes I agree with 2 spaces but not functions
]
LintMsgs = namedtuple('LintMsgs', 'brief, main, extra, replacement')
CUSTOM_LINT_MSGS = {
'E501': LintMsgs(
"""\
One or more lines are longer than the recommended 79 characters. This is
not necessarily a problem but long lines should be an exception to the
rule
""",
"""\
One or more lines are longer than the recommended 79 characters. This is
not necessarily a problem given that we have wider monitors than when
the guidelines were formulated. But long lines should be an exception to
the rule. All being equal, short lines are easier to read and understand
than long lines. There are multiple strategies for shortening lines but
the overall goal has to be readability. Sometimes we have to live with
broken "rules". And that's official. Read PEP 8 - the official Python
style guide - especially the section "A Foolish Consistency is the
Hobgoblin of Little Minds".
""",
'',
True),
'F401': LintMsgs(
"""\
One or more imports not used in snippet.
""",
"""\
One or more imports not used in snippet. If the snippet was extracted
from a larger piece of code and the imports are used in that code then
there is no problem.
""",
'',
False
)
}
LINE_FEED = '&#10;'
......
......@@ -22,7 +22,6 @@ logging.basicConfig(
advisors.load_advisors()
do_test = conf.DO_TEST ## use test snippet rather than the larger demo snippet
do_html = conf.DO_HTML ## use html displayer vs cli displayer
do_displayer = conf.DO_DISPLAYER ## for dev testing only
......@@ -43,7 +42,7 @@ def _get_snippet(snippet, file_path):
elif snippet:
pass
else:
snippet = conf.TEST_SNIPPET if do_test else conf.DEMO_SNIPPET
snippet = conf.TEST_SNIPPET
logging.info("Using default snippet because no snippet provided")
return snippet
......
from collections import namedtuple
## https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
## https://flake8.pycqa.org/en/latest/user/error-codes.html
IGNORED_LINT_RULES = [
'E128', ## flake8 wants visual alignment on line continuation - I don't - I want standardised alignment on indent multiples of 4 (idea taken from Brandon Rhodes thanks Brandon!)
'E266', 'E262', ## I like ## before comments and # before commented out code (idea copied off Tom Eastman - thanks Tom!)
'E305', ## for classes I agree with 2 spaces but not functions
]
LintMsgs = namedtuple('LintMsgs', 'brief, main, extra, replacement')
CUSTOM_LINT_MSGS = {
'E501': LintMsgs(
"""\
One or more lines are longer than the recommended 79 characters. This is
not necessarily a problem but long lines should be an exception to the
rule
""",
"""\
One or more lines are longer than the recommended 79 characters. This is
not necessarily a problem given that we have wider monitors than when
the guidelines were formulated. But long lines should be an exception to
the rule. All being equal, short lines are easier to read and understand
than long lines. There are multiple strategies for shortening lines but
the overall goal has to be readability. Sometimes we have to live with
broken "rules". And that's official. Read PEP 8 - the official Python
style guide - especially the section "A Foolish Consistency is the
Hobgoblin of Little Minds".
""",
'',
True),
'F401': LintMsgs(
"""\
One or more imports not used in snippet.
""",
"""\
One or more imports not used in snippet. If the snippet was extracted
from a larger piece of code and the imports are used in that code then
there is no problem.
""",
'',
False
)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment