Skip to content

Instantly share code, notes, and snippets.

@pyadav
Forked from eliasdorneles/ckpypackage_manage.py
Created March 15, 2020 08:26
Show Gist options
  • Save pyadav/6ca813ae1d074d2e1f3802929d9a5b61 to your computer and use it in GitHub Desktop.
Save pyadav/6ca813ae1d074d2e1f3802929d9a5b61 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Cookiecutter PyPackage development tasks
"""
# To add a task, create a function with name starting with 'do_' that
# receives one argument (the parsed cmdline arguments object).
# Use a short docstring to serve as help.
#
# Example:
#
# def do_clean(args):
# run('rm -rf build/')
from __future__ import print_function
import argparse
import inspect
import shlex
import subprocess
import sys
def run(cmd):
return subprocess.check_output(shlex.split(cmd))
def do_help(args):
"print this help"
for name, func in sorted(TASKS.items()):
print('%-20s %s' % (name, func.__doc__))
def do_bake(args):
"generate project using defaults"
run('cookiecutter --no-input . --overwrite-if-exists')
def find_tasks(module):
"""Find all tasks in given module.
Tasks are just functions whose names start with 'do_'"""
return {
name[3:]: func
for name, func in inspect.getmembers(module)
if name.startswith('do_')
}
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('task', nargs='?',
default='help',
choices=tuple(TASKS),
help='Which task to run')
args = parser.parse_args()
# run task
TASKS[args.task](args)
TASKS = find_tasks(sys.modules[__name__])
if '__main__' == __name__:
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment