Skip to content

Instantly share code, notes, and snippets.

@cyberbikepunk
Created June 26, 2016 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberbikepunk/b543429be9f83bc83ce67a6be799939a to your computer and use it in GitHub Desktop.
Save cyberbikepunk/b543429be9f83bc83ce67a6be799939a to your computer and use it in GitHub Desktop.
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