Skip to content

Instantly share code, notes, and snippets.

@cyberbikepunk
Created Jun 26, 2016
Embed
What would you like to do?
Get command line scripts from setup.py
#! /usr/bin/env python
"""The project dommand line interface for developers.
"""
from __future__ import (absolute_import,
division,
print_function,
unicode_literals)
from io import open
from os.path import join, dirname
from json import loads
from argparse import ArgumentParser
from subprocess import call
def get_scripts():
filepath = join(dirname(__file__), 'package.json')
with open(filepath, encoding='utf-8') as file:
package = loads(file.read())
return package['scripts']
scripts = get_scripts()
def build_parser():
parser = ArgumentParser(prog='python run.py',
description=__doc__,
epilog='See package.json')
parser.add_argument('script', choices=scripts.keys())
return parser
if __name__ == '__main__':
choice = build_parser().parse_args().script
command = scripts[choice]
print('{script} running {command}'.format(script=choice, command=command))
exit(call(command, shell=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment