Last active
August 29, 2015 14:01
-
-
Save kpantic/d90db4760c02924984c1 to your computer and use it in GitHub Desktop.
Snippet for adding PEP8 and JSHint validation to your Fabric fabfile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fabric.api import (task, local, lcd) | |
""" | |
The pep8 and jshint tasks return False if errors were found and True if found. | |
The show_errors parameter controls if the method prints out the errors returned by | |
the checker program. | |
Requirements: Install pep8 and jshint, so that they can be run from the command line | |
- pip install pep8 | |
- npm -g install jshint | |
""" | |
@task | |
def pep8(show_errors=False): | |
with(lcd(os.path.join(os.path.dirname(__file__), APP_DIR))): | |
return handle_error_checking_cmd( | |
"find . -name '*.py' -not -iwholename " | |
"'*migrations*' -exec pep8 {} \;", | |
show_errors, | |
"PEP8" | |
) | |
@task | |
def jshint(show_errors=False): | |
with(nested(lcd(os.path.join(os.path.dirname(__file__), STATIC_JS_DIR)), | |
settings(warn_only=True))): | |
return handle_error_checking_cmd( | |
"jshint . | grep ': line *'", | |
show_errors, | |
"JSHint" | |
) | |
# Helper function to avoid repetition | |
def handle_error_checking_cmd(cmd, show_errors, error_name=''): | |
errors = local(cmd, capture=True) | |
error_list = errors.splitlines() | |
error_count = len(error_list) | |
if show_errors: | |
print(errors) | |
if error_count > 0: | |
print("You have %s %s errors" % (error_count, error_name)) | |
return False | |
else: | |
print("You have no %s errors :D" % (error_name, )) | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I assume we're to replace STATIC_JS_DIR with a target to validate, right?