Skip to content

Commit

Permalink
Merge pull request #209 from zacbrannelly/enhance/custom-checkers
Browse files Browse the repository at this point in the history
ENHANCE: Add custom check for print statements
  • Loading branch information
ucokzeko authored Nov 19, 2019
2 parents 1d7e508 + 6c65ee4 commit 7ee804a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
14 changes: 13 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@
author='Scott Barnett',
author_email='[email protected]',
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': [
Expand Down
Empty file added surround/checkers/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions surround/checkers/surround_checker.py
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 2 additions & 0 deletions surround/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 7 additions & 5 deletions templates/new/dodo.py.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import sys
import subprocess
import re
import webbrowser
import logging

from pathlib import Path

Expand All @@ -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 = [
{{
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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',
Expand Down
12 changes: 7 additions & 5 deletions templates/new/web_dodo.py.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import sys
import subprocess
import re
import webbrowser
import logging

from pathlib import Path

Expand All @@ -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 = [
{{
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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',
Expand Down

0 comments on commit 7ee804a

Please sign in to comment.