diff --git a/setup.py b/setup.py index db57204c..d59929c2 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,19 @@ author='Scott Barnett', author_email='scott.barnett@deakin.edu.au', include_package_data=True, - packages=['surround', 'templates', 'surround.remote', 'surround.split', 'surround.visualise', 'surround.data', 'surround.data.cli', 'surround.configuration', 'surround.experiment', 'surround.experiment.web'], + packages=[ + 'surround', + 'templates', + 'surround.remote', + 'surround.split', + 'surround.visualise', + 'surround.data', + 'surround.data.cli', + 'surround.configuration', + 'surround.experiment', + 'surround.experiment.web', + 'surround.checkers' + ], test_suite='surround.tests', entry_points={ 'console_scripts': [ diff --git a/surround/checkers/__init__.py b/surround/checkers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/surround/checkers/surround_checker.py b/surround/checkers/surround_checker.py new file mode 100644 index 00000000..441e7f3b --- /dev/null +++ b/surround/checkers/surround_checker.py @@ -0,0 +1,24 @@ +from pylint import checkers +from pylint import interfaces +from pylint.checkers import utils + +class SurroundChecker(checkers.BaseChecker): + __implements__ = interfaces.IAstroidChecker + + name = 'surround-convention' + + msgs = { + 'CS001': ( + "Use of print instead of logging statements", + 'surround-avoid-print', + 'Used when a script uses print instead of a logging statement', + ) + } + + @utils.check_messages('surround-avoid-print') + def visit_call(self, node): + if node.func.as_string() == "print": + self.add_message('surround-avoid-print', node=node) + +def register(linter): + linter.register_checker(SurroundChecker(linter)) diff --git a/surround/linter.py b/surround/linter.py index dc2dbb68..0d2934bd 100644 --- a/surround/linter.py +++ b/surround/linter.py @@ -51,6 +51,8 @@ def check_project(self, project_root=os.curdir, extra_args=None, verbose=False): 'attribute-defined-outside-init' ] + args.append("--load-plugins=surround.checkers.surround_checker") + for msg in disable_msgs: args.append('--disable=%s' % msg) diff --git a/templates/new/dodo.py.txt b/templates/new/dodo.py.txt index 7bbcffba..a492608f 100644 --- a/templates/new/dodo.py.txt +++ b/templates/new/dodo.py.txt @@ -7,6 +7,7 @@ import sys import subprocess import re import webbrowser +import logging from pathlib import Path @@ -18,6 +19,7 @@ CONFIG = Config(os.path.dirname(__file__)) DOIT_CONFIG = {{'verbosity':2}} PACKAGE_PATH = os.path.basename(CONFIG["package_path"]) IMAGE = "%s/%s:%s" % (CONFIG["company"], CONFIG["image"], CONFIG["version"]) +LOGGER = logging.getLogger(__name__) PARAMS = [ {{ @@ -237,7 +239,7 @@ def task_jupyter(): stderr=subprocess.PIPE, encoding='utf-8') - print("Starting jupyter notbook server...\n") + LOGGER.info("Starting jupyter notbook server...\n") # Get the IP address of the container, otherwise use localhost ip_process = subprocess.Popen( @@ -261,7 +263,7 @@ def task_jupyter(): break if process.poll(): - print("Failed to start the server, check if its not running somewhere else!") + LOGGER.error("Failed to start the server, check if its not running somewhere else!") # Stop any containers that might be running process = subprocess.Popen( @@ -278,15 +280,15 @@ def task_jupyter(): # Open the browser automatically webbrowser.open('http://%s:55910/tree' % host, new=2) - print("Notebook URL: http://%s:55910/tree\n" % host) - print("Use CTRL+C to stop the server.") + LOGGER.info("Notebook URL: http://%s:55910/tree\n", host) + LOGGER.info("Use CTRL+C to stop the server.") try: process.wait() except KeyboardInterrupt: pass finally: - print("Closing server...") + LOGGER.info("Closing server...") process = subprocess.Popen( [ 'docker', diff --git a/templates/new/web_dodo.py.txt b/templates/new/web_dodo.py.txt index fa3fbe16..02263a6c 100644 --- a/templates/new/web_dodo.py.txt +++ b/templates/new/web_dodo.py.txt @@ -7,6 +7,7 @@ import sys import subprocess import re import webbrowser +import logging from pathlib import Path @@ -18,6 +19,7 @@ CONFIG = Config(os.path.dirname(__file__)) DOIT_CONFIG = {{'verbosity':2}} PACKAGE_PATH = os.path.basename(CONFIG["package_path"]) IMAGE = "%s/%s:%s" % (CONFIG["company"], CONFIG["image"], CONFIG["version"]) +LOGGER = logging.getLogger(__name__) PARAMS = [ {{ @@ -285,7 +287,7 @@ def task_jupyter(): stderr=subprocess.PIPE, encoding='utf-8') - print("Starting jupyter notbook server...\n") + LOGGER.info("Starting jupyter notbook server...\n") # Get the IP address of the container, otherwise use localhost ip_process = subprocess.Popen( @@ -309,7 +311,7 @@ def task_jupyter(): break if process.poll(): - print("Failed to start the server, please try again!") + LOGGER.error("Failed to start the server, please try again!") # Stop any containers that might be running process = subprocess.Popen( @@ -326,15 +328,15 @@ def task_jupyter(): # Open the browser automatically webbrowser.open('http://%s:55910/tree' % host, new=2) - print("Notebook URL: http://%s:55910/tree\n" % host) - print("Use CTRL+C to stop the server.") + LOGGER.info("Notebook URL: http://%s:55910/tree\n", host) + LOGGER.info("Use CTRL+C to stop the server.") try: process.wait() except KeyboardInterrupt: pass finally: - print("Closing server...") + LOGGER.info("Closing server...") process = subprocess.Popen( [ 'docker',