diff --git a/.gitignore b/.gitignore index 8154844..b0080ea 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.egg-info /build/ /dist/ +.* \ No newline at end of file diff --git a/fabfile.py b/fabfile.py index bed5cac..2e439f5 100644 --- a/fabfile.py +++ b/fabfile.py @@ -1,7 +1,5 @@ -from fabpolish import polish, update_sniff -from fabpolish.contrib import ( - find_merge_conflict_leftovers, - find_pep8_violations -) +""" This is a testing file. """ +from fabpolish import update_sniff +from fabpolish.contrib import find_pep8_violations update_sniff(find_pep8_violations, severity='major', timing='fast') diff --git a/fabpolish/__init__.py b/fabpolish/__init__.py index 0db4425..e5c5478 100644 --- a/fabpolish/__init__.py +++ b/fabpolish/__init__.py @@ -1,3 +1,4 @@ +"""init for package import.""" import os import sys @@ -15,6 +16,7 @@ def info(text): + """Get information about input.""" puts(green(text)) @@ -34,14 +36,16 @@ def validate_timing(timing): def sniff(*args, **kwargs): - """ Decorator to collect sniffs and execute on polish - :param severity: Keyword argument only. - One of 'critical', 'major', 'minor', 'info' - Default: 'critical' - :type severity: str - :param timing: Keyword argument only. One of 'slow', 'fast' - Default: 'fast' - :type timing: str + """ + Decorate to collect sniffs and execute on polish. + + :param severity: Keyword argument only. + One of 'critical', 'major', 'minor', 'info' + Default: 'critical' + :type severity: str + :param timing: Keyword argument only. One of 'slow', 'fast' + Default: 'fast' + :type timing: str """ DEFAULT_SEVERITY = 'critical' DEFAULT_TIMING = 'fast' @@ -68,7 +72,9 @@ def wrapper(*args, **kwargs): @task def polish(env='dev'): - """Polish code by running some or all sniffs + """ + Polish code by running some or all sniffs. + :param env: Environment to determine what all sniffs to run Options: 'dev', 'ci' Default: 'dev' @@ -78,23 +84,27 @@ def polish(env='dev'): When environment is 'dev', only fast-critical and fast-major sniffs are run. """ + def check(sniff): + """ + Check function name in frabic_tasks and not fast also note + severity critical or major. + """ + return sniff['function'].name not in fabric_tasks or \ + sniff['timing'] != 'fast' or \ + sniff['severity'] not in ('critical', 'major') + fabric_tasks = list_commands('', 'short') results = list() with settings(warn_only=True): + sniffs_to_run = [] if env == 'ci': - sniffs_to_run = [] - for sniff in _sniffs: - if sniff['function'].name not in fabric_tasks: - continue + for sniff in filter( + lambda each: each['function'].name in fabric_tasks, _sniffs + ): sniffs_to_run.append(sniff) elif env == 'dev': - sniffs_to_run = [] for sniff in _sniffs: - if sniff['function'].name not in fabric_tasks: - continue - if sniff['timing'] != 'fast': - continue - if sniff['severity'] not in ('critical', 'major'): + if check(sniff): continue sniffs_to_run.append(sniff) else: @@ -107,10 +117,12 @@ def polish(env='dev'): def update_sniff(function, severity=None, timing=None): - if type(function) == str: + """Update sniff dict.""" + if isinstance(function, str): function_name = function else: function_name = function.name + sniff = {} for sniff in _sniffs: if sniff['function'].name == function_name: break diff --git a/fabpolish/contrib.py b/fabpolish/contrib.py index 2c428a2..0e1b57e 100644 --- a/fabpolish/contrib.py +++ b/fabpolish/contrib.py @@ -1,33 +1,32 @@ +"""checks on various features.""" from fabpolish import sniff, info, local @sniff(severity='critical', timing='fast') def find_merge_conflict_leftovers(): - """Find Merge conflict leftovers - """ + """Find Merge conflict leftovers.""" info('Finding merge conflict leftovers...') return local("! git grep -P '^(<|=|>){7}(?![<=>])'") @sniff(severity='major', timing='slow') def find_php_syntax_errors(): - """Find syntax error in php files - """ + """Find syntax error in php files.""" info('Finding syntax error in php files...') return local( "git ls-files -z | " - "grep -PZz '\.(php|phtml)$' | " + "grep -PZz '\\.(php|phtml)$' | " "xargs -0 -n 1 php -l >/tmp/debug" ) @sniff(severity='major', timing='fast') def python_code_analyzer(): - """Running static code analyzer""" + """Run static code analyzer.""" info('Running static code analyzer') return local( "git ls-files -z | " - "grep -PZz '\.py$' | " + "grep -PZz '\\.py$' | " "grep -PZvz 'fabfile.py' | " "xargs -0 pyflakes" ) @@ -35,44 +34,44 @@ def python_code_analyzer(): @sniff(severity='minor', timing='slow') def find_pep8_violations(): - """Run pep8 python coding standard check - """ + """Run pep8 python coding standard check.""" info('Running coding standards check for python files...') return local( "git ls-files -z | " - "grep -PZz '\.py$' | " + "grep -PZz '\\.py$' | " "xargs -0 pep8" ) @sniff(severity='major', timing='fast') def fix_file_permission(): - """Fixing permissions for files""" + """Fix permissions for files.""" info('Fixing permissions for files') return local( "git ls-files -z | " - "grep -PvZz '\.sh$' | " + "grep -PvZz '\\.sh$' | " "xargs -0 chmod -c 0664 > /dev/null 2>&1" ) @sniff(severity='major', timing='fast') def fix_script_permission(): - # Fix script permissions + """Fix script permissions.""" info('Fixing script permissions...') return local( "git ls-files -z | " - "grep -PZz '\.sh$' | " + "grep -PZz '\\.sh$' | " "xargs -0 -r chmod 0775 >/dev/null 2>&1" ) @sniff(severity='major', timing='fast') def fix_white_space(): + """Fix White spaces.""" info('Fixing whitespace errors...') return local( "git ls-files -z | " - "grep -PZvz '\.(ico|jpg|png|gif|eot|ttf|woff|wav|xlxs)$' | " + "grep -PZvz '\\.(ico|jpg|png|gif|eot|ttf|woff|wav|xlxs)$' | " "xargs -0 grep -PlZn '(\\s+$)|(\\t)' | " "tee /dev/stderr | " "xargs -0 -r sed -i -e 's/\\s\\+$//' " @@ -81,10 +80,11 @@ def fix_white_space(): @sniff(severity='major', timing='fast') def convert_tab_spaces(): + """Convert all tabe to spaces.""" info('Converting tab to spaces...') return local( "git ls-files -z | " - "grep -PZvz '\.(ico|jpg|png|gif|eot|ttf|woff|wav|xlxs)$' | " + "grep -PZvz '\\.(ico|jpg|png|gif|eot|ttf|woff|wav|xlxs)$' | " "xargs -0 grep -PlZn '(\\s+$)|(\\t)' | " "tee /dev/stderr | " "xargs -0 -r sed -i -e 's/\\t/ /g' " @@ -93,19 +93,19 @@ def convert_tab_spaces(): @sniff(severity='critical', timing='fast') def check_migration_branch(): - """Checking migration branches""" + """Check migration branches.""" info('Checking migration branches...') return local("! alembic branches | grep branchpoint") @sniff(severity='major', timing='fast') def check_python_debug_info(): - """Check and remove debugging print statements""" + """Check and remove debugging print statements.""" info('Checking for debug print statements') return local( "! git ls-files -z | " "grep -PZvz 'fabfile.py' | " - "grep -PZz \.py$ | " + "grep -PZz \\.py$ | " "xargs -0 grep -Pn \'(?>> )print\' | " "grep -v NOCHECK" ) @@ -113,6 +113,7 @@ def check_python_debug_info(): @sniff(severity='major', timing='fast') def check_php_debug_info(): + """Check for var echo or dump in php scripts.""" info('Checking for var_dump, echo or die statements...') return local( "! find ./src -name '*.php' -print0 | " @@ -122,6 +123,7 @@ def check_php_debug_info(): @sniff(severity='major', timing='fast') def check_image_edited(): + """Avoide Browser cashing during image update.""" # Check if image files have been edited info('Checking if image files have been edited...') info('Explanation: A new image should be created when ' @@ -130,28 +132,31 @@ def check_image_edited(): return local( '! git diff master...' + branch + ' --name-only --diff-filter=M | ' + - 'grep ".gif\|.png\|.jpg"' + 'grep ".gif\\|.png\\|.jpg"' ) @sniff(severity='critical', timing='fast') def composer_validate(): + """Run composer validate.""" info('Running composer validate...') return local('composer validate') @sniff(severity='major', timing='fast') def run_eslint(): + """Run ESLint.""" info('Running ESLint...') return local( "git ls-files | " - "grep '\.js$' | " + "grep '\\.js$' | " "xargs ./node_modules/eslint/bin/eslint.js" ) @sniff(severity='major', timing='fast') def check_preg_replace(): + """Use of preg_replace checks.""" info('Checking use of preg_replace...') return local( "! find src -name '*.php' -print0 | " diff --git a/setup.py b/setup.py index 4dbddd7..8d70077 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +"""This is setup.py. Ment for installation of package.""" from setuptools import setup setup(name='fab-polish',