Skip to content

Commit

Permalink
Merge pull request #111 from plone/correct-exit-codes
Browse files Browse the repository at this point in the history
Return correct exit codes in console scripts, fixes #66
  • Loading branch information
saily committed Apr 26, 2015
2 parents b84e5c2 + ec21b08 commit bd2229b
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Change history
2.0.0 (unreleased)
------------------

- Return correct exit codes for console-scripts, fixes #66.
[saily]

- Refactor whole linters framework to use OO design patterns, inherit from
``Analyser`` abstract base class. This fixes #62
[saily]
Expand Down
6 changes: 6 additions & 0 deletions plone/recipe/codeanalysis/analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def is_string(unknown):
return isinstance(unknown, str)


def console_factory(klass, options):
if not klass(options).run():
sys.exit(1)
sys.exit(0)


class Analyser:

__metaclass__ = ABCMeta
Expand Down
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/clean_lines.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import Analyser
from plone.recipe.codeanalysis.analyser import console_factory
import re


Expand Down Expand Up @@ -102,4 +103,4 @@ def run(self):


def console_script(options):
return CleanLines(options).run()
console_factory(CleanLines, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/csslint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import Analyser
from plone.recipe.codeanalysis.analyser import console_factory
import re


Expand Down Expand Up @@ -39,4 +40,4 @@ def parse_output(self, output_file, return_code):


def console_script(options):
return CSSLint(options).run()
console_factory(CSSLint, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/debug_statements.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import console_factory
from plone.recipe.codeanalysis.clean_lines import CleanLines


Expand All @@ -24,4 +25,4 @@ class DebugStatements(CleanLines):


def console_script(options):
return DebugStatements(options).run()
console_factory(DebugStatements, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/deprecated_aliases.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import console_factory
from plone.recipe.codeanalysis.clean_lines import CleanLines


Expand Down Expand Up @@ -45,4 +46,4 @@ def check(self, file_path, fail={}, **kwargs):


def console_script(options):
return DeprecatedAliases(options).run()
console_factory(DeprecatedAliases, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/flake8.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import Analyser
from plone.recipe.codeanalysis.analyser import console_factory
import os


Expand Down Expand Up @@ -37,4 +38,4 @@ def open_output_file(self):


def console_script(options):
return Flake8(options).run()
console_factory(Flake8, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/i18ndude.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import Analyser
from plone.recipe.codeanalysis.analyser import console_factory


class I18NDude(Analyser):
Expand All @@ -21,4 +22,4 @@ def cmd(self):


def console_script(options):
return I18NDude(options).run()
console_factory(I18NDude, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/imports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import console_factory
from plone.recipe.codeanalysis.clean_lines import CleanLines
import re

Expand Down Expand Up @@ -78,4 +79,4 @@ def check(self, file_path, fail={}, **kwargs):


def console_script(options):
return Imports(options).run()
console_factory(Imports, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/jscs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import Analyser
from plone.recipe.codeanalysis.analyser import console_factory
import re


Expand Down Expand Up @@ -52,4 +53,4 @@ def parse_output(self, output_file, return_code):


def console_script(options):
return JSCS(options).run()
console_factory(JSCS, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/jshint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import Analyser
from plone.recipe.codeanalysis.analyser import console_factory
import re


Expand Down Expand Up @@ -43,4 +44,4 @@ def parse_output(self, output_file, return_code):


def console_script(options):
return JSHint(options).run()
console_factory(JSHint, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/pep3101.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import console_factory
from plone.recipe.codeanalysis.clean_lines import CleanLines


Expand All @@ -17,4 +18,4 @@ class PEP3101(CleanLines):


def console_script(options):
return PEP3101(options).run()
console_factory(PEP3101, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/py_hasattr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import console_factory
from plone.recipe.codeanalysis.clean_lines import CleanLines


Expand All @@ -19,4 +20,4 @@ class HasAttr(CleanLines):


def console_script(options):
return HasAttr(options).run()
console_factory(HasAttr, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/python_utf8_header.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import console_factory
from plone.recipe.codeanalysis.clean_lines import CleanLines
import re

Expand Down Expand Up @@ -31,4 +32,4 @@ def check(self, file_path, succeed, **kwargs):


def console_script(options):
return UTF8Headers(options).run()
console_factory(UTF8Headers, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/quoting.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import console_factory
from plone.recipe.codeanalysis.clean_lines import CleanLines


Expand Down Expand Up @@ -60,4 +61,4 @@ def check(self, file_path, **kwargs):


def console_script(options):
return PreferSingleQuotes(options).run()
console_factory(PreferSingleQuotes, options)
3 changes: 2 additions & 1 deletion plone/recipe/codeanalysis/zptlint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plone.recipe.codeanalysis.analyser import Analyser
from plone.recipe.codeanalysis.analyser import console_factory


class ZPTLint(Analyser):
Expand Down Expand Up @@ -35,4 +36,4 @@ def parse_output(self, output_file, return_code):


def console_script(options):
return ZPTLint(options).run()
console_factory(ZPTLint, options)

0 comments on commit bd2229b

Please sign in to comment.