def plugin_build_docs(options): """A command line script (plugin build_docs) points to this. It builds the Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed. usage: plugin build_docs [dist_dir_path] """ if options.dist_dir_path is None: options.dist_dir_path = os.getcwd() destdir = os.path.abspath(os.path.expandvars(os.path.expanduser(options.dist_dir_path))) _verify_dist_dir(destdir) cfgfile = os.path.join(destdir, 'setup.cfg') cfg = SafeConfigParser(dict_type=OrderedDict) cfg.readfp(open(cfgfile, 'r'), cfgfile) cfg.set('metadata', 'entry_points', _get_entry_points(os.path.join(destdir,'src'))) template_options = _get_template_options(destdir, cfg) dirstruct = { 'docs': { 'conf.py': _templates['conf.py'] % template_options, 'pkgdocs.rst': _get_pkgdocs(cfg), 'srcdocs.rst': _get_srcdocs(destdir, template_options['name']), }, } build_directory(dirstruct, force=True, topdir=destdir) _plugin_build_docs(destdir, cfg)
def plugin_build_docs(options): """A command line script (plugin build_docs) points to this. It builds the Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed. usage: plugin build_docs [dist_dir_path] """ if options.dist_dir_path is None: options.dist_dir_path = os.getcwd() destdir = os.path.abspath( os.path.expandvars(os.path.expanduser(options.dist_dir_path))) _verify_dist_dir(destdir) cfgfile = os.path.join(destdir, 'setup.cfg') cfg = SafeConfigParser(dict_type=OrderedDict) cfg.readfp(open(cfgfile, 'r'), cfgfile) cfg.set('metadata', 'entry_points', _get_entry_points(os.path.join(destdir, 'src'))) template_options = _get_template_options(destdir, cfg) dirstruct = { 'docs': { 'conf.py': _templates['conf.py'] % template_options, 'pkgdocs.rst': _get_pkgdocs(cfg), 'srcdocs.rst': _get_srcdocs(destdir, template_options['name']), }, } build_directory(dirstruct, force=True, topdir=destdir) _plugin_build_docs(destdir, cfg)
def plugin_makedist(parser, options, args=None): """A command line script (plugin makedist) points to this. It creates a source distribution containing Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed. usage: plugin makedist [dist_dir_path] """ if args: print_sub_help(parser, "makedist") return -1 options.dist_dir_path = os.path.abspath(os.path.expandvars(os.path.expanduser(options.dist_dir_path))) _verify_dist_dir(options.dist_dir_path) startdir = os.getcwd() os.chdir(options.dist_dir_path) try: plugin_build_docs(parser, options) cfg = SafeConfigParser(dict_type=OrderedDict) cfg.readfp(open("setup.cfg", "r"), "setup.cfg") print "collecting entry point information..." cfg.set("metadata", "entry_points", _get_entry_points("src")) template_options = _get_template_options(options.dist_dir_path, cfg, packages=find_packages("src")) dirstruct = {"setup.py": _templates["setup.py"] % template_options} name = cfg.get("metadata", "name") version = cfg.get("metadata", "version") if sys.platform == "win32": disttar = "%s-%s.zip" % (name, version) else: disttar = "%s-%s.tar.gz" % (name, version) disttarpath = os.path.join(startdir, disttar) if os.path.exists(disttarpath): sys.stderr.write("ERROR: distribution %s already exists.\n" % disttarpath) sys.exit(-1) build_directory(dirstruct, force=True) cmdargs = [sys.executable, "setup.py", "sdist", "-d", startdir] retcode = call(cmdargs) if retcode: cmd = " ".join(cmdargs) sys.stderr.write("\nERROR: command '%s' returned error code: %s\n" % (cmd, retcode)) finally: os.chdir(startdir) if os.path.exists(disttar): print "Created distribution %s" % disttar else: sys.stderr.write("\nERROR: failed to make distribution %s" % disttar)
def plugin_makedist(options): """A command line script (plugin makedist) points to this. It creates a source distribution containing Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed. usage: plugin makedist [dist_dir_path] """ options.dist_dir_path = os.path.abspath(os.path.expandvars(os.path.expanduser(options.dist_dir_path))) _verify_dist_dir(options.dist_dir_path) startdir = os.getcwd() os.chdir(options.dist_dir_path) try: plugin_build_docs(options) cfg = SafeConfigParser(dict_type=OrderedDict) cfg.readfp(open('setup.cfg', 'r'), 'setup.cfg') print "collecting entry point information..." cfg.set('metadata', 'entry_points', _get_entry_points('src')) template_options = _get_template_options(options.dist_dir_path, cfg, packages=find_packages('src')) dirstruct = { 'setup.py': _templates['setup.py'] % template_options, } name = cfg.get('metadata', 'name') version = cfg.get('metadata', 'version') if sys.platform == 'win32': disttar = "%s-%s.zip" % (name, version) else: disttar = "%s-%s.tar.gz" % (name, version) disttarpath = os.path.join(startdir, disttar) if os.path.exists(disttarpath): sys.stderr.write("ERROR: distribution %s already exists.\n" % disttarpath) sys.exit(-1) build_directory(dirstruct, force=True) cmdargs = [sys.executable, 'setup.py', 'sdist', '-d', startdir] retcode = call(cmdargs) if retcode: cmd = ' '.join(cmdargs) sys.stderr.write("\nERROR: command '%s' returned error code: %s\n" % (cmd,retcode)) finally: os.chdir(startdir) if os.path.exists(disttar): print "Created distribution %s" % disttar else: sys.stderr.write("\nERROR: failed to make distribution %s" % disttar)
def test_importing(self): projdirname = 'myproj.projdir' dirstruct = { os.path.splitext(projdirname)[0]: { 'top.py': """ from openmdao.main.api import Component class MyClass(Component): pass """, 'pkgdir': { '__init__.py': '', 'pkgfile.py': 'from openmdao.main.api import Component, Assembly', 'pkgdir2': { '__init__.py': '', 'pkgfile2.py': """ from openmdao.main.api import Component class PkgClass2(Component): def __init__(self, somearg=8, anotherarg=False): super(PkgClass2, self).__init__() """, } }, 'plaindir': { 'plainfile.py': """ from pkgdir.pkgdir2.pkgfile2 import PkgClass2 p = PkgClass2() """, }, }, } build_directory(dirstruct, topdir=os.getcwd()) try: sys.path_hooks = [ProjFinder] + sys.path_hooks sys.path = [os.path.join(os.getcwd(), projdirname)] + sys.path __import__('top') __import__('pkgdir.pkgfile') __import__('pkgdir.pkgdir2.pkgfile2') mod = sys.modules['pkgdir.pkgdir2.pkgfile2'] expected_classname = 'pkgdir.pkgdir2.pkgfile2.PkgClass2' matches = _match_insts([expected_classname]) self.assertEqual(matches, set()) sig = get_signature('pkgdir.pkgdir2.pkgfile2.PkgClass2') self.assertEqual(sig['args'], [['somearg', '8'], ['anotherarg', 'False']]) inst = getattr(mod, 'PkgClass2')() # create an inst of PkgClass2 matches = _match_insts([expected_classname]) self.assertEqual(matches, set([expected_classname])) finally: sys.path = sys.path[1:]
def setUp(self): self.tdir = tempfile.mkdtemp() build_directory(_dstruct, topdir=self.tdir) try: sys.path = [self.tdir] + sys.path if 'mydrv' in sys.modules: reload(sys.modules['mydrv'] ) # in case mydrv was already imported in earlier test finally: sys.path = sys.path[1:]
def plugin_build_docs(parser, options, args=None): """A command-line script (plugin build_docs) points to this. It builds the Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed. usage: plugin build_docs [dist_dir_path] """ if args is not None and len(args) > 1: print_sub_help(parser, 'build_docs') return -1 if args: dist_dir = args[0] else: dist_dir = '.' dist_dir = os.path.abspath(os.path.expandvars( os.path.expanduser(dist_dir))) _verify_dist_dir(dist_dir) #pfiles = fnmatch.filter(os.listdir(options.srcdir), '*.py') #if not pfiles: # options.srcdir = dist_dir cfgfile = os.path.join(dist_dir, 'setup.cfg') cfg = SafeConfigParser(dict_type=OrderedDict) cfg.readfp(open(cfgfile, 'r'), cfgfile) cfg.set('metadata', 'entry_points', _get_entry_points(os.path.join(dist_dir, options.srcdir))) templates, class_templates, test_template = _load_templates() template_options = _get_template_options(dist_dir, cfg, srcdir=options.srcdir) dirstruct = { 'docs': { 'conf.py': templates['conf.py'] % template_options, 'pkgdocs.rst': _get_pkgdocs(cfg), 'srcdocs.rst': _get_srcdocs(dist_dir, template_options['name'], srcdir=options.srcdir), }, } build_directory(dirstruct, force=True, topdir=dist_dir) _plugin_build_docs(dist_dir, cfg, src=options.srcdir) return 0
def test_importing(self): projdirname = 'myproj.projdir' dirstruct = { os.path.splitext(projdirname)[0]: { 'top.py': """ from openmdao.main.api import Component class MyClass(Component): pass """, 'pkgdir': { '__init__.py': '', 'pkgfile.py': 'from openmdao.main.api import Component, Assembly', 'pkgdir2': { '__init__.py': '', 'pkgfile2.py': """ from openmdao.main.api import Component class PkgClass2(Component): def __init__(self, somearg=8, anotherarg=False): super(PkgClass2, self).__init__() """, } }, 'plaindir': { 'plainfile.py': """ from pkgdir.pkgdir2.pkgfile2 import PkgClass2 p = PkgClass2() """, }, }, } build_directory(dirstruct, topdir=os.getcwd()) try: sys.path_hooks = [ProjFinder]+sys.path_hooks sys.path = [os.path.join(os.getcwd(), projdirname)]+sys.path __import__('top') __import__('pkgdir.pkgfile') __import__('pkgdir.pkgdir2.pkgfile2') mod = sys.modules['pkgdir.pkgdir2.pkgfile2'] expected_classname = 'pkgdir.pkgdir2.pkgfile2.PkgClass2' matches = _match_insts([expected_classname]) self.assertEqual(matches, set()) sig = get_signature('pkgdir.pkgdir2.pkgfile2.PkgClass2') self.assertEqual(sig['args'], [['somearg', '8'], ['anotherarg', 'False']]) inst = getattr(mod, 'PkgClass2')() # create an inst of PkgClass2 matches = _match_insts([expected_classname]) self.assertEqual(matches, set([expected_classname])) finally: sys.path = sys.path[1:]
def plugin_build_docs(parser, options, args=None): """A command-line script (plugin build_docs) points to this. It builds the Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed. usage: plugin build_docs [dist_dir_path] """ if args is not None and len(args) > 1: print_sub_help(parser, 'build_docs') return -1 if args: dist_dir = args[0] else: dist_dir = '.' dist_dir = os.path.abspath(os.path.expandvars(os.path.expanduser(dist_dir))) _verify_dist_dir(dist_dir) #pfiles = fnmatch.filter(os.listdir(options.srcdir), '*.py') #if not pfiles: # options.srcdir = dist_dir cfgfile = os.path.join(dist_dir, 'setup.cfg') cfg = SafeConfigParser(dict_type=OrderedDict) cfg.readfp(open(cfgfile, 'r'), cfgfile) cfg.set('metadata', 'entry_points', _get_entry_points(os.path.join(dist_dir, options.srcdir))) templates, class_templates, test_template = _load_templates() template_options = _get_template_options(dist_dir, cfg, srcdir=options.srcdir) dirstruct = { 'docs': { 'conf.py': templates['conf.py'] % template_options, 'pkgdocs.rst': _get_pkgdocs(cfg), 'srcdocs.rst': _get_srcdocs(dist_dir, template_options['name'], srcdir=options.srcdir), }, } build_directory(dirstruct, force=True, topdir=dist_dir) _plugin_build_docs(dist_dir, cfg, src=options.srcdir) return 0
def _build_project(topdir): dirstruct = { 'myclass.py': """ from openmdao.main.api import Component from openmdao.main.datatypes.api import Float class MyClass(Component): x = Float(0.0, iotype='in') y = Float(0.0, iotype='out') """, '_macros': { 'default': """ top = set_as_top(create('openmdao.main.assembly.Assembly')) top.add("P1",create("myclass.MyClass")) top.add("P2",create("myclass.MyClass")) top.connect("P1.y","P2.x") """ } } build_directory(dirstruct, topdir=topdir)
def plugin_build_docs(parser, options, args=None): """A command line script (plugin build_docs) points to this. It builds the Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed. usage: plugin build_docs [dist_dir_path] """ if args: print_sub_help(parser, "build_docs") return -1 if options.dist_dir_path is None: options.dist_dir_path = os.getcwd() destdir = os.path.abspath(os.path.expandvars(os.path.expanduser(options.dist_dir_path))) _verify_dist_dir(destdir) cfgfile = os.path.join(destdir, "setup.cfg") cfg = SafeConfigParser(dict_type=OrderedDict) cfg.readfp(open(cfgfile, "r"), cfgfile) cfg.set("metadata", "entry_points", _get_entry_points(os.path.join(destdir, "src"))) template_options = _get_template_options(destdir, cfg) dirstruct = { "docs": { "conf.py": _templates["conf.py"] % template_options, "pkgdocs.rst": _get_pkgdocs(cfg), "srcdocs.rst": _get_srcdocs(destdir, template_options["name"]), } } build_directory(dirstruct, force=True, topdir=destdir) _plugin_build_docs(destdir, cfg)
def plugin_quickstart(parser, options, args=None): """A command line script (plugin quickstart) points to this. It generates a directory structure for an openmdao plugin package along with Sphinx docs. usage: plugin quickstart <dist_name> [-v <version>] [-d <dest_dir>] [-g <plugin_group>] [-c class_name] """ if args: print_sub_help(parser, 'quickstart') return -1 name = options.dist_name if options.classname: classname = options.classname else: classname = "%s%s" % ((name.upper())[0], name[1:]) version = options.version options.dest = os.path.abspath( os.path.expandvars(os.path.expanduser(options.dest))) if not options.group.startswith('openmdao.'): options.group = 'openmdao.' + options.group templates, class_templates, test_template = _load_templates() startdir = os.getcwd() try: os.chdir(options.dest) if os.path.exists(name): raise OSError("Can't create directory '%s' because it already" " exists." % os.path.join(options.dest, name)) cfg = SafeConfigParser(dict_type=OrderedDict) stream = StringIO.StringIO(templates['setup.cfg'] % { 'name': name, 'version': version }) cfg.readfp(stream, 'setup.cfg') cfgcontents = StringIO.StringIO() cfg.write(cfgcontents) template_options = \ _get_template_options(os.path.join(options.dest, name), cfg, classname=classname) template_options['srcmod'] = name dirstruct = { name: { 'setup.py': templates['setup.py'] % template_options, 'setup.cfg': cfgcontents.getvalue(), 'MANIFEST.in': templates['MANIFEST.in'] % template_options, 'README.txt': templates['README.txt'] % template_options, 'src': { name: { '__init__.py': '', #'from %s import %s\n' % (name,classname), '%s.py' % name: class_templates[options.group] % template_options, 'test': { 'test_%s.py' % name: test_template % template_options }, }, }, 'docs': { 'conf.py': templates['conf.py'] % template_options, 'index.rst': templates['index.rst'] % template_options, 'srcdocs.rst': _get_srcdocs(options.dest, name), 'pkgdocs.rst': _get_pkgdocs(cfg), 'usage.rst': templates['usage.rst'] % template_options, }, }, } build_directory(dirstruct) finally: os.chdir(startdir) return 0
def plugin_makedist(parser, options, args=None, capture=None): """A command line script (plugin makedist) points to this. It creates a source distribution containing Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed. usage: plugin makedist [dist_dir_path] """ if args is not None and len(args) > 1: print_sub_help(parser, 'makedist') return -1 if args: dist_dir = args[0] else: dist_dir = '.' dist_dir = os.path.abspath(os.path.expandvars( os.path.expanduser(dist_dir))) _verify_dist_dir(dist_dir) startdir = os.getcwd() os.chdir(dist_dir) templates, class_templates, test_template = _load_templates() try: plugin_build_docs(parser, options) cfg = SafeConfigParser(dict_type=OrderedDict) cfg.readfp(open('setup.cfg', 'r'), 'setup.cfg') print "collecting entry point information..." cfg.set('metadata', 'entry_points', _get_entry_points('src')) template_options = _get_template_options(options.dist_dir_path, cfg, packages=find_packages('src')) dirstruct = { 'setup.py': templates['setup.py'] % template_options, } name = cfg.get('metadata', 'name') version = cfg.get('metadata', 'version') if sys.platform == 'win32': # pragma no cover disttar = "%s-%s.zip" % (name, version) else: disttar = "%s-%s.tar.gz" % (name, version) disttarpath = os.path.join(startdir, disttar) if os.path.exists(disttarpath): sys.stderr.write("ERROR: distribution %s already exists.\n" % disttarpath) return -1 build_directory(dirstruct, force=True) cmdargs = [sys.executable, 'setup.py', 'sdist', '-d', startdir] if capture: stdout = open(capture, 'w') stderr = STDOUT else: # pragma no cover stdout = None stderr = None try: retcode = call(cmdargs, stdout=stdout, stderr=stderr) finally: if stdout is not None: stdout.close() if retcode: cmd = ' '.join(cmdargs) sys.stderr.write( "\nERROR: command '%s' returned error code: %s\n" % (cmd, retcode)) return retcode finally: os.chdir(startdir) if os.path.exists(disttar): print "Created distribution %s" % disttar return 0 else: sys.stderr.write("\nERROR: failed to make distribution %s" % disttar) return -1
def setUp(self): self.startdir = os.getcwd() self.tempdir = tempfile.mkdtemp() os.chdir(self.tempdir) build_directory(structure)
def plugin_makedist(options): """A command line script (plugin makedist) points to this. It creates a source distribution containing Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed. usage: plugin makedist [dist_dir_path] """ options.dist_dir_path = os.path.abspath( os.path.expandvars(os.path.expanduser(options.dist_dir_path))) _verify_dist_dir(options.dist_dir_path) startdir = os.getcwd() os.chdir(options.dist_dir_path) try: plugin_build_docs(options) cfg = SafeConfigParser(dict_type=OrderedDict) cfg.readfp(open('setup.cfg', 'r'), 'setup.cfg') print "collecting entry point information..." cfg.set('metadata', 'entry_points', _get_entry_points('src')) template_options = _get_template_options(options.dist_dir_path, cfg, packages=find_packages('src')) dirstruct = { 'setup.py': _templates['setup.py'] % template_options, } name = cfg.get('metadata', 'name') version = cfg.get('metadata', 'version') if sys.platform == 'win32': disttar = "%s-%s.zip" % (name, version) else: disttar = "%s-%s.tar.gz" % (name, version) disttarpath = os.path.join(startdir, disttar) if os.path.exists(disttarpath): sys.stderr.write("ERROR: distribution %s already exists.\n" % disttarpath) sys.exit(-1) build_directory(dirstruct, force=True) cmdargs = [sys.executable, 'setup.py', 'sdist', '-d', startdir] retcode = call(cmdargs) if retcode: cmd = ' '.join(cmdargs) sys.stderr.write( "\nERROR: command '%s' returned error code: %s\n" % (cmd, retcode)) finally: os.chdir(startdir) if os.path.exists(disttar): print "Created distribution %s" % disttar else: sys.stderr.write("\nERROR: failed to make distribution %s" % disttar)
def setUp(self): Publisher.silent = True self.tdir = tempfile.mkdtemp() build_directory(_dstruct, topdir=self.tdir)
def plugin_quickstart(parser, options, args=None): """A command line script (plugin quickstart) points to this. It generates a directory structure for an openmdao plugin package along with Sphinx docs. usage: plugin quickstart <dist_name> [-v <version>] [-d <dest_dir>] [-g <plugin_group>] [-c class_name] """ if args: print_sub_help(parser, 'quickstart') return -1 name = options.dist_name if options.classname: classname = options.classname else: classname = "%s%s" % ((name.upper())[0], name[1:]) version = options.version options.dest = os.path.abspath(os.path.expandvars(os.path.expanduser(options.dest))) if not options.group.startswith('openmdao.'): options.group = 'openmdao.'+options.group templates, class_templates, test_template = _load_templates() startdir = os.getcwd() try: os.chdir(options.dest) if os.path.exists(name): raise OSError("Can't create directory '%s' because it already" " exists." % os.path.join(options.dest, name)) cfg = SafeConfigParser(dict_type=OrderedDict) stream = StringIO.StringIO(templates['setup.cfg'] % { 'name':name, 'version':version }) cfg.readfp(stream, 'setup.cfg') cfgcontents = StringIO.StringIO() cfg.write(cfgcontents) template_options = \ _get_template_options(os.path.join(options.dest, name), cfg, classname=classname) template_options['srcmod'] = name dirstruct = { name: { 'setup.py': templates['setup.py'] % template_options, 'setup.cfg': cfgcontents.getvalue(), 'MANIFEST.in': templates['MANIFEST.in'] % template_options, 'README.txt': templates['README.txt'] % template_options, 'src': { name: { '__init__.py': '', #'from %s import %s\n' % (name,classname), '%s.py' % name: class_templates[options.group] % template_options, 'test': { 'test_%s.py' % name: test_template % template_options }, }, }, 'docs': { 'conf.py': templates['conf.py'] % template_options, 'index.rst': templates['index.rst'] % template_options, 'srcdocs.rst': _get_srcdocs(options.dest, name), 'pkgdocs.rst': _get_pkgdocs(cfg), 'usage.rst': templates['usage.rst'] % template_options, }, }, } build_directory(dirstruct) finally: os.chdir(startdir) return 0
def plugin_makedist(parser, options, args=None, capture=None): """A command line script (plugin makedist) points to this. It creates a source distribution containing Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed. usage: plugin makedist [dist_dir_path] """ if args is not None and len(args) > 1: print_sub_help(parser, 'makedist') return -1 if args: dist_dir = args[0] else: dist_dir = '.' dist_dir = os.path.abspath(os.path.expandvars(os.path.expanduser(dist_dir))) _verify_dist_dir(dist_dir) startdir = os.getcwd() os.chdir(dist_dir) templates, class_templates, test_template = _load_templates() try: plugin_build_docs(parser, options) cfg = SafeConfigParser(dict_type=OrderedDict) cfg.readfp(open('setup.cfg', 'r'), 'setup.cfg') print "collecting entry point information..." cfg.set('metadata', 'entry_points', _get_entry_points('src')) template_options = _get_template_options(options.dist_dir_path, cfg, packages=find_packages('src')) dirstruct = { 'setup.py': templates['setup.py'] % template_options, } name = cfg.get('metadata', 'name') version = cfg.get('metadata', 'version') if sys.platform == 'win32': # pragma no cover disttar = "%s-%s.zip" % (name, version) else: disttar = "%s-%s.tar.gz" % (name, version) disttarpath = os.path.join(startdir, disttar) if os.path.exists(disttarpath): sys.stderr.write("ERROR: distribution %s already exists.\n" % disttarpath) return -1 build_directory(dirstruct, force=True) cmdargs = [sys.executable, 'setup.py', 'sdist', '-d', startdir] if capture: stdout = open(capture, 'w') stderr = STDOUT else: # pragma no cover stdout = None stderr = None try: retcode = call(cmdargs, stdout=stdout, stderr=stderr) finally: if stdout is not None: stdout.close() if retcode: cmd = ' '.join(cmdargs) sys.stderr.write("\nERROR: command '%s' returned error code: %s\n" % (cmd, retcode)) return retcode finally: os.chdir(startdir) if os.path.exists(disttar): print "Created distribution %s" % disttar return 0 else: sys.stderr.write("\nERROR: failed to make distribution %s" % disttar) return -1
def mkpseudo(argv=None): """A command line script (mkpseudo) points to this. It generates a source distribution package that's empty aside from having a number of dependencies on other packages. usage: ``make_pseudopkg <pkg_name> <version> [-d <dest_dir>] [-l <links_url>] [-r req1] ... [-r req_n]`` If ``pkg_name`` contains dots, a namespace package will be built. Required dependencies are specified using the same notation used by ``setuptools/easy_install/distribute/pip``. .. note:: If your required dependencies use the "<" or ">" characters, you must put the entire requirement in quotes to avoid misinterpretation by the shell. """ if argv is None: argv = sys.argv[1:] parser = OptionParser() parser.usage = "mkpseudo <name> <version> [options]" parser.add_option( "-d", "--dest", action="store", type="string", dest="dest", default=".", help="directory where distribution will be created (optional)", ) parser.add_option( "-l", "--link", action="append", type="string", dest="deplinks", default=[], help="URLs to search for dependencies (optional)", ) parser.add_option( "-r", "--req", action="append", type="string", dest="reqs", default=[], help="requirement strings for dependent distributions (one or more)", ) parser.add_option( "", "--dist", action="store_true", dest="dist", help="make a source distribution after creating the directory structure", ) (options, args) = parser.parse_args(argv) if len(args) != 2: parser.print_help() sys.exit(-1) name = args[0] names = name.split(".") version = args[1] for i, url in enumerate(options.deplinks): if not url.startswith("http:") and not url.startswith("https:"): options.deplinks[i] = "http://%s" % url dest = os.path.abspath(os.path.expandvars(os.path.expanduser(options.dest))) if len(options.reqs) == 0 and options.dist: print "No dependencies have been specified, so the distribution will not be built" options.dist = False nspkgs = [] for i, nm in enumerate(names[:-1]): nspkgs.append(".".join(names[: i + 1])) dists = working_set.resolve([Requirement.parse(r) for r in options.reqs]) dset = set([("%s" % d).replace(" ", "==") for d in dists]) setup_options = { "requires": list(dset), "name": name, "version": version, "deplinks": options.deplinks, "nspkgs": nspkgs, } startdir = os.getcwd() if options.dist: tdir = tempfile.mkdtemp() else: tdir = dest try: os.chdir(tdir) rnames = names[::-1] for i, ns in enumerate(rnames): if i == 0: dct = {"__init__.py": ""} else: dct = {"__init__.py": _ns_template, rnames[i - 1]: dct} dct = {names[0]: dct} dirstruct = {name: {"setup.py": _setup_py_template % setup_options, "src": dct}} if not options.dist: if os.path.exists(name): print "'%s' already exists. aborting..." % name sys.exit(-1) build_directory(dirstruct) os.chdir(name) if options.dist: tarname = os.path.join(dest, "%s-%s.tar.gz" % (name, version)) zipname = os.path.join(dest, "%s-%s.zip" % (name, version)) for fname in [tarname, zipname]: if os.path.exists(fname): print "%s already exists" % fname sys.exit(-1) cmd = [sys.executable, "setup.py", "sdist", "-d", dest] subprocess.check_call(cmd) finally: os.chdir(startdir) if options.dist: shutil.rmtree(tdir, onerror=onerror)
def mkpseudo(argv=None): """A command line script (mkpseudo) points to this. It generates a source distribution package that's empty aside from having a number of dependencies on other packages. usage: ``make_pseudopkg <pkg_name> <version> [-d <dest_dir>] [-l <links_url>] [-r req1] ... [-r req_n]`` If ``pkg_name`` contains dots, a namespace package will be built. Required dependencies are specified using the same notation used by ``setuptools/easy_install/distribute/pip``. .. note:: If your required dependencies use the "<" or ">" characters, you must put the entire requirement in quotes to avoid misinterpretation by the shell. """ if argv is None: argv = sys.argv[1:] parser = OptionParser() parser.usage = "mkpseudo <name> <version> [options]" parser.add_option( "-d", "--dest", action="store", type="string", dest='dest', default='.', help="directory where distribution will be created (optional)") parser.add_option("-l", "--link", action="append", type="string", dest='deplinks', default=[], help="URLs to search for dependencies (optional)") parser.add_option( "-r", "--req", action="append", type="string", dest='reqs', default=[], help="requirement strings for dependent distributions (one or more)") parser.add_option( "", "--dist", action="store_true", dest="dist", help="make a source distribution after creating the directory structure" ) (options, args) = parser.parse_args(argv) if len(args) != 2: parser.print_help() sys.exit(-1) name = args[0] names = name.split('.') version = args[1] for i, url in enumerate(options.deplinks): if not url.startswith('http:') and not url.startswith('https:'): options.deplinks[i] = "http://%s" % url dest = os.path.abspath(os.path.expandvars(os.path.expanduser( options.dest))) if len(options.reqs) == 0 and options.dist: print "No dependencies have been specified, so the distribution will not be built" options.dist = False nspkgs = [] for i, nm in enumerate(names[:-1]): nspkgs.append('.'.join(names[:i + 1])) dists = working_set.resolve([Requirement.parse(r) for r in options.reqs]) dset = set([("%s" % d).replace(' ', '==') for d in dists]) setup_options = { 'requires': list(dset), 'name': name, 'version': version, 'deplinks': options.deplinks, 'nspkgs': nspkgs, } startdir = os.getcwd() if options.dist: tdir = tempfile.mkdtemp() else: tdir = dest try: os.chdir(tdir) rnames = names[::-1] for i, ns in enumerate(rnames): if i == 0: dct = {'__init__.py': ''} else: dct = { '__init__.py': _ns_template, rnames[i - 1]: dct, } dct = {names[0]: dct} dirstruct = { name: { 'setup.py': _setup_py_template % setup_options, 'src': dct, }, } if not options.dist: if os.path.exists(name): print "'%s' already exists. aborting..." % name sys.exit(-1) build_directory(dirstruct) os.chdir(name) if options.dist: tarname = os.path.join(dest, "%s-%s.tar.gz" % (name, version)) zipname = os.path.join(dest, "%s-%s.zip" % (name, version)) for fname in [tarname, zipname]: if os.path.exists(fname): print "%s already exists" % fname sys.exit(-1) cmd = [sys.executable, 'setup.py', 'sdist', '-d', dest] subprocess.check_call(cmd) finally: os.chdir(startdir) if options.dist: shutil.rmtree(tdir, onerror=onerror)
def plugin_quickstart(argv=None): """A command line script (plugin_quickstart) points to this. It generates a directory structure for an openmdao plugin package along with Sphinx docs. usage: plugin_quickstart <dist_name> [-v <version>] [-d <dest_dir>] [-g <plugin_group>] [-c class_name] """ if argv is None: argv = sys.argv[1:] parser = OptionParser() parser.usage = "plugin_quickstart <dist_name> [options]" parser.add_option("-v", "--version", action="store", type="string", dest='version', default='0.1', help="version id of the plugin (optional)") parser.add_option("-c", "--class", action="store", type="string", dest='classname', help="plugin class name (optional)") parser.add_option("-d", "--dest", action="store", type="string", dest='dest', default='.', help="directory where new plugin directory will be created (optional)") parser.add_option("-g", "--group", action="store", type="string", dest='group', default = 'openmdao.component', help="specify plugin group (openmdao.component, openmdao.driver, openmdao.variable) (optional)") (options, args) = parser.parse_args(argv) if len(args) < 1 or len(args) > 2: parser.print_help() sys.exit(-1) name = args[0] if options.classname: classname = options.classname else: classname = "%s%s" % ((name.upper())[0], name[1:]) version = options.version options.dest = os.path.abspath(os.path.expandvars(os.path.expanduser(options.dest))) startdir = os.getcwd() try: os.chdir(options.dest) if os.path.exists(name): raise OSError("Can't create directory '%s' because it already exists." % os.path.join(options.dest, name)) cfg = SafeConfigParser(dict_type=OrderedDict) stream = StringIO.StringIO(_templates['setup.cfg'] % { 'name':name, 'version':version }) cfg.readfp(stream, 'setup.cfg') cfgcontents = StringIO.StringIO() cfg.write(cfgcontents) template_options = _get_template_options(os.path.join(options.dest,name), cfg, classname=classname) template_options['srcmod'] = name dirstruct = { name: { 'setup.py': _templates['setup.py'] % template_options, 'setup.cfg': cfgcontents.getvalue(), 'MANIFEST.in': _templates['MANIFEST.in'] % template_options, 'README.txt': _templates['README.txt'] % template_options, 'src': { name: { '__init__.py': '', #'from %s import %s\n' % (name,classname), '%s.py' % name: _class_templates[options.group] % template_options, 'test': { 'test_%s.py' % name: test_template % template_options }, }, }, 'docs': { 'conf.py': _templates['conf.py'] % template_options, 'index.rst': _templates['index.rst'] % template_options, 'srcdocs.rst': _get_srcdocs(options.dest, name), 'pkgdocs.rst': _get_pkgdocs(cfg), 'usage.rst': _templates['usage.rst'] % template_options, }, }, } build_directory(dirstruct) finally: os.chdir(startdir)
def plugin_quickstart(parser, options, args=None): """A command line script (plugin quickstart) points to this. It generates a directory structure for an openmdao plugin package along with Sphinx docs. usage: plugin quickstart <dist_name> [-v <version>] [-d <dest_dir>] [-g <plugin_group>] [-c class_name] """ if args: print_sub_help(parser, "quickstart") return -1 name = options.dist_name if options.classname: classname = options.classname else: classname = "%s%s" % ((name.upper())[0], name[1:]) version = options.version options.dest = os.path.abspath(os.path.expandvars(os.path.expanduser(options.dest))) if not options.group.startswith("openmdao."): options.group = "openmdao." + options.group startdir = os.getcwd() try: os.chdir(options.dest) if os.path.exists(name): raise OSError("Can't create directory '%s' because it already exists." % os.path.join(options.dest, name)) cfg = SafeConfigParser(dict_type=OrderedDict) stream = StringIO.StringIO(_templates["setup.cfg"] % {"name": name, "version": version}) cfg.readfp(stream, "setup.cfg") cfgcontents = StringIO.StringIO() cfg.write(cfgcontents) template_options = _get_template_options(os.path.join(options.dest, name), cfg, classname=classname) template_options["srcmod"] = name dirstruct = { name: { "setup.py": _templates["setup.py"] % template_options, "setup.cfg": cfgcontents.getvalue(), "MANIFEST.in": _templates["MANIFEST.in"] % template_options, "README.txt": _templates["README.txt"] % template_options, "src": { name: { "__init__.py": "", #'from %s import %s\n' % (name,classname), "%s.py" % name: _class_templates[options.group] % template_options, "test": {"test_%s.py" % name: test_template % template_options}, } }, "docs": { "conf.py": _templates["conf.py"] % template_options, "index.rst": _templates["index.rst"] % template_options, "srcdocs.rst": _get_srcdocs(options.dest, name), "pkgdocs.rst": _get_pkgdocs(cfg), "usage.rst": _templates["usage.rst"] % template_options, }, } } build_directory(dirstruct) finally: os.chdir(startdir)
def plugin_makedist(parser, options, args=None, capture=None, srcdir="src"): """A command-line script (plugin makedist) points to this. It creates a source distribution containing Sphinx documentation for the specified distribution directory. If no directory is specified, the current directory is assumed. usage: plugin makedist [dist_dir_path] """ if args: print_sub_help(parser, "makedist") return -1 dist_dir = os.path.abspath(os.path.expandvars(os.path.expanduser(options.dist_dir_path))) _verify_dist_dir(dist_dir) startdir = os.getcwd() os.chdir(dist_dir) templates, class_templates, test_template = _load_templates() try: plugin_build_docs(parser, options) cfg = SafeConfigParser(dict_type=OrderedDict) cfg.readfp(open("setup.cfg", "r"), "setup.cfg") print "collecting entry point information..." cfg.set("metadata", "entry_points", _get_entry_points(srcdir)) template_options = _get_template_options(options.dist_dir_path, cfg, packages=find_packages(srcdir)) dirstruct = {"setup.py": templates["setup.py"] % template_options} name = cfg.get("metadata", "name") version = cfg.get("metadata", "version") if sys.platform == "win32": # pragma no cover disttar = "%s-%s.zip" % (name, version) else: disttar = "%s-%s.tar.gz" % (name, version) disttarpath = os.path.join(startdir, disttar) if os.path.exists(disttarpath): print "Removing existing distribution %s" % disttar os.remove(disttarpath) build_directory(dirstruct, force=True) cmdargs = [sys.executable, "setup.py", "sdist", "-d", startdir] if capture: stdout = open(capture, "w") stderr = STDOUT else: # pragma no cover stdout = None stderr = None try: retcode = call(cmdargs, stdout=stdout, stderr=stderr) finally: if stdout is not None: stdout.close() if retcode: cmd = " ".join(cmdargs) sys.stderr.write("\nERROR: command '%s' returned error code: %s\n" % (cmd, retcode)) return retcode finally: os.chdir(startdir) if os.path.exists(disttar): print "Created distribution %s" % disttar return 0 else: sys.stderr.write("\nERROR: failed to make distribution %s" % disttar) return -1