Skip to content

Commit

Permalink
Merge branch '2.0'
Browse files Browse the repository at this point in the history
master now has become 2.0, there won't be another 1.6 anymore,
since the focus of the team is on the next big release now.
Minor bug fixes will be implemented though in 1.5.X.
  • Loading branch information
PCManticore committed Feb 16, 2016
2 parents 6d31776 + 3770120 commit 98c887d
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 92 deletions.
17 changes: 16 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ ChangeLog for Pylint
--------------------

--
* Disable reports by default and show the evaluation score by default

As per discussion from issue #746, the reports were disabled by
default in order to simplify the interaction between the tool
and the users. The score is still shown by default, as a way of
closely measuring when it increases or decreases due to changes
brought to the code.

* Disable the information category messages by default.

This is a step towards making pylint more sane, as
per the discussion from issue #746.



* Catch more cases as not proper iterables for __slots__ with
regard to invalid-slots pattern. Closes issue #775.

Expand Down Expand Up @@ -53,7 +68,7 @@ ChangeLog for Pylint
Closes issue #745.

* empty indent strings are rejected.

* Suppress reporting 'unneeded-not' inside `__ne__` methods

Closes issue #749.
Expand Down
2 changes: 1 addition & 1 deletion pylint/__pkginfo__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

modname = distname = 'pylint'

numversion = (1, 6, 0)
numversion = (2, 0, 0)
version = '.'.join([str(num) for num in numversion])

install_requires = [
Expand Down
41 changes: 23 additions & 18 deletions pylint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@


MANAGER = astroid.MANAGER
INCLUDE_IDS_HELP = ("Deprecated. It was used to include message\'s "
"id in output. Use --msg-template instead.")
SYMBOLS_HELP = ("Deprecated. It was used to include symbolic ids of "
"messages in output. Use --msg-template instead.")


def _get_new_args(message):
location = (
Expand Down Expand Up @@ -299,8 +296,8 @@ def make_options():
'short': 'f',
'group': 'Reports',
'help' : 'Set the output format. Available formats are text,'
' parseable, colorized, msvs (visual studio) and html. You '
'can also give a reporter class, eg mypackage.mymodule.'
' parseable, colorized, json, msvs (visual studio) and html. '
'You can also give a reporter class, eg mypackage.mymodule.'
'MyReporterClass.'}),

('files-output',
Expand All @@ -312,7 +309,7 @@ def make_options():
'name "pylint_global.[txt|html]".'}),

('reports',
{'default': 1, 'type' : 'yn', 'metavar' : '<y_or_n>',
{'default': False, 'type' : 'yn', 'metavar' : '<y_or_n>',
'short': 'r',
'group': 'Reports',
'help' : 'Tells whether to display a full report or only the '
Expand All @@ -330,6 +327,11 @@ def make_options():
'warnings messages and the total number of '
'statements analyzed. This is used by the global '
'evaluation report (RP0004).'}),
('score',
{'default': True, 'type': 'yn', 'metavar': '<y_or_n>',
'short': 's',
'group': 'Reports',
'help': 'Activate the evaluation score.'}),

('comment', utils.deprecated_option(opt_type='yn')),

Expand Down Expand Up @@ -459,8 +461,6 @@ def __init__(self, options=(), reporter=None, option_groups=(),
report_messages_by_module_stats),
('RP0003', 'Messages',
report_messages_stats),
('RP0004', 'Global evaluation',
self.report_evaluation),
)
self.register_checker(self)
self._dynamic_plugins = set()
Expand Down Expand Up @@ -606,6 +606,7 @@ def error_mode(self):
self.disable('python3')
self.set_option('reports', False)
self.set_option('persistent', False)
self.set_option('score', False)

def python3_porting_mode(self):
"""Disable all other checkers and enable Python 3 warnings."""
Expand Down Expand Up @@ -982,35 +983,40 @@ def generate_reports(self):
self.reporter.set_output(open(filename, 'w'))
else:
sect = report_nodes.Section()

if self.config.reports:
self.reporter.display_reports(sect)
self._report_evaluation()
# save results if persistent run
if self.config.persistent:
config.save_results(self.stats, self.file_state.base_name)
else:
self.reporter.on_close(self.stats, {})

# specific reports ########################################################

def report_evaluation(self, sect, stats, previous_stats):
def _report_evaluation(self):
"""make the global evaluation report"""
# check with at least check 1 statements (usually 0 when there is a
# syntax error preventing pylint from further processing)
if stats['statement'] == 0:
raise utils.EmptyReport()
previous_stats = config.load_results(self.file_state.base_name)
if self.stats['statement'] == 0:
return

# get a global note for the code
evaluation = self.config.evaluation
try:
note = eval(evaluation, {}, self.stats) # pylint: disable=eval-used
except Exception as ex: # pylint: disable=broad-except
msg = 'An exception occurred while rating: %s' % ex
else:
stats['global_note'] = note
self.stats['global_note'] = note
msg = 'Your code has been rated at %.2f/10' % note
pnote = previous_stats.get('global_note')
if pnote is not None:
msg += ' (previous run: %.2f/10, %+.2f)' % (pnote, note - pnote)
sect.append(report_nodes.Text(msg))

if self.config.score:
sect = report_nodes.EvaluationSection(msg)
self.reporter.display_reports(sect)

# some reporting functions ####################################################

Expand Down Expand Up @@ -1263,8 +1269,7 @@ def __init__(self, args, reporter=None, exit=True):
'been issued by analysing pylint output status code\n',
level=1)
# read configuration
linter.disable('suppressed-message')
linter.disable('useless-suppression')
linter.disable('I')
linter.read_config_file()
config_parser = linter.cfgfile_parser
# run init hook, if present, before loading plugins
Expand Down
6 changes: 0 additions & 6 deletions pylint/reporters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ def display_reports(self, layout):
layout.children[0].children[0].data += ' (%s)' % layout.report_id
self._display(layout)

def display_results(self, layout):
warnings.warn("display_results is deprecated, use display_reports instead. "
"The former will be removed in Pylint 2.0.",
DeprecationWarning)
self.display_reports(layout)

def _display(self, layout):
"""display the layout"""
raise NotImplementedError()
Expand Down
2 changes: 2 additions & 0 deletions pylint/reporters/ureports/html_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def visit_section(self, layout):
self.writeln(u'</div>')
self.section -= 1

visit_evaluationsection = visit_section

def visit_title(self, layout):
"""display a title using <hX>"""
self.write(u'<h%s>' % self.section)
Expand Down
13 changes: 13 additions & 0 deletions pylint/reporters/ureports/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ def __init__(self, title=None, description=None, **kwargs):
self.insert(0, Title(children=(title,)))


class EvaluationSection(Section):

def __init__(self, message, **kwargs):
super(EvaluationSection, self).__init__(**kwargs)
title = Paragraph()
title.append(Text("-" * len(message)))
self.append(title)

message_body = Paragraph()
message_body.append(Text(message))
self.append(message_body)


class Title(BaseLayout):
"""a title
Expand Down
7 changes: 7 additions & 0 deletions pylint/reporters/ureports/text_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def visit_section(self, layout):
self.section -= 1
self.writeln()

def visit_evaluationsection(self, layout):
"""Display an evaluation section as a text."""
self.section += 1
self.format_children(layout)
self.section -= 1
self.writeln()

def visit_title(self, layout):
title = u''.join(list(self.compute_content(layout)))
self.writeln(title)
Expand Down
13 changes: 1 addition & 12 deletions pylint/test/regrtest_data/application_crash.py
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
class ErudiPublisher:
def __init__(self, config):
self.url_resolver = self.select_component('urlpublisher')

def select_component(self, cid, *args, **kwargs):
try:
return self.select(self.registry_objects('components', cid), *args, **kwargs)
except NoSelectableObject:
return

def main_publish(self, path, req):
ctrlid = self.url_resolver.process(req, path)
ABC = something_undefined
3 changes: 3 additions & 0 deletions pylint/test/regrtest_data/meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pylint: disable=invalid-name, missing-docstring
# pylint: disable=unbalanced-tuple-unpacking
n = 42
1 change: 1 addition & 0 deletions pylint/test/test_import_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def setUp(self):
def test_checker_dep_graphs(self):
l = self.linter
l.global_set_option('persistent', False)
l.global_set_option('reports', True)
l.global_set_option('enable', 'imports')
l.global_set_option('import-graph', 'import.dot')
l.global_set_option('ext-import-graph', 'ext_import.dot')
Expand Down
20 changes: 19 additions & 1 deletion pylint/test/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def test_wrong_import_position_when_others_disabled(self):
module2 = join(HERE, 'regrtest_data', 'wrong_import_position.py')
args = [module2, module1,
"--disable=all", "--enable=wrong-import-position",
"-rn"]
"-rn", "-sn"]
out = six.StringIO()
self._run_pylint(args, out=out)
actual_output = out.getvalue()
Expand Down Expand Up @@ -342,6 +342,24 @@ def test_json_report_when_file_is_missing(self):
self.assertEqual(message[key], value)
self.assertTrue(message['message'].startswith("No module named"))

def test_information_category_disabled_by_default(self):
expected = 'No config file found, using default configuration'
path = join(HERE, 'regrtest_data', 'meta.py')
self._test_output([path], expected_output=expected)

def test_error_mode_shows_no_score(self):
expected_output = textwrap.dedent('''
No config file found, using default configuration
************* Module application_crash
E: 1, 6: Undefined variable 'something_undefined' (undefined-variable)
''')
module = join(HERE, 'regrtest_data', 'application_crash.py')
self._test_output([module, "-E"], expected_output=expected_output)

def test_evaluation_score_shown_by_default(self):
expected_output = 'Your code has been rated at -60.00/10'
module = join(HERE, 'regrtest_data', 'application_crash.py')
self._test_output([module], expected_output=expected_output)


if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions pylint/test/unittest_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def test_lint_ext_module_with_file_output(self):
else:
strio = 'io'
self.linter.config.files_output = True
self.linter.config.reports = True
pylint_strio = 'pylint_%s.txt' % strio
files = [pylint_strio, 'pylint_global.txt']
for file in files:
Expand Down
12 changes: 2 additions & 10 deletions pylint/test/unittest_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,8 @@ def _display(self, layout):
return None

reporter = CustomReporter()
if __pkginfo__.numversion >= (2, 0):
with self.assertRaises(AttributeError):
reporter.display_results
else:
with warnings.catch_warnings(record=True) as cm:
warnings.simplefilter("always")
reporter.display_results(Section())

self.assertEqual(len(cm), 1)
self.assertIsInstance(cm[0].message, DeprecationWarning)
with self.assertRaises(AttributeError):
reporter.display_results


if __name__ == '__main__':
Expand Down
12 changes: 1 addition & 11 deletions pylint/test/unittest_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,10 @@ def visit_assname(self, node):
walker = utils.PyLintASTWalker(linter)
checker = Checker()
walker.add_checker(checker)
with warnings.catch_warnings(record=True) as w:
with warnings.catch_warnings(record=True):
warnings.simplefilter('always')
walker.walk(astroid.parse("x = 1"))

if __pkginfo__.numversion < (2, 0):
expected = ('Implemented method visit_assname instead of '
'visit_assignname. This will be supported until '
'Pylint 2.0.')
self.assertEqual(len(w), 1)
self.assertIsInstance(w[0].message, PendingDeprecationWarning)
self.assertEqual(str(w[0].message), expected)
self.assertTrue(checker.called)
else:
self.assertNotEqual(len(w), 1)
self.assertFalse(checker.called)


Expand Down
34 changes: 2 additions & 32 deletions pylint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,6 @@ class EmptyReport(Exception):
'F' : 1
}

DEPRECATED_ALIASES = {
# New name, deprecated name.
'repr': 'backquote',
'expr': 'discard',
'assignname': 'assname',
'assignattr': 'assattr',
'attribute': 'getattr',
'call': 'callfunc',
'importfrom': 'from',
'classdef': 'class',
'functiondef': 'function',
'generatorexp': 'genexpr',
}

_MSG_ORDER = 'EWRCIF'
MSG_STATE_SCOPE_CONFIG = 0
MSG_STATE_SCOPE_MODULE = 1
Expand Down Expand Up @@ -922,27 +908,11 @@ def walk(self, astroid):
# In this case, favour the methods for the deprecated
# alias if any, in order to maintain backwards
# compatibility.
old_cid = DEPRECATED_ALIASES.get(cid)
visit_events = ()
leave_events = ()

if old_cid:
visit_events = self.visit_events.get(old_cid, ())
leave_events = self.leave_events.get(old_cid, ())
if visit_events or leave_events:
msg = ("Implemented method {meth}_{old} instead of {meth}_{new}. "
"This will be supported until Pylint 2.0.")
if visit_events:
warnings.warn(msg.format(meth="visit", old=old_cid, new=cid),
PendingDeprecationWarning)
if leave_events:
warnings.warn(msg.format(meth="leave", old=old_cid, new=cid),
PendingDeprecationWarning)

visit_events = itertools.chain(visit_events,
self.visit_events.get(cid, ()))
leave_events = itertools.chain(leave_events,
self.leave_events.get(cid, ()))
visit_events = self.visit_events.get(cid, ())
leave_events = self.leave_events.get(cid, ())

if astroid.is_statement:
self.nbstatements += 1
Expand Down

0 comments on commit 98c887d

Please sign in to comment.