Mercurial > hg > MakeItSo
view makeitso/script2package.py @ 174:aed8c4af5f26
STUB: makeitso/cli.py makeitso/script2package.py setup.py
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Thu, 16 Jan 2014 13:31:54 -0800 |
parents | 6cd2894bb11c |
children | 5fa35ff86644 |
line wrap: on
line source
#!/usr/bin/env python # -*- coding: utf-8 -*- """ make a package from a .py file """ ### STUB ### # TODO: # - thing to make a setup.py from a .py file # - use makeitso templates -> directory structure import optparse import os import subprocess import sys from .python import PythonModuleTemplate, PythonPackageTemplate def add_options(parser): """add options to the OptionParser instance""" # TODO: replace with `configuration` package parser.add_option('-m', '--module', dest='py_module', action='store_true', default=False, help="create a single-module package with py_modules in setup.py") parser.add_option('-n', '--name', dest='name', help="Name of package; default taken from script name") parser.add_option('-o', '--output', dest='output', help="where to output the resulting package [DEFAULT: '.']") def main(args=sys.argv[1:]): # parse command line options usage = '%prog [options] script.py' class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): """description formatter for console script entry point""" def format_description(self, description): if description: return description.strip() + '\n' else: return '' parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) add_options(parser) options, args = parser.parse_args(args) if len(args) != 1: parser.error("Please specify a source script") # configure template template = PythonModuleTemplate if options.py_module else PythonPackageTemplate # interpolate template # TODO if __name__ == '__main__': main()