def _rollback_releaseinfo_files(): startdir = os.getcwd() topdir = repo_top() try: for project_name, pdir, pkgtype in openmdao_packages: pdir = os.path.join(topdir, pdir, project_name) if 'src' in os.listdir(pdir): os.chdir(os.path.join(pdir, 'src')) else: os.chdir(pdir) _rollback_releaseinfo_file(project_name) finally: os.chdir(startdir)
def _update_releaseinfo_files(version): startdir = os.getcwd() topdir = repo_top() releaseinfo_str = _get_releaseinfo_str(version) try: for project_name, pdir, pkgtype in openmdao_packages: pdir = os.path.join(topdir, pdir, project_name) if 'src' in os.listdir(pdir): os.chdir(os.path.join(pdir, 'src')) else: os.chdir(pdir) _create_releaseinfo_file(project_name, releaseinfo_str) finally: os.chdir(startdir)
def _push_release(release_dir, destination, obj): """Take a directory containing release files (openmdao package distributions, install scripts, etc., and place the files in the proper locations on the server. release_dir: str where the release file are located destination: str the location where the release files are to be placed. It can be a URL or a local directory obj: _CommObj an object to wrap the behaviors of run, put, etc. so calls are the same for local or remote release areas """ files = os.listdir(release_dir) f = fnmatch.filter(files, 'go-openmdao-*.py') if len(f) < 1: raise RuntimeError("can't find go-openmdao-*.py file in release directory") elif len(f) > 1: raise RuntimeError("more than one file in release dir matches 'go-openmdao-*.py'") script = f[0] # determine version from the form of the go-openmdao-?.?.py file version = os.path.splitext(script)[0].split('-', 2)[2] # the following will barf if the version already exists on the server obj.run('mkdir %s/downloads/%s' % (destination, version)) obj.run('chmod 755 %s/downloads/%s' % (destination, version)) # push new distribs to the server for f in os.listdir(release_dir): if (f.endswith('.tar.gz') and f != 'docs.tar.gz') or f.endswith('.egg'): obj.put(os.path.join(release_dir,f), '%s/dists/%s' % (destination, f)) obj.run('chmod 644 %s/dists/%s' % (destination, f)) # for now, put the go-openmdao script up without the version # id in the name obj.put(os.path.join(release_dir, 'go-openmdao-%s.py' % version), '%s/downloads/%s/go-openmdao.py' % (destination, version)) obj.run('chmod 755 %s/downloads/%s/go-openmdao.py' % (destination, version)) # put the docs on the server obj.put_dir(os.path.join(release_dir, 'docs'), '%s/downloads/%s/docs' % (destination, version)) obj.put(os.path.join(repo_top(),'scripts','mkdlversionindex.py'), '%s/downloads/%s/mkdlversionindex.py' % (destination, version)) obj.put(os.path.join(repo_top(),'scripts','mkegglistindex.py'), '%s/dists/mkegglistindex.py' % destination) obj.put(os.path.join(repo_top(),'scripts','mkdownloadindex.py'), '%s/downloads/mkdownloadindex.py' % destination) cdir = os.getcwd() # update the index.html for the version download directory on the server dpath = '%s/downloads/%s' % (destination, version) obj.run('cd %s && python2.6 mkdlversionindex.py' % dpath) os.chdir(cdir) # update the index.html for the dists directory on the server dpath = '%s/dists' % destination obj.run('cd %s && python2.6 mkegglistindex.py' % dpath) os.chdir(cdir) # update the 'latest' link obj.run('rm -f %s/downloads/latest' % destination) obj.run('ln -s -f %s %s/downloads/latest' % (version, destination)) os.chdir(cdir) # update the index.html for the downloads directory on the server dpath = '%s/downloads' % destination obj.run('cd %s && python mkdownloadindex.py' % dpath)
def build_release(parser, options): """Create an OpenMDAO release, placing the following files in the specified destination directory: - source distribs of all of the openmdao subpackages - binary eggs for openmdao subpackages with compiled code - an installer script for the released version of openmdao that will create a virtualenv and populate it with all of the necessary dependencies needed to use openmdao - Sphinx documentation in html To run this, you must be in a Git repository with no uncommitted changes. If not running with the ``--test`` option, a release branch will be created from the specified base branch, and in the process of running, a number of ``releaseinfo.py`` files will be updated with new version information and committed. """ if options.version is None: parser.print_usage() print "version was not specified" sys.exit(-1) if options.destdir is None: options.destdir = "rel_%s" % options.version _check_version(options.version) options.cfg = os.path.expanduser(options.cfg) hostlist, config = read_config(options) required_binaries = set([('windows', 'python2.6'), ('windows', 'python2.7')]) binary_hosts = set() if options.binaries: for host in hostlist: if config.has_section(host): if config.has_option(host, 'build_binaries') and config.getboolean(host, 'build_binaries'): platform = _get_cfg_val(config, host, 'platform') py = _get_cfg_val(config, host, 'py') if (platform, py) in required_binaries: required_binaries.remove((platform, py)) binary_hosts.add(host) if sys.platform == 'darwin': # build osx binaries if we're on a mac binary_hosts.add('localhost') elif required_binaries and sys.platform.startswith('win'): try: required_binaries.remove(('windows', 'python%d.%d' % (sys.version_info[0:2]))) except: pass else: binary_hosts.add('localhost') if required_binaries: print "WARNING: binary distributions are required for the following and no hosts were specified: %s" % list(required_binaries) if not options.test: print 'aborting...' sys.exit(-1) orig_branch = get_git_branch() if not orig_branch: print "You must make a release from within a git repository. aborting" sys.exit(-1) if not options.test: if orig_branch != options.base: print "Your current branch '%s', is not the specified base branch '%s'" % (orig_branch, options.base) sys.exit(-1) if _has_checkouts(): print "There are uncommitted changes. You must create a release from a clean branch" sys.exit(-1) if orig_branch == 'dev': print "pulling dev branch from origin..." os.system("git pull origin %s" % orig_branch) if _has_checkouts(): print "something went wrong during pull. aborting" sys.exit(-1) else: print "WARNING: base branch is not 'dev' so it has not been" print "automatically brought up-to-date." answer = raw_input("Proceed? (Y/N) ") if answer.lower() not in ["y", "yes"]: sys.exit(-1) relbranch = "release_%s" % options.version if relbranch in get_git_branches(): print "release branch %s already exists in this repo" % relbranch sys.exit(-1) print "creating release branch '%s' from base branch '%s'" % (relbranch, orig_branch) check_call(['git', 'branch', relbranch]) print "checking out branch '%s'" % relbranch check_call(['git', 'checkout', relbranch]) destdir = os.path.abspath(options.destdir) if not os.path.exists(destdir): os.makedirs(destdir) startdir = os.getcwd() topdir = repo_top() cfgpath = os.path.expanduser(options.cfg) try: _update_releaseinfo_files(options.version) # build the docs docdir = os.path.join(topdir, 'docs') idxpath = os.path.join(docdir, '_build', 'html', 'index.html') if not os.path.isfile(idxpath) or not options.nodocbuild: build_docs(parser, options) shutil.copytree(os.path.join(topdir,'docs','_build', 'html'), os.path.join(destdir,'docs')) shutil.copytree(os.path.join(topdir,'docs','_build', 'html'), os.path.join(topdir,'openmdao.main', 'src', 'openmdao', 'main', 'docs')) if not options.test: # commit the changes to the release branch print "committing all changes to branch '%s'" % relbranch check_call(['git', 'commit', '-a', '-m', '"updating releaseinfo files for release %s"' % options.version]) # build openmdao package distributions proj_dirs = [] for project_name, pdir, pkgtype in openmdao_packages: pdir = os.path.join(topdir, pdir, project_name) if 'src' in os.listdir(pdir): os.chdir(os.path.join(pdir, 'src')) else: os.chdir(pdir) print 'building %s' % project_name _build_sdist(pdir, destdir, options.version) if pkgtype == 'bdist_egg': proj_dirs.append(pdir) os.chdir(startdir) _build_bdist_eggs(proj_dirs, destdir, list(binary_hosts), cfgpath) print 'creating bootstrapping installer script go-openmdao.py' installer = os.path.join(os.path.dirname(__file__), 'mkinstaller.py') check_call([sys.executable, installer, '--dest=%s'%destdir]) if options.comment: comment = options.comment else: comment = 'creating release %s' % options.version if not options.test: # tag the current revision with the release version id print "tagging release with '%s'" % options.version check_call(['git', 'tag', '-f', '-a', options.version, '-m', comment]) check_call(['git', 'checkout', orig_branch]) print "\n*REMEMBER* to push '%s' up to the master branch if this release is official" % relbranch print "new release files have been placed in %s" % destdir finally: if options.test: _rollback_releaseinfo_files() #Cleanup shutil.rmtree(os.path.join(topdir, "openmdao.main", 'src', 'openmdao', 'main', "docs")) os.chdir(startdir)
def _push_release(release_dir, destination, obj, py='python'): """Take a directory containing release files (openmdao package distributions, install scripts, etc., and place the files in the proper locations on the server. release_dir: str where the release file are located destination: str the location where the release files are to be placed. It can be a URL or a local directory obj: _CommObj an object to wrap the behaviors of run, put, etc. so calls are the same for local or remote release areas py: str python version to use to build index files """ files = os.listdir(release_dir) f = fnmatch.filter(files, 'go-openmdao-*.py') try: f.remove('go-openmdao-dev.py') except: pass if len(f) < 1: raise RuntimeError("can't find go-openmdao-*.py file in release directory") elif len(f) > 1: raise RuntimeError("more than one file in release dir matches 'go-openmdao-*.py'") script = f[0] # determine version from the form of the go-openmdao-?.?.py file version = os.path.splitext(script)[0].split('-', 2)[2] # the following will barf if the version already exists on the server obj.run('mkdir %s/downloads/%s' % (destination, version)) obj.run('chmod 755 %s/downloads/%s' % (destination, version)) # push new distribs to the server for f in os.listdir(release_dir): if (f.endswith('.tar.gz') and f != 'docs.tar.gz') or f.endswith('.egg'): obj.put(os.path.join(release_dir,f), '%s/dists/%s' % (destination, f)) obj.run('chmod 644 %s/dists/%s' % (destination, f)) obj.put(os.path.join(release_dir, 'go-openmdao-%s.py' % version), '%s/downloads/%s/go-openmdao-%s.py' % (destination, version, version)) obj.run('chmod 755 %s/downloads/%s/go-openmdao-%s.py' % (destination, version, version)) # put the docs on the server obj.put_dir(os.path.join(release_dir, 'docs'), '%s/downloads/%s/docs' % (destination, version)) obj.put(os.path.join(repo_top(),'scripts','mkdlversionindex.py'), '%s/downloads/%s/mkdlversionindex.py' % (destination, version)) obj.put(os.path.join(repo_top(),'scripts','mkegglistindex.py'), '%s/dists/mkegglistindex.py' % destination) obj.put(os.path.join(repo_top(),'scripts','mkdownloadindex.py'), '%s/downloads/mkdownloadindex.py' % destination) cdir = os.getcwd() # update the index.html for the version download directory on the server dpath = '%s/downloads/%s' % (destination, version) obj.run('cd %s && %s mkdlversionindex.py' % (dpath, py)) os.chdir(cdir) # update the index.html for the dists directory on the server dpath = '%s/dists' % destination obj.run('cd %s && %s mkegglistindex.py' % (dpath, py)) os.chdir(cdir) # update the 'latest' link obj.run('rm -f %s/downloads/latest' % destination) obj.run('ln -s -f %s %s/downloads/latest' % (version, destination)) os.chdir(cdir) # update the index.html for the downloads directory on the server dpath = '%s/downloads' % destination obj.run('cd %s && %s mkdownloadindex.py' % (dpath, py))
def build_release(parser, options): """Create an OpenMDAO release, placing the following files in the specified destination directory: - source distribs of all of the openmdao subpackages - binary eggs for openmdao subpackages with compiled code - an installer script for the released version of openmdao that will create a virtualenv and populate it with all of the necessary dependencies needed to use openmdao - Sphinx documentation in html To run this, you must be in a Git repository with no uncommitted changes. If not running with the ``--test`` option, a release branch will be created from the specified base branch, and in the process of running, a number of ``releaseinfo.py`` files will be updated with new version information and committed. """ if options.version is None: parser.print_usage() print "version was not specified" sys.exit(-1) if options.destdir is None: options.destdir = "rel_%s" % options.version _check_version(options.version) options.cfg = os.path.expanduser(options.cfg) hostlist, config = read_config(options) required_binaries = set([('windows', 'python2.7')]) binary_hosts = set() if options.binaries: for host in hostlist: if config.has_section(host): if config.has_option(host, 'build_binaries') and config.getboolean( host, 'build_binaries'): platform = _get_cfg_val(config, host, 'platform') py = _get_cfg_val(config, host, 'py') if (platform, py) in required_binaries: required_binaries.remove((platform, py)) binary_hosts.add(host) if sys.platform == 'darwin': # build osx binaries if we're on a mac binary_hosts.add('localhost') elif required_binaries and sys.platform.startswith('win'): try: required_binaries.remove( ('windows', 'python%d.%d' % (sys.version_info[0:2]))) except: pass else: binary_hosts.add('localhost') if required_binaries: print "WARNING: binary distributions are required for the following and no hosts were specified: %s" % list( required_binaries) if not options.test: print 'aborting...' sys.exit(-1) orig_branch = get_git_branch() if not orig_branch: print "You must make a release from within a git repository. aborting" sys.exit(-1) if not options.test: if orig_branch != options.base: print "Your current branch '%s', is not the specified base branch '%s'" % ( orig_branch, options.base) sys.exit(-1) if _has_checkouts(): print "There are uncommitted changes. You must create a release from a clean branch" sys.exit(-1) if orig_branch == 'master': print "pulling master branch from origin..." os.system("git pull origin %s" % orig_branch) if _has_checkouts(): print "something went wrong during pull. aborting" sys.exit(-1) else: print "WARNING: base branch is not 'master' so it has not been" print "automatically brought up-to-date." answer = raw_input("Proceed? (Y/N) ") if answer.lower() not in ["y", "yes"]: sys.exit(-1) relbranch = "release_%s" % options.version if relbranch in get_git_branches(): print "release branch %s already exists in this repo" % relbranch sys.exit(-1) print "creating release branch '%s' from base branch '%s'" % ( relbranch, orig_branch) check_call(['git', 'branch', relbranch]) print "checking out branch '%s'" % relbranch check_call(['git', 'checkout', relbranch]) destdir = os.path.abspath(options.destdir) if not os.path.exists(destdir): os.makedirs(destdir) startdir = os.getcwd() topdir = repo_top() cfgpath = os.path.expanduser(options.cfg) try: _update_releaseinfo_files(options.version) # build the docs docdir = os.path.join(topdir, 'docs') idxpath = os.path.join(docdir, '_build', 'html', 'index.html') if not os.path.isfile(idxpath) or not options.nodocbuild: build_docs(parser, options) shutil.copytree(os.path.join(topdir, 'docs', '_build', 'html'), os.path.join(destdir, 'docs')) shutil.copytree( os.path.join(topdir, 'docs', '_build', 'html'), os.path.join(topdir, 'openmdao.main', 'src', 'openmdao', 'main', 'docs')) if not options.test: # commit the changes to the release branch print "committing all changes to branch '%s'" % relbranch check_call([ 'git', 'commit', '-a', '-m', '"updating releaseinfo files for release %s"' % options.version ]) # build openmdao package distributions proj_dirs = [] for project_name, pdir, pkgtype in openmdao_packages: pdir = os.path.join(topdir, pdir, project_name) if 'src' in os.listdir(pdir): os.chdir(os.path.join(pdir, 'src')) else: os.chdir(pdir) print 'building %s' % project_name _build_sdist(pdir, destdir, options.version) if pkgtype == 'bdist_egg': proj_dirs.append(pdir) os.chdir(startdir) _build_bdist_eggs(proj_dirs, destdir, list(binary_hosts), cfgpath) print 'creating bootstrapping installer script go-openmdao-%s.py' % options.version installer = os.path.join(os.path.dirname(__file__), 'mkinstaller.py') check_call([sys.executable, installer, '--dest=%s' % destdir]) if options.comment: comment = options.comment else: comment = 'creating release %s' % options.version if not options.test: # tag the current revision with the release version id print "tagging release with '%s'" % options.version check_call( ['git', 'tag', '-f', '-a', options.version, '-m', comment]) check_call(['git', 'checkout', orig_branch]) print "\n*REMEMBER* to push '%s' up to the master branch if this release is official" % relbranch print "new release files have been placed in %s" % destdir finally: if options.test: _rollback_releaseinfo_files() # Cleanup try: shutil.rmtree( os.path.join(topdir, "openmdao.main", 'src', 'openmdao', 'main', "docs")) except: pass os.chdir(startdir)
def make_release(): """Create an OpenMDAO release, placing the following files in the specified destination directory: - source distribs of all of the openmdao subpackages - binary eggs for openmdao subpackages with compiled code - an installer script for the released version of openmdao that will create a virtualenv and populate it with all of the necessary dependencies needed to use openmdao - Sphinx documentation in html In order to run this, you must be in a git repository with no uncommitted changes. If not running with the --test option, a release branch will be created from the specified base branch, and in the process of running, a number of releaseinfo.py files will be updated with new version information and committed. """ parser = OptionParser() parser.add_option("-d", "--destination", action="store", type="string", dest="destdir", help="directory where distributions and docs will be placed") parser.add_option("-v", "--version", action="store", type="string", dest="version", help="version string applied to all openmdao distributions") parser.add_option("-m", action="store", type="string", dest="comment", help="optional comment for version tag") parser.add_option("-b", "--basebranch", action="store", type="string", dest="base", default='master', help="base branch for release. defaults to master") parser.add_option("-t", "--test", action="store_true", dest="test", help="used for testing. A release branch will not be created") parser.add_option("-n", "--nodocbuild", action="store_true", dest="nodocbuild", help="used for testing. The docs will not be rebuilt if they already exist") parser.add_option("--host", action='append', dest='hosts', metavar='HOST', default=[], help="host from config file to build bdist_eggs on. " "Multiple --host args are allowed.") parser.add_option("-c", "--config", action='store', dest='cfg', metavar='CONFIG', default='~/.openmdao/testhosts.cfg', help="path of config file where info for hosts is located") (options, args) = parser.parse_args(sys.argv[1:]) if not options.version or not options.destdir: parser.print_help() sys.exit(-1) _check_version(options.version) options.cfg = os.path.expanduser(options.cfg) config = ConfigParser.ConfigParser() config.readfp(open(options.cfg)) haswin = False for host in options.hosts: if host == 'localhost': if sys.platform.startswith('win'): haswin = True elif config.has_section(host): platform = config.get(host, 'platform') if platform == 'windows': haswin = True if not haswin: print "no windows host was specified, so can't build binary eggs for windows" sys.exit(-1) orig_branch = get_git_branch() if not orig_branch: print "You must run mkrelease from within a git repository. aborting" sys.exit(-1) if not options.test: if orig_branch != options.base: print "Your current branch '%s', is not the specified base branch '%s'" % (orig_branch, options.base) sys.exit(-1) if _has_checkouts(): print "There are uncommitted changes. You must run mkrelease.py from a clean branch" sys.exit(-1) if orig_branch == 'master': print "pulling master" os.system("git pull origin master") if _has_checkouts(): print "something went wrong during pull. aborting" sys.exit(-1) else: print "WARNING: base branch is not 'master' so it has not been" print "automatically brought up-to-date." answer = raw_input("Proceed? (Y/N) ") if answer.lower() not in ["y", "yes"]: sys.exit(-1) relbranch = "release_%s" % options.version if relbranch in get_git_branches(): print "release branch %s already exists in this repo" % relbranch sys.exit(-1) print "creating release branch '%s' from base branch '%s'" % (relbranch, orig_branch) check_call(['git', 'branch', relbranch]) print "checking out branch '%s'" % relbranch check_call(['git', 'checkout', relbranch]) destdir = os.path.abspath(options.destdir) if not os.path.exists(destdir): os.makedirs(destdir) startdir = os.getcwd() topdir = repo_top() cfgpath = os.path.expanduser(options.cfg) try: _update_releaseinfo_files(options.version) # build the docs docdir = os.path.join(topdir, 'docs') idxpath = os.path.join(docdir, '_build', 'html', 'index.html') if not os.path.isfile(idxpath) or not options.nodocbuild: build_docs(argv=['-v', options.version]) shutil.copytree(os.path.join(topdir,'docs','_build', 'html'), os.path.join(destdir,'docs')) if not options.test: # commit the changes to the release branch print "committing all changes to branch '%s'" % relbranch check_call(['git', 'commit', '-a', '-m', '"updating releaseinfo files for release %s"' % options.version]) # build openmdao package distributions proj_dirs = [] for project_name, pdir, pkgtype in openmdao_packages: pdir = os.path.join(topdir, pdir, project_name) if 'src' in os.listdir(pdir): os.chdir(os.path.join(pdir, 'src')) else: os.chdir(pdir) print 'building %s' % project_name _build_sdist(pdir, destdir, options.version) if pkgtype == 'bdist_egg': proj_dirs.append(pdir) os.chdir(startdir) _build_bdist_eggs(proj_dirs, destdir, options.hosts, cfgpath) print 'creating bootstrapping installer script go-openmdao.py' installer = os.path.join(os.path.dirname(__file__), 'mkinstaller.py') check_call([sys.executable, installer, '--dest=%s'%destdir]) if options.comment: comment = options.comment else: comment = 'creating release %s' % options.version if options.test: _rollback_releaseinfo_files() else: # tag the current revision with the release version id print "tagging release with '%s'" % options.version check_call(['git', 'tag', '-f', '-a', options.version, '-m', comment]) check_call(['git', 'checkout', orig_branch]) print "\n*REMEMBER* to push '%s' up to the master branch if this release is official" % relbranch print "new release files have been placed in %s" % destdir finally: os.chdir(startdir)