Last active
February 22, 2018 13:58
-
-
Save dylanbstorey/327af47245dc1fb027f790a57944e072 to your computer and use it in GitHub Desktop.
Doit tasks so i don't have to remember commands for software development.
This file contains 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
import os | |
import fnmatch | |
import glob | |
import shutil | |
package = os.path.basename(os.path.dirname(__file__)) | |
def task_docs(): | |
""" | |
Build our documentation | |
:return: | |
""" | |
return{ | |
'actions' : ['sphinx-apidoc -fMTeE -o docs/source {0}/ && cd docs && make clean && make html'.format(package)] , | |
} | |
def task_doc_coverage(): | |
""" | |
Find out what documentation we need to get finished | |
:return: | |
""" | |
os.environ['SPHINX_APIDOC_OPTIONS']='members' | |
return { | |
'actions' : ['sphinx-apidoc -fMTeE -o docs/source {0}/ && cd docs && make coverage && cat build/coverage/python.txt >&2'.format(package)] , | |
} | |
def task_coverage(): | |
""" | |
Generate a code coverage report | |
:return: | |
""" | |
return { | |
'actions' : [ 'nosetests --logging-level=FATAL --with-coverage --cover-package {0} --cover-html --cover-erase '.format(package)] | |
} | |
def task_test(): | |
""" | |
Just run tests | |
:return: | |
""" | |
return { | |
'actions' : ['nosetests -sv --logging-level=DEBUG --with-coverage --cover-package {0} --cover-erase'.format(package)] | |
} | |
def task_loc(): | |
""" | |
Get current LOC in project | |
:return:git | |
""" | |
def walk(root='.', recurse=True, pattern='*'): | |
""" | |
Generator for walking a directory tree. | |
Starts at specified root folder, returning files | |
that match our pattern. Optionally will also | |
recurse through sub-folders. | |
""" | |
for path, subdirs, files in os.walk(root): | |
for name in files: | |
if fnmatch.fnmatch(name, pattern): | |
yield os.path.join(path, name) | |
if not recurse: | |
break | |
def loc(root='', recurse=True): | |
""" | |
Counts lines of code in two ways: | |
maximal size (source LOC) with blank lines and comments | |
minimal size (logical LOC) stripping same | |
Sums all Python files in the specified folder. | |
By default recurses through subfolders. | |
""" | |
count_mini, count_maxi = 0, 0 | |
for fspec in walk(root, recurse, '*.py'): | |
skip = False | |
for line in open(fspec).readlines(): | |
count_maxi += 1 | |
line = line.strip() | |
if line: | |
if line.startswith('#'): | |
continue | |
if line.startswith('"""'): | |
skip = not skip | |
continue | |
if not skip: | |
count_mini += 1 | |
return "\'Lines of Code: {0} \nTotal Lines: {1}\'".format(count_mini, count_maxi) | |
return { | |
'actions' : ['echo %s >&2 ' % loc('.')], | |
} | |
def task_mypy(): | |
""" | |
Run mypy | |
:return: | |
""" | |
return { | |
'actions' : [ 'mypy --ignore-missing-imports {0}'.format(package)] | |
} | |
def task_clean_up(): | |
""" | |
Delete files that aren't needed and definately shouldn't be checked into a repo or hed around any way. | |
:return: | |
""" | |
rm_dirs = ['.mypy_cache','cover'] | |
rm_files = ['.coverage','test_broker.sqlite3'] | |
[ rm_dirs.append(f) for f in glob.glob('**', recursive=True) if os.path.basename(f) == '__pycache__' ] | |
[ rm_files.append(f) for f in glob.glob('docs/source/*.rst',recursive=True) if package in f ] | |
rm_dirs = [d for d in rm_dirs if os.path.isdir(d)] | |
rm_files =[f for f in rm_files if os.path.exists(f)] | |
[os.unlink(f) for f in rm_files] + [shutil.rmtree(d) for d in rm_dirs] | |
return { | |
'actions' : ['echo clean'] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment