예제 #1
0
파일: dist.py 프로젝트: jmavila/python
 def fetch_build_eggs(self, requires):
     """Resolve pre-setup requirements"""
     from pkg_resources import working_set, parse_requirements
     for dist in working_set.resolve(
         parse_requirements(requires), installer=self.fetch_build_egg
     ):
         working_set.add(dist)
예제 #2
0
 def fetch_build_eggs(self, requires):
     """Resolve pre-setup requirements"""
     from pkg_resources import working_set, parse_requirements
     for dist in working_set.resolve(
         parse_requirements(requires), installer=self.fetch_build_egg
     ):
         working_set.add(dist)
예제 #3
0
 def fetch_requirement(req, dest_dir, force_download):
     from setuptools.package_index import PackageIndex  # @Reimport
     from pkg_resources import working_set  # @Reimport  # NOQA
     i = PackageIndex()
     if force_download:
         [i.remove(i[req.key][0]) for _ in xrange(len(i[req.key]))]
         d = i.download(req, dest_dir)
     else:
         d = i.fetch_distribution(req, dest_dir, force_scan=True)
     d = getattr(d, 'location', d) if d else ''
     return (d if d else working_set.resolve([req])[0].location)
예제 #4
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    parser = OptionParser()
    parser.add_option("--dev", action="store_true", dest='dev',
                      help="if present, a development script will be generated instead of a release script")
    parser.add_option("--dest", action="store", type="string", dest='dest',
                      help="specify destination directory", default='.')
    parser.add_option("--offline", action="store", type="string", dest='offline',
                      help="make offline gathering script", default='')
    parser.add_option("-f", "--findlinks", action="store", type="string",
                      dest="findlinks",
                      default='http://openmdao.org/dists',
                      help="default URL where openmdao packages and dependencies are searched for first (before PyPI)")

    (options, args) = parser.parse_args(args)

    if len(args) > 0:
        print 'unrecognized args: %s' % args
        parser.print_help()
        sys.exit(-1)

    if options.dev:
        openmdao_packages.extend(openmdao_dev_packages)
        sout = StringIO.StringIO()
        pprint.pprint(openmdao_packages, sout)
        pkgstr = sout.getvalue()
        make_dev_eggs = """
        # now install dev eggs for all of the openmdao packages
        topdir = os.path.abspath(os.path.dirname(__file__))
        startdir = os.getcwd()
        absbin = os.path.abspath(bin_dir)
        openmdao_packages = %s
        try:
            for pkg, pdir, _ in openmdao_packages:
                if not options.gui and pkg == 'openmdao.gui':
                    continue
                os.chdir(join(topdir, pdir, pkg))
                cmdline = [join(absbin, 'python'), 'setup.py',
                           'develop', '-N'] + cmds
                try:
                    call_subprocess(cmdline, show_stdout=True, raise_on_returncode=True)
                except OSError:
                    failures.append(pkg)
        finally:
            os.chdir(startdir)
        """ % pkgstr
        make_docs = """
        if options.docs:
            if(os.system('%s %s && %s %s build_docs && deactivate'
                         % (source_command, activate, python, openmdao)) != 0):
                print "Failed to build the docs."
        else:
            print "\\nSkipping build of OpenMDAO docs.\\n"
        """
    else:  # making a release installer
        make_dev_eggs = ''
        make_docs = ''

    if options.offline == "gather":
        offline_ = ["'-zmaxd'", "'-zmaxd'", ", 'pkg'", "os.mkdir('pkg')", "['-f', url]", "['-f', openmdao_url]"]
        f_prefix = "gather-"
    elif options.offline == "installer":
        offline_ = ["'-Z'", "'-NZ'", '', '', "['-H', 'None', '-f', options.findlinks]", "['-H', 'None', '-f', options.findlinks]"]
        f_prefix = "offline-"
    else:
        offline_ = ["'-Z'", "'-NZ'", '', '', "['-f', url]", "['-f', openmdao_url]"]
        f_prefix = ""

    script_str = """

openmdao_prereqs = %(openmdao_prereqs)s

%(mkdir_pkg)s

def extend_parser(parser):
    parser.add_option("-r","--req", action="append", type="string", dest='reqs',
                      help="specify additional required distributions", default=[])
    parser.add_option("--noprereqs", action="store_true", dest='noprereqs',
                      help="don't check for any prerequisites, e.g., numpy or scipy")
    parser.add_option("--nogui", action="store_false", dest='gui', default=True,
                      help="do not install the openmdao graphical user interface and its dependencies")
    parser.add_option("--nodocs", action="store_false", dest='docs', default=True,
                      help="do not build the docs")
    parser.add_option("-f", "--findlinks", action="store", type="string",
                      dest="findlinks",
                      help="default URL where openmdao packages and dependencies are searched for first (before PyPI)")
    parser.add_option("--testurl", action="store", type="string", dest='testurl',
                      help="specify url where openmdao.* distribs are located (used for release testing only)")

    # go back to old behavior that includes system site packages by default
    parser.set_defaults(system_site_packages=True)

%(adjust_options)s


def download(url, dest='.'):
    import urllib2
    dest = os.path.abspath(os.path.expanduser(os.path.expandvars(dest)))

    resp = urllib2.urlopen(url)
    outpath = os.path.join(dest, os.path.basename(url))
    bs = 1024*8
    with open(outpath, 'wb') as out:
        while True:
            block = resp.fp.read(bs)
            if block == '':
                break
            out.write(block)
    return outpath

def _get_mingw_dlls(bin_dir):
    def _mingw_dlls_in_path():
        # first, check if MinGW/bin is already in PATH
        if 'path' in os.environ:
            for entry in os.environ['PATH'].split(os.pathsep):
                if os.path.isfile(os.path.join(entry, 'libgfortran-3.dll')):
                    print 'MinGW is already installed, skipping download.'
                    return True

        return False

    def _get_mingw_dlls_from_site(bin_dir):
        import zipfile
        dest = os.path.abspath(bin_dir)
        zippath = download('http://openmdao.org/releases/misc/mingwdlls.zip')
        zipped = zipfile.ZipFile(zippath, 'r')
        zipped.extractall(dest)
        zipped.close()
        os.remove(zippath)

    _mingw_dlls_in_path() or _get_mingw_dlls_from_site(bin_dir)

def _single_install(cmds, req, bin_dir, failures, dodeps=False):
    global logger
    if dodeps:
        extarg = %(extarg1)s
    else:
        extarg = %(extarg2)s
    # If there are spaces in the install path, the easy_install script
    # will have an invalid shebang line (Linux/Mac only).
    cmdline = [] if is_win else [join(bin_dir, 'python')]
    cmdline += [join(bin_dir, 'easy_install'), extarg %(dldir)s] + cmds + [req]
        # pip seems more robust than easy_install, but won't install binary distribs :(
        #cmdline = [join(bin_dir, 'pip'), 'install'] + cmds + [req]
    #logger.debug("running command: %%s" %% ' '.join(cmdline))
    try:
        call_subprocess(cmdline, show_stdout=True, raise_on_returncode=True)
    except OSError:
        failures.append(req)


def _copy_winlibs(home_dir, activated):
    # On windows, builds using numpy.distutils.Configuration will
    # fail when built in a virtualenv
    # (still broken as of virtualenv 1.9.1, under python 2.7.4)
    # because distutils looks for libpython?.?.lib under sys.prefix/libs.
    # virtualenv does not (at this time) create a libs directory.

    import fnmatch
    libsdir = os.path.join(home_dir, 'libs')
    if not os.path.isdir(libsdir):
        os.mkdir(libsdir)
    if activated:
        with open(os.path.join(home_dir, 'Lib', 'orig-prefix.txt')) as inp:
            prefix = inp.readline().strip()
    else:
        prefix = os.path.dirname(sys.executable)
    sysdir = os.path.join(prefix, 'libs')
    names = os.listdir(sysdir)
    for pat in ['*python*', '*msvc*']:
        for name in fnmatch.filter(names, pat):
            if not os.path.isfile(os.path.join(libsdir, name)):
                shutil.copyfile(os.path.join(sysdir, name),
                                os.path.join(libsdir, name))

def _update_easy_manifest(home_dir):
    # distribute requires elevation when run on 32 bit windows,
    # apparently because Windows assumes that any program with
    # 'install' in the name should require elevation.  The
    # solution is to create a manifest file for easy_install.exe
    # that tells Windows that it doesn't require elevated
    # access.
    template = \"\"\"
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0"
  processorArchitecture="X86"
  name="easy_install.exe"
  type="win32"/>
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  <security>
  <requestedPrivileges>
  <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
  </requestedPrivileges>
  </security>
  </trustInfo>
</assembly>
    \"\"\"

    bindir = os.path.join(home_dir, 'Scripts')
    manifest = os.path.join(bindir, 'easy_install.exe.manifest')
    if not os.path.isfile(manifest):
        with open(manifest, 'w') as f:
            f.write(template)
        # 'touch' the easy_install executable
        os.utime(os.path.join(bindir, 'easy_install.exe'), None)

def after_install(options, home_dir, activated=False):
    global logger, openmdao_prereqs

    setuptools_version = "0.9.5"
    setuptools_egg = \"setuptools-%%s-py%%s.egg\" %% (setuptools_version, sys.version[:3])

    if(os.path.exists(setuptools_egg)):
        os.remove(setuptools_egg)

    reqs = %(reqs)s
    guireqs = %(guireqs)s
    guitestreqs = %(guitestreqs)s

    if options.findlinks is None:
        url = '%(url)s'
    else:
        url = options.findlinks
    # For testing we allow one to specify a url where the openmdao
    # package dists are located that may be different from the main
    # url where the dependencies are located. We do this because
    # setuptools only allows us to specify a single -f parameter,
    # which would force us to mirror the entire openmdao distribution
    # directory in order to test our releases because setuptools will
    # barf if it can't find everything in the same location (or on PyPI).
    # TODO: get rid of this after we quit using setuptools.
    if options.testurl:
        openmdao_url = options.testurl
    else:
        openmdao_url = url
    etc = join(home_dir, 'etc')
    if is_win:
        lib_dir = join(home_dir, 'Lib')
        bin_dir = join(home_dir, 'Scripts')
    else:
        lib_dir = join(home_dir, 'lib', py_version)
        bin_dir = join(home_dir, 'bin')

    if not os.path.exists(etc):
        os.makedirs(etc)

    if is_win:
        _copy_winlibs(home_dir, activated)
        _update_easy_manifest(home_dir)
    else:
        # Put lib64_path at front of paths rather than end.
        # As of virtualenv 1.8.2 this fix had not made it in the release.
        patched = False
        site_orig = join(lib_dir, 'site.py')
        site_patched = join(lib_dir, 'site-patched.py')
        with open(site_orig, 'r') as inp:
            with open(site_patched, 'w') as out:
                for line in inp:
                    if 'paths.append(lib64_path)' in line:
                        print 'Patching site.py...'
                        print '  found %%r' %% line
                        line = line.replace('append(', 'insert(0, ')
                        print '    new %%r' %% line
                        sys.stdout.flush()
                        patched = True
                    out.write(line)
        if patched:
            os.rename(site_orig, join(lib_dir, 'site-orig.py'))
            os.rename(site_patched, site_orig)

    failed_imports = []
    for pkg in openmdao_prereqs:
        try:
            __import__(pkg)
        except ImportError:
            failed_imports.append(pkg)
    if failed_imports:
        if options.noprereqs:
            print "\\n**** The following prerequisites could not be imported: %%s." %% failed_imports
            print "**** As a result, some OpenMDAO components will not work."
        else:
            print "ERROR: the following prerequisites could not be imported: %%s." %% failed_imports
            print "These must be installed in the system level python before installing OpenMDAO."
            print "To run a limited version of OpenMDAO without the prerequisites, try 'python %%s --noprereqs'" %% __file__
            sys.exit(-1)

    cmds = %(cmds_str)s
    openmdao_cmds = %(openmdao_cmds_str)s
    try:
        allreqs = reqs[:]
        failures = []
        if options.gui:
            allreqs = allreqs + guireqs
            allreqs = allreqs + guitestreqs

        for req in allreqs:
            if req.startswith('openmdao.'):
                _single_install(openmdao_cmds, req, bin_dir, failures)
            else:
                _single_install(cmds, req, bin_dir, failures)

%(make_dev_eggs)s

        # add any additional packages specified on the command line
        for req in options.reqs:
            _single_install(cmds, req, bin_dir, failures, dodeps=True)

        activate = os.path.join(bin_dir, 'activate')
        deactivate = os.path.join(bin_dir, 'deactivate')
        if is_win:
            source_command = ''
            python = ''
            openmdao = 'openmdao'
        else:
            source_command = '.'
            python = os.path.join(bin_dir, 'python')
            openmdao = os.path.join(bin_dir, 'openmdao')

%(make_docs)s
        if is_win: # retrieve MinGW DLLs from server
            try:
                _get_mingw_dlls(bin_dir)
            except Exception as err:
                print str(err)
                print "\\n\\n**** Failed to download MinGW DLLs, so OpenMDAO extension packages may fail to load."
                print "If you install MinGW yourself (including c,c++, and fortran compilers) and put "
                print "the MinGW bin directory in your path, that should fix the problem."
    except Exception as err:
        print "ERROR: build failed: %%s" %% str(err)
        sys.exit(-1)

    # If there are spaces in the install path lots of commands need to be
    # patched so Python can be found on Linux/Mac.
    abs_bin = os.path.abspath(bin_dir)
    if not is_win and ' ' in abs_bin:
        import stat
        shebang = '#!"%%s"\\n' %% os.path.join(abs_bin, 'python')
        print '\\nFixing scripts for spaces in install path'
        for path in sorted(glob.glob(os.path.join(bin_dir, '*'))):
            with open(path, 'r') as script:
                lines = script.readlines()
            if lines[0] == shebang:
                mode = os.stat(path).st_mode
                os.rename(path, path+'.orig')
                lines[0] = '#!/usr/bin/env python\\n'
                with open(path, 'w') as script:
                    script.writelines(lines)
                os.chmod(path, mode)

    abshome = os.path.abspath(home_dir)

    if failures:
        failures.sort()
        print '\\n\\n***** The following packages failed to install: %%s.' %% failures
        print
        print 'This may be an intermittent network problem and simply retrying'
        print 'could result in a successfull installation.  Without all'
        print 'packages at least some tests will likely fail, and without core'
        print 'packages such as Traits OpenMDAO will not function at all.'
        print
        if not activated:
            print 'If you would like to try using this installation anyway,'
            print 'from %%s type:\\n' %% abshome
            if is_win:
                print r'Scripts\\activate'
            else:
                print '. bin/activate'
            print '\\nto activate your environment.'

    else:
        print '\\n\\nThe OpenMDAO virtual environment has been installed in\\n %%s' %% abshome
        if not activated:
            print '\\nFrom %%s, type:\\n' %% abshome
            if is_win:
                print r'Scripts\\activate'
            else:
                print '. bin/activate'
            print '\\nto activate your environment and start using OpenMDAO.'

    sys.exit(1 if failures else 0)
    """

    reqs = set()
    guireqs = set()
    guitestreqs = set()

    version = '?.?.?'
    excludes = set(['setuptools', 'distribute', 'SetupDocs']+openmdao_prereqs)
    dists = working_set.resolve([Requirement.parse(r[0])
                                   for r in openmdao_packages if r[0] != 'openmdao.gui'])

    distnames = set([d.project_name for d in dists])-excludes
    gui_dists = working_set.resolve([Requirement.parse('openmdao.gui')])
    guinames = set([d.project_name for d in gui_dists])-distnames-excludes
    guitest_dists = working_set.resolve([Requirement.parse('openmdao.gui[jsTest]')])
    guitest_dists.extend(working_set.resolve([Requirement.parse('openmdao.gui[functionalTest]')]))
    guitestnames = set([d.project_name for d in guitest_dists])-distnames-excludes-guinames

    try:
        setupdoc_dist = working_set.resolve([Requirement.parse('setupdocs')])[0]
    except:
        setupdoc_dist = None

    for dist in dists:
        if dist.project_name not in distnames:
            continue
        if dist.project_name == 'openmdao.main':
            version = dist.version
        if options.dev:  # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                reqs.add('%s' % dist.as_requirement())
        else:
            reqs.add('%s' % dist.as_requirement())

    for dist in gui_dists:
        if dist.project_name not in guinames:
            continue
        if options.dev:  # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                guireqs.add('%s' % dist.as_requirement())
        else:
            guireqs.add('%s' % dist.as_requirement())

    for dist in guitest_dists:
        if dist.project_name not in guitestnames:
            continue
        if options.dev:  # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                guitestreqs.add('%s' % dist.as_requirement())
        else:
            guitestreqs.add('%s' % dist.as_requirement())

    # adding setupdocs req is a workaround to prevent Traits from looking elsewhere for it
    if setupdoc_dist:
        _reqs = [str(setupdoc_dist.as_requirement())]
    else:
        _reqs = ['setupdocs>=1.0']
    reqs = sorted(_reqs + list(reqs))
    guireqs = sorted(guireqs)
    guitestreqs = sorted(guitestreqs)

    # pin setuptools to this version
    setuptools_version = "0.9.5"
    setuptools_url = "https://openmdao.org/dists/setuptools-%s-py%s.egg" % (setuptools_version, sys.version[:3])

    optdict = {
        'mkdir_pkg':         offline_[3],
        'extarg1':           offline_[0],
        'extarg2':           offline_[1],
        'dldir':             offline_[2],
        'cmds_str':          offline_[4],
        'openmdao_cmds_str': offline_[5],
        'reqs':              reqs,
        'guireqs':           guireqs,
        'guitestreqs':       guitestreqs,
        'version':           version,
        'url':               options.findlinks,
        'make_dev_eggs':     make_dev_eggs,
        'make_docs':         make_docs,
        'adjust_options':    _get_adjust_options(options, version, setuptools_url, setuptools_version),
        'openmdao_prereqs':  openmdao_prereqs,
    }

    dest = os.path.abspath(options.dest)
    if options.dev:
        scriptname = os.path.join(dest, f_prefix + 'go-openmdao-dev.py')
    else:
        scriptname = os.path.join(dest, f_prefix + 'go-openmdao-%s.py' % version)

    if os.path.isfile(scriptname):
        shutil.copyfile(scriptname, scriptname+'.old'
                        )
    with open(scriptname, 'wb') as f:
        # Pin the version of setuptools used.
        fixline = u"        egg_path = 'setuptools-*-py%s.egg' % sys.version[:3]"
        for line in virtualenv.create_bootstrap_script(script_str % optdict).split('\n'):
            if line == fixline:
                line = line.replace('*', setuptools_version)
            elif ", '-U'" in line:  # remove forcing it to look for latest setuptools version
                line = line.replace(", '-U'", "")
            f.write('%s\n' % line)
    os.chmod(scriptname, 0755)
예제 #5
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    parser = OptionParser()
    parser.add_option(
        "--dev",
        action="store_true",
        dest='dev',
        help=
        "if present, a development script will be generated instead of a release script"
    )
    parser.add_option("--dest",
                      action="store",
                      type="string",
                      dest='dest',
                      help="specify destination directory",
                      default='.')
    parser.add_option("--offline",
                      action="store",
                      type="string",
                      dest='offline',
                      help="make offline gathering script",
                      default='')
    parser.add_option(
        "-f",
        "--findlinks",
        action="store",
        type="string",
        dest="findlinks",
        default='http://openmdao.org/dists',
        help=
        "default URL where openmdao packages and dependencies are searched for first (before PyPI)"
    )

    (options, args) = parser.parse_args(args)

    if len(args) > 0:
        print 'unrecognized args: %s' % args
        parser.print_help()
        sys.exit(-1)

    if options.dev:
        openmdao_packages.extend(openmdao_dev_packages)
        sout = StringIO.StringIO()
        pprint.pprint(openmdao_packages, sout)
        pkgstr = sout.getvalue()
        make_dev_eggs = """
        # now install dev eggs for all of the openmdao packages
        topdir = os.path.abspath(os.path.dirname(__file__))
        startdir = os.getcwd()
        absbin = os.path.abspath(bin_dir)
        openmdao_packages = %s
        try:
            for pkg, pdir, _ in openmdao_packages:
                if not options.gui and pkg == 'openmdao.gui':
                    continue
                os.chdir(join(topdir, pdir, pkg))
                cmdline = [join(absbin, 'python'), 'setup.py',
                           'develop', '-N'] + cmds
                try:
                    call_subprocess(cmdline, show_stdout=True, raise_on_returncode=True)
                except OSError:
                    failures.append(pkg)
        finally:
            os.chdir(startdir)
        """ % pkgstr
        make_docs = """
        if options.docs:
            if(os.system('%s %s && %s %s build_docs && deactivate'
                         % (source_command, activate, python, openmdao)) != 0):
                print "Failed to build the docs."
        else:
            print "\\nSkipping build of OpenMDAO docs.\\n"
        """
    else:  # making a release installer
        make_dev_eggs = ''
        make_docs = ''

    if options.offline == "gather":
        offline_ = [
            "'-zmaxd'", "'-zmaxd'", ", 'pkg'", "os.mkdir('pkg')",
            "['-f', url]", "['-f', openmdao_url]"
        ]
        f_prefix = "gather-"
    elif options.offline == "installer":
        offline_ = [
            "'-Z'", "'-NZ'", '', '', "['-H', 'None', '-f', options.findlinks]",
            "['-H', 'None', '-f', options.findlinks]"
        ]
        f_prefix = "offline-"
    else:
        offline_ = [
            "'-Z'", "'-NZ'", '', '', "['-f', url]", "['-f', openmdao_url]"
        ]
        f_prefix = ""

    script_str = """

openmdao_prereqs = %(openmdao_prereqs)s

%(mkdir_pkg)s

def extend_parser(parser):
    parser.add_option("-r","--req", action="append", type="string", dest='reqs',
                      help="specify additional required distributions", default=[])
    parser.add_option("--noprereqs", action="store_true", dest='noprereqs',
                      help="don't check for any prerequisites, e.g., numpy or scipy")
    parser.add_option("--nogui", action="store_false", dest='gui', default=True,
                      help="do not install the openmdao graphical user interface and its dependencies")
    parser.add_option("--nodocs", action="store_false", dest='docs', default=True,
                      help="do not build the docs")
    parser.add_option("-f", "--findlinks", action="store", type="string",
                      dest="findlinks",
                      help="default URL where openmdao packages and dependencies are searched for first (before PyPI)")
    parser.add_option("--testurl", action="store", type="string", dest='testurl',
                      help="specify url where openmdao.* distribs are located (used for release testing only)")

    # go back to old behavior that includes system site packages by default
    parser.set_defaults(system_site_packages=True)

%(adjust_options)s


def download(url, dest='.'):
    import urllib2
    dest = os.path.abspath(os.path.expanduser(os.path.expandvars(dest)))

    resp = urllib2.urlopen(url)
    outpath = os.path.join(dest, os.path.basename(url))
    bs = 1024*8
    with open(outpath, 'wb') as out:
        while True:
            block = resp.fp.read(bs)
            if block == '':
                break
            out.write(block)
    return outpath

def _get_mingw_dlls(bin_dir):
    def _mingw_dlls_in_path():
        # first, check if MinGW/bin is already in PATH
        if 'path' in os.environ:
            for entry in os.environ['PATH'].split(os.pathsep):
                if os.path.isfile(os.path.join(entry, 'libgfortran-3.dll')):
                    print 'MinGW is already installed, skipping download.'
                    return True

        return False

    def _get_mingw_dlls_from_site(bin_dir):
        import zipfile
        dest = os.path.abspath(bin_dir)
        zippath = download('http://openmdao.org/releases/misc/mingwdlls.zip')
        zipped = zipfile.ZipFile(zippath, 'r')
        zipped.extractall(dest)
        zipped.close()
        os.remove(zippath)

    _mingw_dlls_in_path() or _get_mingw_dlls_from_site(bin_dir)

def _single_install(cmds, req, bin_dir, failures, dodeps=False):
    global logger
    if dodeps:
        extarg = %(extarg1)s
    else:
        extarg = %(extarg2)s
    # If there are spaces in the install path, the easy_install script
    # will have an invalid shebang line (Linux/Mac only).
    cmdline = [] if is_win else [join(bin_dir, 'python')]
    cmdline += [join(bin_dir, 'easy_install'), extarg %(dldir)s] + cmds + [req]
        # pip seems more robust than easy_install, but won't install binary distribs :(
        #cmdline = [join(bin_dir, 'pip'), 'install'] + cmds + [req]
    #logger.debug("running command: %%s" %% ' '.join(cmdline))
    try:
        call_subprocess(cmdline, show_stdout=True, raise_on_returncode=True)
    except OSError:
        failures.append(req)


def _copy_winlibs(home_dir, activated):
    # On windows, builds using numpy.distutils.Configuration will
    # fail when built in a virtualenv
    # (still broken as of virtualenv 1.9.1, under python 2.7.4)
    # because distutils looks for libpython?.?.lib under sys.prefix/libs.
    # virtualenv does not (at this time) create a libs directory.

    import fnmatch
    libsdir = os.path.join(home_dir, 'libs')
    if not os.path.isdir(libsdir):
        os.mkdir(libsdir)
    if activated:
        with open(os.path.join(home_dir, 'Lib', 'orig-prefix.txt')) as inp:
            prefix = inp.readline().strip()
    else:
        prefix = os.path.dirname(sys.executable)
    sysdir = os.path.join(prefix, 'libs')
    names = os.listdir(sysdir)
    for pat in ['*python*', '*msvc*']:
        for name in fnmatch.filter(names, pat):
            if not os.path.isfile(os.path.join(libsdir, name)):
                shutil.copyfile(os.path.join(sysdir, name),
                                os.path.join(libsdir, name))

def _update_easy_manifest(home_dir):
    # distribute requires elevation when run on 32 bit windows,
    # apparently because Windows assumes that any program with
    # 'install' in the name should require elevation.  The
    # solution is to create a manifest file for easy_install.exe
    # that tells Windows that it doesn't require elevated
    # access.
    template = \"\"\"
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0"
  processorArchitecture="X86"
  name="easy_install.exe"
  type="win32"/>
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  <security>
  <requestedPrivileges>
  <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
  </requestedPrivileges>
  </security>
  </trustInfo>
</assembly>
    \"\"\"

    bindir = os.path.join(home_dir, 'Scripts')
    manifest = os.path.join(bindir, 'easy_install.exe.manifest')
    if not os.path.isfile(manifest):
        with open(manifest, 'w') as f:
            f.write(template)
        # 'touch' the easy_install executable
        os.utime(os.path.join(bindir, 'easy_install.exe'), None)

def after_install(options, home_dir, activated=False):
    global logger, openmdao_prereqs

    setuptools_version = "0.9.5"
    setuptools_egg = \"setuptools-%%s-py%%s.egg\" %% (setuptools_version, sys.version[:3])

    if(os.path.exists(setuptools_egg)):
        os.remove(setuptools_egg)

    reqs = %(reqs)s
    guireqs = %(guireqs)s
    guitestreqs = %(guitestreqs)s

    if options.findlinks is None:
        url = '%(url)s'
    else:
        url = options.findlinks
    # For testing we allow one to specify a url where the openmdao
    # package dists are located that may be different from the main
    # url where the dependencies are located. We do this because
    # setuptools only allows us to specify a single -f parameter,
    # which would force us to mirror the entire openmdao distribution
    # directory in order to test our releases because setuptools will
    # barf if it can't find everything in the same location (or on PyPI).
    # TODO: get rid of this after we quit using setuptools.
    if options.testurl:
        openmdao_url = options.testurl
    else:
        openmdao_url = url
    etc = join(home_dir, 'etc')
    if is_win:
        lib_dir = join(home_dir, 'Lib')
        bin_dir = join(home_dir, 'Scripts')
    else:
        lib_dir = join(home_dir, 'lib', py_version)
        bin_dir = join(home_dir, 'bin')

    if not os.path.exists(etc):
        os.makedirs(etc)

    if is_win:
        _copy_winlibs(home_dir, activated)
        _update_easy_manifest(home_dir)
    else:
        # Put lib64_path at front of paths rather than end.
        # As of virtualenv 1.8.2 this fix had not made it in the release.
        patched = False
        site_orig = join(lib_dir, 'site.py')
        site_patched = join(lib_dir, 'site-patched.py')
        with open(site_orig, 'r') as inp:
            with open(site_patched, 'w') as out:
                for line in inp:
                    if 'paths.append(lib64_path)' in line:
                        print 'Patching site.py...'
                        print '  found %%r' %% line
                        line = line.replace('append(', 'insert(0, ')
                        print '    new %%r' %% line
                        sys.stdout.flush()
                        patched = True
                    out.write(line)
        if patched:
            os.rename(site_orig, join(lib_dir, 'site-orig.py'))
            os.rename(site_patched, site_orig)

    failed_imports = []
    for pkg in openmdao_prereqs:
        try:
            __import__(pkg)
        except ImportError:
            failed_imports.append(pkg)
    if failed_imports:
        if options.noprereqs:
            print "\\n**** The following prerequisites could not be imported: %%s." %% failed_imports
            print "**** As a result, some OpenMDAO components will not work."
        else:
            print "ERROR: the following prerequisites could not be imported: %%s." %% failed_imports
            print "These must be installed in the system level python before installing OpenMDAO."
            print "To run a limited version of OpenMDAO without the prerequisites, try 'python %%s --noprereqs'" %% __file__
            sys.exit(-1)

    cmds = %(cmds_str)s
    openmdao_cmds = %(openmdao_cmds_str)s
    try:
        allreqs = reqs[:]
        failures = []
        if options.gui:
            allreqs = allreqs + guireqs
            allreqs = allreqs + guitestreqs

        for req in allreqs:
            if req.startswith('openmdao.'):
                _single_install(openmdao_cmds, req, bin_dir, failures)
            else:
                _single_install(cmds, req, bin_dir, failures)

%(make_dev_eggs)s

        # add any additional packages specified on the command line
        for req in options.reqs:
            _single_install(cmds, req, bin_dir, failures, dodeps=True)

        activate = os.path.join(bin_dir, 'activate')
        deactivate = os.path.join(bin_dir, 'deactivate')
        if is_win:
            source_command = ''
            python = ''
            openmdao = 'openmdao'
        else:
            source_command = '.'
            python = os.path.join(bin_dir, 'python')
            openmdao = os.path.join(bin_dir, 'openmdao')

%(make_docs)s
        if is_win: # retrieve MinGW DLLs from server
            try:
                _get_mingw_dlls(bin_dir)
            except Exception as err:
                print str(err)
                print "\\n\\n**** Failed to download MinGW DLLs, so OpenMDAO extension packages may fail to load."
                print "If you install MinGW yourself (including c,c++, and fortran compilers) and put "
                print "the MinGW bin directory in your path, that should fix the problem."
    except Exception as err:
        print "ERROR: build failed: %%s" %% str(err)
        sys.exit(-1)

    # If there are spaces in the install path lots of commands need to be
    # patched so Python can be found on Linux/Mac.
    abs_bin = os.path.abspath(bin_dir)
    if not is_win and ' ' in abs_bin:
        import stat
        shebang = '#!"%%s"\\n' %% os.path.join(abs_bin, 'python')
        print '\\nFixing scripts for spaces in install path'
        for path in sorted(glob.glob(os.path.join(bin_dir, '*'))):
            with open(path, 'r') as script:
                lines = script.readlines()
            if lines[0] == shebang:
                mode = os.stat(path).st_mode
                os.rename(path, path+'.orig')
                lines[0] = '#!/usr/bin/env python\\n'
                with open(path, 'w') as script:
                    script.writelines(lines)
                os.chmod(path, mode)

    abshome = os.path.abspath(home_dir)

    if failures:
        failures.sort()
        print '\\n\\n***** The following packages failed to install: %%s.' %% failures
        print
        print 'This may be an intermittent network problem and simply retrying'
        print 'could result in a successfull installation.  Without all'
        print 'packages at least some tests will likely fail, and without core'
        print 'packages such as Traits OpenMDAO will not function at all.'
        print
        if not activated:
            print 'If you would like to try using this installation anyway,'
            print 'from %%s type:\\n' %% abshome
            if is_win:
                print r'Scripts\\activate'
            else:
                print '. bin/activate'
            print '\\nto activate your environment.'

    else:
        print '\\n\\nThe OpenMDAO virtual environment has been installed in\\n %%s' %% abshome
        if not activated:
            print '\\nFrom %%s, type:\\n' %% abshome
            if is_win:
                print r'Scripts\\activate'
            else:
                print '. bin/activate'
            print '\\nto activate your environment and start using OpenMDAO.'

    sys.exit(1 if failures else 0)
    """

    reqs = set()
    guireqs = set()
    guitestreqs = set()

    version = '?.?.?'
    excludes = set(['setuptools', 'distribute', 'SetupDocs'] +
                   openmdao_prereqs)
    dists = working_set.resolve([
        Requirement.parse(r[0]) for r in openmdao_packages
        if r[0] != 'openmdao.gui'
    ])

    distnames = set([d.project_name for d in dists]) - excludes
    gui_dists = working_set.resolve([Requirement.parse('openmdao.gui')])
    guinames = set([d.project_name for d in gui_dists]) - distnames - excludes
    guitest_dists = working_set.resolve(
        [Requirement.parse('openmdao.gui[jsTest]')])
    guitest_dists.extend(
        working_set.resolve(
            [Requirement.parse('openmdao.gui[functionalTest]')]))
    guitestnames = set([d.project_name for d in guitest_dists
                        ]) - distnames - excludes - guinames

    try:
        setupdoc_dist = working_set.resolve([Requirement.parse('setupdocs')
                                             ])[0]
    except:
        setupdoc_dist = None

    for dist in dists:
        if dist.project_name not in distnames:
            continue
        if dist.project_name == 'openmdao.main':
            version = dist.version
        if options.dev:  # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                reqs.add('%s' % dist.as_requirement())
        else:
            reqs.add('%s' % dist.as_requirement())

    for dist in gui_dists:
        if dist.project_name not in guinames:
            continue
        if options.dev:  # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                guireqs.add('%s' % dist.as_requirement())
        else:
            guireqs.add('%s' % dist.as_requirement())

    for dist in guitest_dists:
        if dist.project_name not in guitestnames:
            continue
        if options.dev:  # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                guitestreqs.add('%s' % dist.as_requirement())
        else:
            guitestreqs.add('%s' % dist.as_requirement())

    # adding setupdocs req is a workaround to prevent Traits from looking elsewhere for it
    if setupdoc_dist:
        _reqs = [str(setupdoc_dist.as_requirement())]
    else:
        _reqs = ['setupdocs>=1.0']
    reqs = sorted(_reqs + list(reqs))
    guireqs = sorted(guireqs)
    guitestreqs = sorted(guitestreqs)

    # pin setuptools to this version
    setuptools_version = "0.9.5"
    setuptools_url = "https://openmdao.org/dists/setuptools-%s-py%s.egg" % (
        setuptools_version, sys.version[:3])

    optdict = {
        'mkdir_pkg':
        offline_[3],
        'extarg1':
        offline_[0],
        'extarg2':
        offline_[1],
        'dldir':
        offline_[2],
        'cmds_str':
        offline_[4],
        'openmdao_cmds_str':
        offline_[5],
        'reqs':
        reqs,
        'guireqs':
        guireqs,
        'guitestreqs':
        guitestreqs,
        'version':
        version,
        'url':
        options.findlinks,
        'make_dev_eggs':
        make_dev_eggs,
        'make_docs':
        make_docs,
        'adjust_options':
        _get_adjust_options(options, version, setuptools_url,
                            setuptools_version),
        'openmdao_prereqs':
        openmdao_prereqs,
    }

    dest = os.path.abspath(options.dest)
    if options.dev:
        scriptname = os.path.join(dest, f_prefix + 'go-openmdao-dev.py')
    else:
        scriptname = os.path.join(dest,
                                  f_prefix + 'go-openmdao-%s.py' % version)

    if os.path.isfile(scriptname):
        shutil.copyfile(scriptname, scriptname + '.old')
    with open(scriptname, 'wb') as f:
        # Pin the version of setuptools used.
        fixline = u"        egg_path = 'setuptools-*-py%s.egg' % sys.version[:3]"
        for line in virtualenv.create_bootstrap_script(script_str %
                                                       optdict).split('\n'):
            if line == fixline:
                line = line.replace('*', setuptools_version)
            elif ", '-U'" in line:  # remove forcing it to look for latest setuptools version
                line = line.replace(", '-U'", "")
            f.write('%s\n' % line)
    os.chmod(scriptname, 0755)
예제 #6
0
def _make_license_table(docdir, reqs=None):
    """
    Generates a file in docs/licenses/licenses_table.rst that
    contains a restructured text table with the name, license, and home-page of
    all distributions that openmdao depends on.
    """
    meta_names = ['name', 'version', 'license','home-page']
    headers = ['**Distribs Used by OpenMDAO**',
               '**Version**',
               '**License**',
               '**Link**']
    numcols = len(meta_names)
    data_templates = ["%s", "%s", "%s", "%s"]
    col_spacer = ' '
    max_col_width = 80
    excludes = [] #["openmdao.*"]
    license_fname = os.path.join(docdir,'licenses','licenses_table.txt')
    
    if reqs is None:
        reqs = [Requirement.parse(p) for p in packages]
    dists = working_set.resolve(reqs)
        
    metadict = {}
    for dist in dists:
        metadict[dist.project_name] = get_dist_metadata(dist)
    to_remove = set()
    for pattern in excludes:
        to_remove.update(fnmatch.filter(metadict.keys(), pattern))
    for rem in to_remove:
        del metadict[rem]
    for projname,meta in metadict.items():
        for i,name in enumerate(meta_names):
            try:
                meta[name] = data_templates[i] % str(meta[name])
            except KeyError:
                meta[name] = 'UNKNOWN'
        if meta['name'] == 'UNKNOWN':
            meta['name'] = projname
    # figure out sizes of table columns
    colwidths = [len(s)+1 for s in headers]
    for i,name in enumerate(meta_names):
        sz = max([len(m[name]) for m in metadict.values()])+1
        sz = min(sz, max_col_width)
        colwidths[i] = max(colwidths[i], sz)
    
    with open(license_fname, 'wb') as outfile:
        # write header
        outfile.write(_get_border_line(numcols, colwidths, char='='))
        for i,header in enumerate(headers):
            outfile.write(header+' '*(colwidths[i]-len(header)))
            outfile.write(col_spacer)
        outfile.write('\n')
        outfile.write(_get_border_line(numcols, colwidths, char='='))
        
        # write table data
        tups = [(k,v) for k,v in metadict.items()]
        tups = sorted(tups, lambda x,y: cmp(x[0].lower(), y[0].lower()))
        for j,tup in enumerate(tups):
            for i,name in enumerate(meta_names):
                outfile.write(_get_table_cell(tup[1][name], colwidths[i]))
                outfile.write(col_spacer)
            outfile.write('\n')
            if j<len(tups)-1:
                outfile.write(_get_border_line(numcols, colwidths, char='-'))
            
        # bottom border
        outfile.write(_get_border_line(numcols, colwidths, char='='))
        outfile.write('\n')
예제 #7
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    parser = OptionParser()
    parser.add_option("--dev", action="store_true", dest='dev', 
                      help="if present, a development script will be generated instead of a release script")
    parser.add_option("--dest", action="store", type="string", dest='dest', 
                      help="specify destination directory", default='.')
    parser.add_option("--offline", action="store", type="string", dest='offline', 
                      help="make offline gathering script", default='')    
    parser.add_option("-f", "--findlinks", action="store", type="string", 
                      dest="findlinks",
                      default='http://openmdao.org/dists',
                      help="default URL where openmdao packages and dependencies are searched for first (before PyPI)")
    
    (options, args) = parser.parse_args(args)
    
    if len(args) > 0:
        print 'unrecognized args: %s' % args
        parser.print_help()
        sys.exit(-1)

    if options.dev:
        openmdao_packages.extend(openmdao_dev_packages)
        sout = StringIO.StringIO()
        pprint.pprint(openmdao_packages, sout)
        pkgstr = sout.getvalue()
        make_dev_eggs = """
        # now install dev eggs for all of the openmdao packages
        topdir = os.path.abspath(os.path.dirname(__file__))
        startdir = os.getcwd()
        absbin = os.path.abspath(bin_dir)
        openmdao_packages = %s
        try:
            for pkg, pdir, _ in openmdao_packages:
                if not options.gui and pkg == 'openmdao.gui':
                    continue
                os.chdir(join(topdir, pdir, pkg))
                cmdline = [join(absbin, 'python'), 'setup.py', 
                           'develop', '-N'] + cmds
                try:
                    call_subprocess(cmdline, show_stdout=True, raise_on_returncode=True)
                except OSError:
                    failures.append(pkg)
        finally:
            os.chdir(startdir)
        """ % pkgstr
        make_docs = """
        if options.docs:
            if(os.system('%s %s && openmdao build_docs && deactivate' % (source_command, activate)) != 0):
                print "Failed to build the docs."
        else:
            print "\\nSkipping build of OpenMDAO docs.\\n"
        """
    else:  # making a release installer
        make_dev_eggs = ''
        make_docs = ''
        
    if options.offline == "gather":
        offline_ = ["'-zmaxd'", "'-zmaxd'", ", 'pkg'", "os.mkdir('pkg')", "['-f', url]", "['-f', openmdao_url]"]
        f_prefix = "gather-"
    elif options.offline == "installer":
        offline_ = ["'-Z'", "'-NZ'", '','', "['-H', 'None', '-f', options.findlinks]", "['-H', 'None', '-f', options.findlinks]"]
        f_prefix = "offline-"
    else:
        offline_ = ["'-Z'", "'-NZ'", '','', "['-f', url]", "['-f', openmdao_url]"]
        f_prefix = ""
        
         
        
    script_str = """

openmdao_prereqs = %(openmdao_prereqs)s

%(mkdir_pkg)s

def extend_parser(parser):
    parser.add_option("-r","--req", action="append", type="string", dest='reqs', 
                      help="specify additional required distributions", default=[])
    parser.add_option("--noprereqs", action="store_true", dest='noprereqs', 
                      help="don't check for any prerequisites, e.g., numpy or scipy")
    parser.add_option("--nogui", action="store_false", dest='gui', default=True,
                      help="do not install the openmdao graphical user interface and its dependencies")
    parser.add_option("--nodocs", action="store_false", dest='docs', default=True,
                      help="do not build the docs")
    parser.add_option("-f", "--findlinks", action="store", type="string", 
                      dest="findlinks",
                      help="default URL where openmdao packages and dependencies are searched for first (before PyPI)")
    parser.add_option("--testurl", action="store", type="string", dest='testurl', 
                      help="specify url where openmdao.* distribs are located (used for release testing only)")
                      
    # go back to old behavior that includes system site packages by default
    parser.set_defaults(system_site_packages=True)

%(adjust_options)s


def download(url, dest='.'):
    import urllib2
    dest = os.path.abspath(os.path.expanduser(os.path.expandvars(dest)))
    
    resp = urllib2.urlopen(url)
    outpath = os.path.join(dest, os.path.basename(url))
    bs = 1024*8
    with open(outpath, 'wb') as out:
        while True:
            block = resp.fp.read(bs)
            if block == '':
                break
            out.write(block)
    return outpath

def _get_mingw_dlls():
    # first, check if MinGW/bin is already in PATH
    for entry in sys.path:
        if os.path.isfile(os.path.join(entry, 'libgfortran-3.dll')):
            print 'MinGW is already installed, skipping download.'
            break
    else:
        import zipfile
        dest = os.path.dirname(sys.executable)
        zippath = download('http://openmdao.org/releases/misc/mingwdlls.zip')
        zipped = zipfile.ZipFile(zippath, 'r')
        zipped.extractall(dest)
        zipped.close()
        os.remove(zippath)
    
def _single_install(cmds, req, bin_dir, failures, dodeps=False):
    global logger
    if dodeps:
        extarg = %(extarg1)s
    else:
        extarg = %(extarg2)s
    cmdline = [join(bin_dir, 'easy_install'), extarg %(dldir)s] + cmds + [req]
        # pip seems more robust than easy_install, but won't install binary distribs :(
        #cmdline = [join(bin_dir, 'pip'), 'install'] + cmds + [req]
    #logger.debug("running command: %%s" %% ' '.join(cmdline))
    try:
        call_subprocess(cmdline, show_stdout=True, raise_on_returncode=True)
    except OSError:
        failures.append(req)

def _update_activate(bindir):
    _lpdict = {
        'linux2': 'LD_LIBRARY_PATH',
        'linux': 'LD_LIBRARY_PATH',
        'darwin': 'DYLD_LIBRARY_PATH',
        'win32': 'PATH',
    }
    libpathvname = _lpdict.get(sys.platform)
    if libpathvname:
        libfiles = []
        if sys.platform.startswith('win'):
            activate_base = 'activate.bat'
        else:
            activate_base = 'activate'
                
        absbin = os.path.abspath(bindir)
        activate_fname = os.path.join(absbin, activate_base)
        with open(activate_fname, 'r') as inp:
            content = inp.read()
            
        if 'get_full_libpath' not in content:
            if sys.platform.startswith('win'):
                content += '''\\nfor /f "delims=" %%%%A in ('get_full_libpath') do @set PATH=%%%%A\\n\\n'''
            else:
                content += "\\n%%s=$(get_full_libpath)\\nexport %%s\\n\\n" %% (libpathvname, libpathvname)
            
        with open(activate_fname, 'w') as out:
            out.write(content)
            

def after_install(options, home_dir):
    global logger, openmdao_prereqs
    
    reqs = %(reqs)s
    guireqs = %(guireqs)s
    guitestreqs = %(guitestreqs)s
    
    if options.findlinks is None:
        url = '%(url)s'
    else:
        url = options.findlinks
    # For testing we allow one to specify a url where the openmdao
    # package dists are located that may be different from the main
    # url where the dependencies are located. We do this because
    # setuptools only allows us to specify a single -f parameter,
    # which would force us to mirror the entire openmdao distribution
    # directory in order to test our releases because setuptools will
    # barf if it can't find everything in the same location (or on PyPI).
    # TODO: get rid of this after we quit using setuptools.
    if options.testurl:
        openmdao_url = options.testurl
    else:
        openmdao_url = url
    etc = join(home_dir, 'etc')
    if sys.platform == 'win32':
        lib_dir = join(home_dir, 'Lib')
        bin_dir = join(home_dir, 'Scripts')
    else:
        lib_dir = join(home_dir, 'lib', py_version)
        bin_dir = join(home_dir, 'bin')

    if not os.path.exists(etc):
        os.makedirs(etc)
        
    if sys.platform != 'win32':
        # Put lib64_path at front of paths rather than end.
        # As of virtualenv 1.8.2 this fix had not made it in the release.
        patched = False
        site_orig = join(lib_dir, 'site.py')
        site_patched = join(lib_dir, 'site-patched.py')
        with open(site_orig, 'r') as inp:
            with open(site_patched, 'w') as out:
                for line in inp:
                    if 'paths.append(lib64_path)' in line:
                        print 'Patching site.py...'
                        print '  found %%r' %% line
                        line = line.replace('append(', 'insert(0, ')
                        print '    new %%r' %% line
                        sys.stdout.flush()
                        patched = True
                    out.write(line)
        if patched:
            os.rename(site_orig, join(lib_dir, 'site-orig.py'))
            os.rename(site_patched, site_orig)

    failed_imports = []
    for pkg in openmdao_prereqs:
        try:
            __import__(pkg)
        except ImportError:
            failed_imports.append(pkg)
    if failed_imports:
        if options.noprereqs:
            print "\\n**** The following prerequisites could not be imported: %%s." %% failed_imports
            print "**** As a result, some OpenMDAO components will not work."
        else:
            print "ERROR: the following prerequisites could not be imported: %%s." %% failed_imports
            print "These must be installed in the system level python before installing OpenMDAO."
            print "To run a limited version of OpenMDAO without the prerequisites, try 'python %%s --noprereqs'" %% __file__
            sys.exit(-1)
    
    cmds = %(cmds_str)s
    openmdao_cmds = %(openmdao_cmds_str)s
    try:
        allreqs = reqs[:]
        failures = []
        if options.gui:
            allreqs = allreqs + guireqs
            allreqs = allreqs + guitestreqs 
            
        for req in allreqs:
            if req.startswith('openmdao.'):
                _single_install(openmdao_cmds, req, bin_dir, failures)
            else:
                _single_install(cmds, req, bin_dir, failures)
        
%(make_dev_eggs)s

        # add any additional packages specified on the command line
        for req in options.reqs:
            _single_install(cmds, req, bin_dir, failures, dodeps=True)

        activate = os.path.join(bin_dir, 'activate')
        deactivate = os.path.join(bin_dir, 'deactivate')
        source_command = "." if not sys.platform.startswith("win") else ""
        
%(make_docs)s
        if sys.platform.startswith('win'): # retrieve MinGW DLLs from server
            try:
                _get_mingw_dlls()
            except Exception as err:
                print str(err)
                print "\\n\\n**** Failed to download MinGW DLLs, so OpenMDAO extension packages may fail to load."
                print "If you install MinGW yourself (including c,c++, and fortran compilers) and put "
                print "the MinGW bin directory in your path, that should fix the problem."
    except Exception as err:
        print "ERROR: build failed: %%s" %% str(err)
        sys.exit(-1)
    
    _update_activate(bin_dir)
    
    abshome = os.path.abspath(home_dir)
    
    if failures:
        failmsg = ' (with failures).'
        failures.sort()
        print '\\n\\n***** The following packages failed to install: %%s.' %% failures
    else:
        failmsg = '.'
    print '\\n\\nThe OpenMDAO virtual environment has been installed in\\n %%s%%s' %% (abshome, failmsg)
    print '\\nFrom %%s, type:\\n' %% abshome
    if sys.platform == 'win32':
        print r'Scripts\\activate'
    else:
        print '. bin/activate'
    print "\\nto activate your environment and start using OpenMDAO."
    
    sys.exit(1 if failures else 0)
    """
    
    reqs = set()
    guireqs = set()
    guitestreqs = set()
    
    version = '?.?.?'
    excludes = set(['setuptools', 'distribute', 'SetupDocs']+openmdao_prereqs)
    dists = working_set.resolve([Requirement.parse(r[0]) 
                                   for r in openmdao_packages if r[0]!='openmdao.gui'])
    distnames = set([d.project_name for d in dists])-excludes
    gui_dists = working_set.resolve([Requirement.parse('openmdao.gui')])
    guinames = set([d.project_name for d in gui_dists])-distnames-excludes
    guitest_dists = working_set.resolve([Requirement.parse('openmdao.gui[jsTest]')])
    guitest_dists.extend(working_set.resolve([Requirement.parse('openmdao.gui[functionalTest]')]))
    guitestnames = set([d.project_name for d in guitest_dists])-distnames-excludes-guinames
    
    try:
        setupdoc_dist = working_set.resolve([Requirement.parse('setupdocs')])[0]
    except:
        setupdoc_dist = None
        
    for dist in dists:
        if dist.project_name not in distnames:
            continue
        if dist.project_name == 'openmdao.main':
            version = dist.version
        if options.dev: # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                reqs.add('%s' % dist.as_requirement())
        else:
            reqs.add('%s' % dist.as_requirement())
            
    for dist in gui_dists:
        if dist.project_name not in guinames:
            continue
        if options.dev: # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                guireqs.add('%s' % dist.as_requirement())
        else:
            guireqs.add('%s' % dist.as_requirement())

    for dist in guitest_dists:
        if dist.project_name not in guitestnames:
            continue
        if options.dev: # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                guitestreqs.add('%s' % dist.as_requirement())
        else:
            guitestreqs.add('%s' % dist.as_requirement())

    # adding setupdocs req is a workaround to prevent Traits from looking elsewhere for it
    if setupdoc_dist:
        _reqs = [str(setupdoc_dist.as_requirement())]
    else:
        _reqs = ['setupdocs>=1.0']
    reqs = _reqs + list(reqs) 
    guireqs = list(guireqs)
    guitestreqs = list(guitestreqs)
    
    optdict = { 
        'mkdir_pkg' : offline_[3],
        'extarg1' : offline_[0],
        'extarg2' : offline_[1],
        'dldir' : offline_[2],
        'cmds_str':offline_[4],
        'openmdao_cmds_str':offline_[5],
        'reqs': reqs, 
        'guireqs': guireqs,
        'guitestreqs': guitestreqs,
        'version': version, 
        'url': options.findlinks,
        'make_dev_eggs': make_dev_eggs,
        'make_docs': make_docs,
        'adjust_options': _get_adjust_options(options, version),
        'openmdao_prereqs': openmdao_prereqs,
    }
    
    dest = os.path.abspath(options.dest)
    if options.dev:
        scriptname = os.path.join(dest, f_prefix + 'go-openmdao-dev.py')
    else:
        scriptname = os.path.join(dest, f_prefix + 'go-openmdao-%s.py' % version)
        
    if os.path.isfile(scriptname):
        shutil.copyfile(scriptname, scriptname+'.old'
                        )
    with open(scriptname, 'wb') as f:
        f.write(virtualenv.create_bootstrap_script(script_str % optdict))
    os.chmod(scriptname, 0755)
예제 #8
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    parser = OptionParser()
    parser.add_option("--dev", action="store_true", dest='dev', 
                      help="if present, a development script will be generated instead of a release script")
    parser.add_option("--dest", action="store", type="string", dest='dest', 
                      help="specify destination directory", default='.')
    parser.add_option("--disturl", action="store", type="string", dest="disturl",
                      default='http://openmdao.org/dists',
                      help="OpenMDAO distribution URL (used for testing)")
    
    (options, args) = parser.parse_args(args)
    
    if len(args) > 0:
        print 'unrecognized args: %s' % args
        parser.print_help()
        sys.exit(-1)

    if options.dev:
        openmdao_packages.extend(openmdao_dev_packages)
        sout = StringIO.StringIO()
        pprint.pprint(openmdao_packages, sout)
        pkgstr = sout.getvalue()
        make_dev_eggs = """
        # now install dev eggs for all of the openmdao packages
        topdir = os.path.abspath(os.path.dirname(__file__))
        startdir = os.getcwd()
        absbin = os.path.abspath(bin_dir)
        openmdao_packages = %s
        try:
            for pkg, pdir, _ in openmdao_packages:
                os.chdir(join(topdir, pdir, pkg))
                cmdline = [join(absbin, 'python'), 'setup.py', 
                           'develop', '-N'] + cmds
                subprocess.check_call(cmdline)
        finally:
            os.chdir(startdir)
        """ % pkgstr
        wing = """
    # copy the wing project file into the virtualenv
    proj_template = join(topdir,'config','wing_proj_template.wpr')
    
    shutil.copy(proj_template, 
                join(abshome,'etc','wingproj.wpr'))
                
        """
    else:
        make_dev_eggs = ''
        wing = ''

    script_str = """

openmdao_prereqs = %(openmdao_prereqs)s

def extend_parser(parser):
    parser.add_option("-r","--req", action="append", type="string", dest='reqs', 
                      help="specify additional required distributions", default=[])
    parser.add_option("--disturl", action="store", type="string", dest='disturl', 
                      help="specify url where openmdao distribs are located")

%(adjust_options)s

def _single_install(cmds, req, bin_dir, dodeps=False):
    global logger
    if dodeps:
        extarg = '-Z'
    else:
        extarg = '-NZ'
    cmdline = [join(bin_dir, 'easy_install'), extarg] + cmds + [req]
        # pip seems more robust than easy_install, but won't install binary distribs :(
        #cmdline = [join(bin_dir, 'pip'), 'install'] + cmds + [req]
    logger.debug("running command: %%s" %% ' '.join(cmdline))
    subprocess.check_call(cmdline)

def after_install(options, home_dir):
    global logger, openmdao_prereqs
    
    reqs = %(reqs)s
    url = '%(url)s'
    # for testing we allow one to specify a url where the openmdao
    # package dists are located that may be different from the main
    # url where the dependencies are located. We do this because
    # setuptools only allows us to specify a single -f parameter,
    # which would force us to mirror the entire openmdao distribution
    # directory in order to test our releases because setuptools will
    # barf if it can't find everything in the same location (or on PyPI).
    # TODO: get rid of this after we quit using setuptools.
    if options.disturl:
        openmdao_url = options.disturl
    else:
        openmdao_url = '%(url)s'
    etc = join(home_dir, 'etc')
    if sys.platform == 'win32':
        lib_dir = join(home_dir, 'Lib')
        bin_dir = join(home_dir, 'Scripts')
    else:
        lib_dir = join(home_dir, 'lib', py_version)
        bin_dir = join(home_dir, 'bin')

    if not os.path.exists(etc):
        os.makedirs(etc)
        
    failed_imports = []
    for pkg in openmdao_prereqs:
        try:
            __import__(pkg)
        except ImportError:
            failed_imports.append(pkg)
    if failed_imports:
        logger.error("ERROR: the following prerequisites could not be imported: %%s." %% failed_imports)
        logger.error("These must be installed in the system level python before installing OpenMDAO.")
        sys.exit(-1)
    
    cmds = ['-f', url]
    openmdao_cmds = ['-f', openmdao_url]
    try:
        for req in reqs:
            if req.startswith('openmdao.'):
                _single_install(openmdao_cmds, req, bin_dir)
            else:
                _single_install(cmds, req, bin_dir)
        
%(make_dev_eggs)s

        # add any additional packages specified on the command line
        for req in options.reqs:
            _single_install(cmds, req, bin_dir, True)

    except Exception as err:
        logger.error("ERROR: build failed: %%s" %% str(err))
        sys.exit(-1)

    abshome = os.path.abspath(home_dir)
    
%(wing)s

    print '\\n\\nThe OpenMDAO virtual environment has been installed in %%s.' %% abshome
    print 'From %%s, type:\\n' %% abshome
    if sys.platform == 'win32':
        print r'Scripts\\activate'
    else:
        print '. bin/activate'
    print "\\nto activate your environment and start using OpenMDAO."
    """
    
    reqs = set()
    
    version = '?.?.?'
    dists = working_set.resolve([Requirement.parse(r[0]) for r in openmdao_packages])
    excludes = set(['setuptools', 'distribute']+openmdao_prereqs)
    for dist in dists:
        if dist.project_name == 'openmdao.main':
            version = dist.version
        if dist.project_name not in excludes:
            if options.dev: # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
                if not dist.project_name.startswith('openmdao.'):
                    reqs.add('%s' % dist.as_requirement())
            else:
                reqs.add('%s' % dist.as_requirement())

    reqs = list(reqs)
    
    optdict = { 
        'reqs': reqs, 
        'version': version, 
        'url': options.disturl,
        'make_dev_eggs': make_dev_eggs,
        'wing': wing,
        'adjust_options': _get_adjust_options(options, version),
        'openmdao_prereqs': openmdao_prereqs,
    }
    
    dest = os.path.abspath(options.dest)
    if options.dev:
        scriptname = os.path.join(dest,'go-openmdao-dev.py')
    else:
        scriptname = os.path.join(dest,'go-openmdao-%s.py' % version)
    with open(scriptname, 'wb') as f:
        f.write(virtualenv.create_bootstrap_script(script_str % optdict))
    os.chmod(scriptname, 0755)
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    parser = OptionParser()
    parser.add_option("--dev", action="store_true", dest='dev', 
                      help="if present, a development script will be generated instead of a release script")
    parser.add_option("--dest", action="store", type="string", dest='dest', 
                      help="specify destination directory", default='.')
    parser.add_option("-f", "--findlinks", action="store", type="string", 
                      dest="findlinks",
                      default='http://openmdao.org/dists',
                      help="default URL where openmdao packages and dependencies are searched for first (before PyPI)")
    
    (options, args) = parser.parse_args(args)
    
    if len(args) > 0:
        print 'unrecognized args: %s' % args
        parser.print_help()
        sys.exit(-1)

    if options.dev:
        openmdao_packages.extend(openmdao_dev_packages)
        sout = StringIO.StringIO()
        pprint.pprint(openmdao_packages, sout)
        pkgstr = sout.getvalue()
        make_dev_eggs = """
        # now install dev eggs for all of the openmdao packages
        topdir = os.path.abspath(os.path.dirname(__file__))
        startdir = os.getcwd()
        absbin = os.path.abspath(bin_dir)
        openmdao_packages = %s
        try:
            for pkg, pdir, _ in openmdao_packages:
                if not options.gui and pkg == 'openmdao.gui':
                    continue
                os.chdir(join(topdir, pdir, pkg))
                cmdline = [join(absbin, 'python'), 'setup.py', 
                           'develop', '-N'] + cmds
                try:
                    call_subprocess(cmdline, show_stdout=True, raise_on_returncode=True)
                except OSError:
                    failures.append(pkg)
        finally:
            os.chdir(startdir)
        """ % pkgstr
    else:  # making a release installer
        make_dev_eggs = ''

    script_str = """

openmdao_prereqs = %(openmdao_prereqs)s

def extend_parser(parser):
    parser.add_option("-r","--req", action="append", type="string", dest='reqs', 
                      help="specify additional required distributions", default=[])
    parser.add_option("--noprereqs", action="store_true", dest='noprereqs', 
                      help="don't check for any prerequisites, e.g., numpy or scipy")
    parser.add_option("--nogui", action="store_false", dest='gui', default=True,
                      help="do not install the openmdao graphical user interface and its dependencies")
    parser.add_option("-f", "--findlinks", action="store", type="string", 
                      dest="findlinks",
                      help="default URL where openmdao packages and dependencies are searched for first (before PyPI)")
    parser.add_option("--testurl", action="store", type="string", dest='testurl', 
                      help="specify url where openmdao.* distribs are located (used for release testing only)")
                      
    # hack to force use of setuptools for now because using 'distribute' causes issues
    os.environ['VIRTUALENV_USE_SETUPTOOLS'] = '1'

%(adjust_options)s


def download(url, dest='.'):
    import urllib2
    dest = os.path.abspath(os.path.expanduser(os.path.expandvars(dest)))
    
    resp = urllib2.urlopen(url)
    outpath = os.path.join(dest, os.path.basename(url))
    bs = 1024*8
    with open(outpath, 'wb') as out:
        while True:
            block = resp.fp.read(bs)
            if block == '':
                break
            out.write(block)
    return outpath

def _get_mingw_dlls():
    # first, check if MinGW/bin is already in PATH
    for entry in sys.path:
        if os.path.isfile(os.path.join(entry, 'libgfortran-3.dll')):
            print 'MinGW is already installed, skipping download.'
            break
    else:
        import zipfile
        dest = os.path.dirname(sys.executable)
        zippath = download('http://openmdao.org/releases/misc/mingwdlls.zip')
        zipped = zipfile.ZipFile(zippath, 'r')
        zipped.extractall(dest)
        zipped.close()
        os.remove(zippath)
    
def _single_install(cmds, req, bin_dir, failures, dodeps=False):
    global logger
    if dodeps:
        extarg = '-Z'
    else:
        extarg = '-NZ'
    cmdline = [join(bin_dir, 'easy_install'), extarg] + cmds + [req]
        # pip seems more robust than easy_install, but won't install binary distribs :(
        #cmdline = [join(bin_dir, 'pip'), 'install'] + cmds + [req]
    #logger.debug("running command: %%s" %% ' '.join(cmdline))
    try:
        call_subprocess(cmdline, show_stdout=True, raise_on_returncode=True)
    except OSError:
        failures.append(req)

def after_install(options, home_dir):
    global logger, openmdao_prereqs
    
    reqs = %(reqs)s
    guireqs = %(guireqs)s
    guitestreqs = %(guitestreqs)s
    
    if options.findlinks is None:
        url = '%(url)s'
    else:
        url = options.findlinks
    # for testing we allow one to specify a url where the openmdao
    # package dists are located that may be different from the main
    # url where the dependencies are located. We do this because
    # setuptools only allows us to specify a single -f parameter,
    # which would force us to mirror the entire openmdao distribution
    # directory in order to test our releases because setuptools will
    # barf if it can't find everything in the same location (or on PyPI).
    # TODO: get rid of this after we quit using setuptools.
    if options.testurl:
        openmdao_url = options.testurl
    else:
        openmdao_url = url
    etc = join(home_dir, 'etc')
    if sys.platform == 'win32':
        lib_dir = join(home_dir, 'Lib')
        bin_dir = join(home_dir, 'Scripts')
    else:
        lib_dir = join(home_dir, 'lib', py_version)
        bin_dir = join(home_dir, 'bin')

    if not os.path.exists(etc):
        os.makedirs(etc)
        
    failed_imports = []
    for pkg in openmdao_prereqs:
        try:
            __import__(pkg)
        except ImportError:
            failed_imports.append(pkg)
    if failed_imports:
        if options.noprereqs:
            print "\\n**** The following prerequisites could not be imported: %%s." %% failed_imports
            print "**** As a result, some OpenMDAO components will not work."
        else:
            print "ERROR: the following prerequisites could not be imported: %%s." %% failed_imports
            print "These must be installed in the system level python before installing OpenMDAO."
            print "To run a limited version of OpenMDAO without the prerequisites, try 'python %%s --noprereqs'" %% __file__
            sys.exit(-1)
    
    cmds = ['-f', url]
    openmdao_cmds = ['-f', openmdao_url]
    try:
        allreqs = reqs[:]
        failures = []
        if options.gui:
            allreqs = allreqs + guireqs
            # No GUI unit or functional testing on Windows at this time.
            if sys.platform != 'win32':
                allreqs = allreqs + guitestreqs 
            
        for req in allreqs:
            if req.startswith('openmdao.'):
                _single_install(openmdao_cmds, req, bin_dir, failures)
            else:
                _single_install(cmds, req, bin_dir, failures)
        
%(make_dev_eggs)s

        # add any additional packages specified on the command line
        for req in options.reqs:
            _single_install(cmds, req, bin_dir, failures, dodeps=True)

        if sys.platform.startswith('win'): # retrieve MinGW DLLs from server
            try:
                _get_mingw_dlls()
            except Exception as err:
                print str(err)
                print "\\n\\n**** Failed to download MinGW DLLs, so OpenMDAO extension packages may fail to load."
                print "If you install MinGW yourself (including c,c++, and fortran compilers) and put "
                print "the MinGW bin directory in your path, that should fix the problem."
    except Exception as err:
        print "ERROR: build failed: %%s" %% str(err)
        sys.exit(-1)

    abshome = os.path.abspath(home_dir)
    
    if failures:
        failmsg = ' (with failures).'
        failures.sort()
        print '\\n\\n***** The following packages failed to install: %%s.' %% failures
    else:
        failmsg = '.'
    print '\\n\\nThe OpenMDAO virtual environment has been installed in\\n %%s%%s' %% (abshome, failmsg)
    print '\\nFrom %%s, type:\\n' %% abshome
    if sys.platform == 'win32':
        print r'Scripts\\activate'
    else:
        print '. bin/activate'
    print "\\nto activate your environment and start using OpenMDAO."
    
    sys.exit(1 if failures else 0)
    """
    
    reqs = set()
    guireqs = set()
    guitestreqs = set()
    
    version = '?.?.?'
    excludes = set(['setuptools', 'distribute', 'SetupDocs']+openmdao_prereqs)
    dists = working_set.resolve([Requirement.parse(r[0]) 
                                   for r in openmdao_packages if r[0]!='openmdao.gui'])
    distnames = set([d.project_name for d in dists])-excludes
    gui_dists = working_set.resolve([Requirement.parse('openmdao.gui')])
    guinames = set([d.project_name for d in gui_dists])-distnames-excludes
    guitest_dists = working_set.resolve([Requirement.parse('openmdao.gui[jsTest]')])
    guitest_dists.extend(working_set.resolve([Requirement.parse('openmdao.gui[functionalTest]')]))
    guitestnames = set([d.project_name for d in guitest_dists])-distnames-excludes-guinames
    
    try:
        setupdoc_dist = working_set.resolve([Requirement.parse('setupdocs')])[0]
    except:
        setupdoc_dist = None
        
    for dist in dists:
        if dist.project_name not in distnames:
            continue
        if dist.project_name == 'openmdao.main':
            version = dist.version
        if options.dev: # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                reqs.add('%s' % dist.as_requirement())
        else:
            reqs.add('%s' % dist.as_requirement())
            
    for dist in gui_dists:
        if dist.project_name not in guinames:
            continue
        if options.dev: # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                guireqs.add('%s' % dist.as_requirement())
        else:
            guireqs.add('%s' % dist.as_requirement())

    for dist in guitest_dists:
        if dist.project_name not in guitestnames:
            continue
        if options.dev: # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                guitestreqs.add('%s' % dist.as_requirement())
        else:
            guitestreqs.add('%s' % dist.as_requirement())

    # adding setupdocs req is a workaround to prevent Traits from looking elsewhere for it
    if setupdoc_dist:
        _reqs = [str(setupdoc_dist.as_requirement())]
    else:
        _reqs = ['setupdocs>=1.0']
    reqs = _reqs + list(reqs) 
    guireqs = list(guireqs)
    guitestreqs = list(guitestreqs)
    
    optdict = { 
        'reqs': reqs, 
        'guireqs': guireqs,
        'guitestreqs': guitestreqs,
        'version': version, 
        'url': options.findlinks,
        'make_dev_eggs': make_dev_eggs,
        'adjust_options': _get_adjust_options(options, version),
        'openmdao_prereqs': openmdao_prereqs,
    }
    
    dest = os.path.abspath(options.dest)
    if options.dev:
        scriptname = os.path.join(dest,'go-openmdao-dev.py')
    else:
        scriptname = os.path.join(dest,'go-openmdao-%s.py' % version)
    if os.path.isfile(scriptname):
        shutil.copyfile(scriptname, scriptname+'.old'
                        )
    with open(scriptname, 'wb') as f:
        f.write(virtualenv.create_bootstrap_script(script_str % optdict))
    os.chmod(scriptname, 0755)
예제 #10
0
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)
예제 #11
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    parser = OptionParser()
    parser.add_option(
        "--dev",
        action="store_true",
        dest='dev',
        help=
        "if present, a development script will be generated instead of a release script"
    )
    parser.add_option("--dest",
                      action="store",
                      type="string",
                      dest='dest',
                      help="specify destination directory",
                      default='.')
    parser.add_option(
        "-f",
        "--findlinks",
        action="store",
        type="string",
        dest="findlinks",
        default='http://openmdao.org/dists',
        help=
        "default URL where openmdao packages and dependencies are searched for first (before PyPI)"
    )

    (options, args) = parser.parse_args(args)

    if len(args) > 0:
        print 'unrecognized args: %s' % args
        parser.print_help()
        sys.exit(-1)

    if options.dev:
        openmdao_packages.extend(openmdao_dev_packages)
        sout = StringIO.StringIO()
        pprint.pprint(openmdao_packages, sout)
        pkgstr = sout.getvalue()
        make_dev_eggs = """
        # now install dev eggs for all of the openmdao packages
        topdir = os.path.abspath(os.path.dirname(__file__))
        startdir = os.getcwd()
        absbin = os.path.abspath(bin_dir)
        openmdao_packages = %s
        try:
            for pkg, pdir, _ in openmdao_packages:
                if not options.gui and pkg == 'openmdao.gui':
                    continue
                os.chdir(join(topdir, pdir, pkg))
                cmdline = [join(absbin, 'python'), 'setup.py', 
                           'develop', '-N'] + cmds
                try:
                    call_subprocess(cmdline, show_stdout=True, raise_on_returncode=True)
                except OSError:
                    failures.append(pkg)
        finally:
            os.chdir(startdir)
        """ % pkgstr
    else:  # making a release installer
        make_dev_eggs = ''

    script_str = """

openmdao_prereqs = %(openmdao_prereqs)s

def extend_parser(parser):
    parser.add_option("-r","--req", action="append", type="string", dest='reqs', 
                      help="specify additional required distributions", default=[])
    parser.add_option("--noprereqs", action="store_true", dest='noprereqs', 
                      help="don't check for any prerequisites, e.g., numpy or scipy")
    parser.add_option("--nogui", action="store_false", dest='gui', default=True,
                      help="do not install the openmdao graphical user interface and its dependencies")
    parser.add_option("-f", "--findlinks", action="store", type="string", 
                      dest="findlinks",
                      help="default URL where openmdao packages and dependencies are searched for first (before PyPI)")
    parser.add_option("--testurl", action="store", type="string", dest='testurl', 
                      help="specify url where openmdao.* distribs are located (used for release testing only)")
                      
    # hack to force use of setuptools for now because using 'distribute' causes issues
    os.environ['VIRTUALENV_USE_SETUPTOOLS'] = '1'

%(adjust_options)s


def download(url, dest='.'):
    import urllib2
    dest = os.path.abspath(os.path.expanduser(os.path.expandvars(dest)))
    
    resp = urllib2.urlopen(url)
    outpath = os.path.join(dest, os.path.basename(url))
    bs = 1024*8
    with open(outpath, 'wb') as out:
        while True:
            block = resp.fp.read(bs)
            if block == '':
                break
            out.write(block)
    return outpath

def _get_mingw_dlls():
    # first, check if MinGW/bin is already in PATH
    for entry in sys.path:
        if os.path.isfile(os.path.join(entry, 'libgfortran-3.dll')):
            print 'MinGW is already installed, skipping download.'
            break
    else:
        import zipfile
        dest = os.path.dirname(sys.executable)
        zippath = download('http://openmdao.org/releases/misc/mingwdlls.zip')
        zipped = zipfile.ZipFile(zippath, 'r')
        zipped.extractall(dest)
        zipped.close()
        os.remove(zippath)
    
def _single_install(cmds, req, bin_dir, failures, dodeps=False):
    global logger
    if dodeps:
        extarg = '-Z'
    else:
        extarg = '-NZ'
    cmdline = [join(bin_dir, 'easy_install'), extarg] + cmds + [req]
        # pip seems more robust than easy_install, but won't install binary distribs :(
        #cmdline = [join(bin_dir, 'pip'), 'install'] + cmds + [req]
    #logger.debug("running command: %%s" %% ' '.join(cmdline))
    try:
        call_subprocess(cmdline, show_stdout=True, raise_on_returncode=True)
    except OSError:
        failures.append(req)

def after_install(options, home_dir):
    global logger, openmdao_prereqs
    
    reqs = %(reqs)s
    guireqs = %(guireqs)s
    guitestreqs = %(guitestreqs)s
    
    if options.findlinks is None:
        url = '%(url)s'
    else:
        url = options.findlinks
    # for testing we allow one to specify a url where the openmdao
    # package dists are located that may be different from the main
    # url where the dependencies are located. We do this because
    # setuptools only allows us to specify a single -f parameter,
    # which would force us to mirror the entire openmdao distribution
    # directory in order to test our releases because setuptools will
    # barf if it can't find everything in the same location (or on PyPI).
    # TODO: get rid of this after we quit using setuptools.
    if options.testurl:
        openmdao_url = options.testurl
    else:
        openmdao_url = url
    etc = join(home_dir, 'etc')
    if sys.platform == 'win32':
        lib_dir = join(home_dir, 'Lib')
        bin_dir = join(home_dir, 'Scripts')
    else:
        lib_dir = join(home_dir, 'lib', py_version)
        bin_dir = join(home_dir, 'bin')

    if not os.path.exists(etc):
        os.makedirs(etc)
        
    failed_imports = []
    for pkg in openmdao_prereqs:
        try:
            __import__(pkg)
        except ImportError:
            failed_imports.append(pkg)
    if failed_imports:
        if options.noprereqs:
            print "\\n**** The following prerequisites could not be imported: %%s." %% failed_imports
            print "**** As a result, some OpenMDAO components will not work."
        else:
            print "ERROR: the following prerequisites could not be imported: %%s." %% failed_imports
            print "These must be installed in the system level python before installing OpenMDAO."
            print "To run a limited version of OpenMDAO without the prerequisites, try 'python %%s --noprereqs'" %% __file__
            sys.exit(-1)
    
    cmds = ['-f', url]
    openmdao_cmds = ['-f', openmdao_url]
    try:
        allreqs = reqs[:]
        failures = []
        if options.gui:
            allreqs = allreqs + guireqs
            # No GUI unit or functional testing on Windows at this time.
            if sys.platform != 'win32':
                allreqs = allreqs + guitestreqs 
            
        for req in allreqs:
            if req.startswith('openmdao.'):
                _single_install(openmdao_cmds, req, bin_dir, failures)
            else:
                _single_install(cmds, req, bin_dir, failures)
        
%(make_dev_eggs)s

        # add any additional packages specified on the command line
        for req in options.reqs:
            _single_install(cmds, req, bin_dir, failures, dodeps=True)

        if sys.platform.startswith('win'): # retrieve MinGW DLLs from server
            try:
                _get_mingw_dlls()
            except Exception as err:
                print str(err)
                print "\\n\\n**** Failed to download MinGW DLLs, so OpenMDAO extension packages may fail to load."
                print "If you install MinGW yourself (including c,c++, and fortran compilers) and put "
                print "the MinGW bin directory in your path, that should fix the problem."
    except Exception as err:
        print "ERROR: build failed: %%s" %% str(err)
        sys.exit(-1)

    abshome = os.path.abspath(home_dir)
    
    if failures:
        failmsg = ' (with failures).'
        failures.sort()
        print '\\n\\n***** The following packages failed to install: %%s.' %% failures
    else:
        failmsg = '.'
    print '\\n\\nThe OpenMDAO virtual environment has been installed in\\n %%s%%s' %% (abshome, failmsg)
    print '\\nFrom %%s, type:\\n' %% abshome
    if sys.platform == 'win32':
        print r'Scripts\\activate'
    else:
        print '. bin/activate'
    print "\\nto activate your environment and start using OpenMDAO."
    
    sys.exit(1 if failures else 0)
    """

    reqs = set()
    guireqs = set()
    guitestreqs = set()

    version = '?.?.?'
    excludes = set(['setuptools', 'distribute', 'SetupDocs'] +
                   openmdao_prereqs)
    dists = working_set.resolve([
        Requirement.parse(r[0]) for r in openmdao_packages
        if r[0] != 'openmdao.gui'
    ])
    distnames = set([d.project_name for d in dists]) - excludes
    gui_dists = working_set.resolve([Requirement.parse('openmdao.gui')])
    guinames = set([d.project_name for d in gui_dists]) - distnames - excludes
    guitest_dists = working_set.resolve(
        [Requirement.parse('openmdao.gui[jsTest]')])
    guitest_dists.extend(
        working_set.resolve(
            [Requirement.parse('openmdao.gui[functionalTest]')]))
    guitestnames = set([d.project_name for d in guitest_dists
                        ]) - distnames - excludes - guinames

    try:
        setupdoc_dist = working_set.resolve([Requirement.parse('setupdocs')
                                             ])[0]
    except:
        setupdoc_dist = None

    for dist in dists:
        if dist.project_name not in distnames:
            continue
        if dist.project_name == 'openmdao.main':
            version = dist.version
        if options.dev:  # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                reqs.add('%s' % dist.as_requirement())
        else:
            reqs.add('%s' % dist.as_requirement())

    for dist in gui_dists:
        if dist.project_name not in guinames:
            continue
        if options.dev:  # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                guireqs.add('%s' % dist.as_requirement())
        else:
            guireqs.add('%s' % dist.as_requirement())

    for dist in guitest_dists:
        if dist.project_name not in guitestnames:
            continue
        if options.dev:  # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                guitestreqs.add('%s' % dist.as_requirement())
        else:
            guitestreqs.add('%s' % dist.as_requirement())

    # adding setupdocs req is a workaround to prevent Traits from looking elsewhere for it
    if setupdoc_dist:
        _reqs = [str(setupdoc_dist.as_requirement())]
    else:
        _reqs = ['setupdocs>=1.0']
    reqs = _reqs + list(reqs)
    guireqs = list(guireqs)
    guitestreqs = list(guitestreqs)

    optdict = {
        'reqs': reqs,
        'guireqs': guireqs,
        'guitestreqs': guitestreqs,
        'version': version,
        'url': options.findlinks,
        'make_dev_eggs': make_dev_eggs,
        'adjust_options': _get_adjust_options(options, version),
        'openmdao_prereqs': openmdao_prereqs,
    }

    dest = os.path.abspath(options.dest)
    if options.dev:
        scriptname = os.path.join(dest, 'go-openmdao-dev.py')
    else:
        scriptname = os.path.join(dest, 'go-openmdao-%s.py' % version)
    if os.path.isfile(scriptname):
        shutil.copyfile(scriptname, scriptname + '.old')
    with open(scriptname, 'wb') as f:
        f.write(virtualenv.create_bootstrap_script(script_str % optdict))
    os.chmod(scriptname, 0755)
예제 #12
0
파일: mkpseudo.py 프로젝트: hitej/meta-core
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)
예제 #13
0
        return 'with_'+name.replace('-','_')

    def fetch_build_eggs(self, requires):
        """Resolve pre-setup requirements"""
<<<<<<< HEAD
        resolved_dists = pkg_resources.working_set.resolve(
            pkg_resources.parse_requirements(requires),
            installer=self.fetch_build_egg,
            replace_conflicting=True,
        )
        for dist in resolved_dists:
            pkg_resources.working_set.add(dist, replace=True)
=======
        from pkg_resources import working_set, parse_requirements
        for dist in working_set.resolve(
            parse_requirements(requires), installer=self.fetch_build_egg,
            replace_conflicting=True
        ):
            working_set.add(dist, replace=True)
>>>>>>> e4baf504ede925f4f1e07d823c9b20b3d0dbe14c

    def finalize_options(self):
        _Distribution.finalize_options(self)
        if self.features:
            self._set_global_opts_from_features()

        for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
            value = getattr(self,ep.name,None)
            if value is not None:
                ep.require(installer=self.fetch_build_egg)
                ep.load()(self, ep.name, value)
        if getattr(self, 'convert_2to3_doctests', None):
예제 #14
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]

    parser = OptionParser()
    parser.add_option(
        "--dev",
        action="store_true",
        dest='dev',
        help=
        "if present, a development script will be generated instead of a release script"
    )
    parser.add_option("--dest",
                      action="store",
                      type="string",
                      dest='dest',
                      help="specify destination directory",
                      default='.')
    parser.add_option("--offline",
                      action="store",
                      type="string",
                      dest='offline',
                      help="make offline gathering script",
                      default='')
    parser.add_option(
        "-f",
        "--findlinks",
        action="store",
        type="string",
        dest="findlinks",
        default='http://openmdao.org/dists',
        help=
        "default URL where openmdao packages and dependencies are searched for first (before PyPI)"
    )

    (options, args) = parser.parse_args(args)

    if len(args) > 0:
        print 'unrecognized args: %s' % args
        parser.print_help()
        sys.exit(-1)

    if options.dev:
        openmdao_packages.extend(openmdao_dev_packages)
        sout = StringIO.StringIO()
        pprint.pprint(openmdao_packages, sout)
        pkgstr = sout.getvalue()
        make_dev_eggs = """
        # now install dev eggs for all of the openmdao packages
        topdir = os.path.abspath(os.path.dirname(__file__))
        startdir = os.getcwd()
        absbin = os.path.abspath(bin_dir)
        openmdao_packages = %s
        try:
            for pkg, pdir, _ in openmdao_packages:
                if not options.gui and pkg == 'openmdao.gui':
                    continue
                os.chdir(join(topdir, pdir, pkg))
                cmdline = [join(absbin, 'python'), 'setup.py', 
                           'develop', '-N'] + cmds
                try:
                    call_subprocess(cmdline, show_stdout=True, raise_on_returncode=True)
                except OSError:
                    failures.append(pkg)
        finally:
            os.chdir(startdir)
        """ % pkgstr
        make_docs = """
        if options.docs:
            if(os.system('%s %s && openmdao build_docs && deactivate' % (source_command, activate)) != 0):
                print "Failed to build the docs."
        else:
            print "\\nSkipping build of OpenMDAO docs.\\n"
        """
    else:  # making a release installer
        make_dev_eggs = ''
        make_docs = ''

    if options.offline == "gather":
        offline_ = [
            "'-zmaxd'", "'-zmaxd'", ", 'pkg'", "os.mkdir('pkg')",
            "['-f', url]", "['-f', openmdao_url]"
        ]
        f_prefix = "gather-"
    elif options.offline == "installer":
        offline_ = [
            "'-Z'", "'-NZ'", '', '', "['-H', 'None', '-f', options.findlinks]",
            "['-H', 'None', '-f', options.findlinks]"
        ]
        f_prefix = "offline-"
    else:
        offline_ = [
            "'-Z'", "'-NZ'", '', '', "['-f', url]", "['-f', openmdao_url]"
        ]
        f_prefix = ""

    script_str = """

openmdao_prereqs = %(openmdao_prereqs)s

%(mkdir_pkg)s

def extend_parser(parser):
    parser.add_option("-r","--req", action="append", type="string", dest='reqs', 
                      help="specify additional required distributions", default=[])
    parser.add_option("--noprereqs", action="store_true", dest='noprereqs', 
                      help="don't check for any prerequisites, e.g., numpy or scipy")
    parser.add_option("--nogui", action="store_false", dest='gui', default=True,
                      help="do not install the openmdao graphical user interface and its dependencies")
    parser.add_option("--nodocs", action="store_false", dest='docs', default=True,
                      help="do not build the docs")
    parser.add_option("-f", "--findlinks", action="store", type="string", 
                      dest="findlinks",
                      help="default URL where openmdao packages and dependencies are searched for first (before PyPI)")
    parser.add_option("--testurl", action="store", type="string", dest='testurl', 
                      help="specify url where openmdao.* distribs are located (used for release testing only)")
                      
    # go back to old behavior that includes system site packages by default
    parser.set_defaults(system_site_packages=True)

%(adjust_options)s


def download(url, dest='.'):
    import urllib2
    dest = os.path.abspath(os.path.expanduser(os.path.expandvars(dest)))
    
    resp = urllib2.urlopen(url)
    outpath = os.path.join(dest, os.path.basename(url))
    bs = 1024*8
    with open(outpath, 'wb') as out:
        while True:
            block = resp.fp.read(bs)
            if block == '':
                break
            out.write(block)
    return outpath

def _get_mingw_dlls():
    # first, check if MinGW/bin is already in PATH
    for entry in sys.path:
        if os.path.isfile(os.path.join(entry, 'libgfortran-3.dll')):
            print 'MinGW is already installed, skipping download.'
            break
    else:
        import zipfile
        dest = os.path.dirname(sys.executable)
        zippath = download('http://openmdao.org/releases/misc/mingwdlls.zip')
        zipped = zipfile.ZipFile(zippath, 'r')
        zipped.extractall(dest)
        zipped.close()
        os.remove(zippath)
    
def _single_install(cmds, req, bin_dir, failures, dodeps=False):
    global logger
    if dodeps:
        extarg = %(extarg1)s
    else:
        extarg = %(extarg2)s
    cmdline = [join(bin_dir, 'easy_install'), extarg %(dldir)s] + cmds + [req]
        # pip seems more robust than easy_install, but won't install binary distribs :(
        #cmdline = [join(bin_dir, 'pip'), 'install'] + cmds + [req]
    #logger.debug("running command: %%s" %% ' '.join(cmdline))
    try:
        call_subprocess(cmdline, show_stdout=True, raise_on_returncode=True)
    except OSError:
        failures.append(req)

def _update_activate(bindir):
    _lpdict = {
        'linux2': 'LD_LIBRARY_PATH',
        'linux': 'LD_LIBRARY_PATH',
        'darwin': 'DYLD_LIBRARY_PATH',
        'win32': 'PATH',
    }
    libpathvname = _lpdict.get(sys.platform)
    if libpathvname:
        libfiles = []
        if sys.platform.startswith('win'):
            activate_base = 'activate.bat'
        else:
            activate_base = 'activate'
                
        absbin = os.path.abspath(bindir)
        activate_fname = os.path.join(absbin, activate_base)
        with open(activate_fname, 'r') as inp:
            content = inp.read()
            
        if 'get_full_libpath' not in content:
            if sys.platform.startswith('win'):
                content += '''\\nfor /f "delims=" %%%%A in ('get_full_libpath') do @set PATH=%%%%A\\n\\n'''
            else:
                content += "\\n%%s=$(get_full_libpath)\\nexport %%s\\n\\n" %% (libpathvname, libpathvname)
            
        with open(activate_fname, 'w') as out:
            out.write(content)
            

def after_install(options, home_dir):
    global logger, openmdao_prereqs
    
    reqs = %(reqs)s
    guireqs = %(guireqs)s
    guitestreqs = %(guitestreqs)s
    
    if options.findlinks is None:
        url = '%(url)s'
    else:
        url = options.findlinks
    # For testing we allow one to specify a url where the openmdao
    # package dists are located that may be different from the main
    # url where the dependencies are located. We do this because
    # setuptools only allows us to specify a single -f parameter,
    # which would force us to mirror the entire openmdao distribution
    # directory in order to test our releases because setuptools will
    # barf if it can't find everything in the same location (or on PyPI).
    # TODO: get rid of this after we quit using setuptools.
    if options.testurl:
        openmdao_url = options.testurl
    else:
        openmdao_url = url
    etc = join(home_dir, 'etc')
    if sys.platform == 'win32':
        lib_dir = join(home_dir, 'Lib')
        bin_dir = join(home_dir, 'Scripts')
    else:
        lib_dir = join(home_dir, 'lib', py_version)
        bin_dir = join(home_dir, 'bin')

    if not os.path.exists(etc):
        os.makedirs(etc)
        
    if sys.platform != 'win32':
        # Put lib64_path at front of paths rather than end.
        # As of virtualenv 1.8.2 this fix had not made it in the release.
        patched = False
        site_orig = join(lib_dir, 'site.py')
        site_patched = join(lib_dir, 'site-patched.py')
        with open(site_orig, 'r') as inp:
            with open(site_patched, 'w') as out:
                for line in inp:
                    if 'paths.append(lib64_path)' in line:
                        print 'Patching site.py...'
                        print '  found %%r' %% line
                        line = line.replace('append(', 'insert(0, ')
                        print '    new %%r' %% line
                        sys.stdout.flush()
                        patched = True
                    out.write(line)
        if patched:
            os.rename(site_orig, join(lib_dir, 'site-orig.py'))
            os.rename(site_patched, site_orig)

    failed_imports = []
    for pkg in openmdao_prereqs:
        try:
            __import__(pkg)
        except ImportError:
            failed_imports.append(pkg)
    if failed_imports:
        if options.noprereqs:
            print "\\n**** The following prerequisites could not be imported: %%s." %% failed_imports
            print "**** As a result, some OpenMDAO components will not work."
        else:
            print "ERROR: the following prerequisites could not be imported: %%s." %% failed_imports
            print "These must be installed in the system level python before installing OpenMDAO."
            print "To run a limited version of OpenMDAO without the prerequisites, try 'python %%s --noprereqs'" %% __file__
            sys.exit(-1)
    
    cmds = %(cmds_str)s
    openmdao_cmds = %(openmdao_cmds_str)s
    try:
        allreqs = reqs[:]
        failures = []
        if options.gui:
            allreqs = allreqs + guireqs
            allreqs = allreqs + guitestreqs 
            
        for req in allreqs:
            if req.startswith('openmdao.'):
                _single_install(openmdao_cmds, req, bin_dir, failures)
            else:
                _single_install(cmds, req, bin_dir, failures)
        
%(make_dev_eggs)s

        # add any additional packages specified on the command line
        for req in options.reqs:
            _single_install(cmds, req, bin_dir, failures, dodeps=True)

        activate = os.path.join(bin_dir, 'activate')
        deactivate = os.path.join(bin_dir, 'deactivate')
        source_command = "." if not sys.platform.startswith("win") else ""
        
%(make_docs)s
        if sys.platform.startswith('win'): # retrieve MinGW DLLs from server
            try:
                _get_mingw_dlls()
            except Exception as err:
                print str(err)
                print "\\n\\n**** Failed to download MinGW DLLs, so OpenMDAO extension packages may fail to load."
                print "If you install MinGW yourself (including c,c++, and fortran compilers) and put "
                print "the MinGW bin directory in your path, that should fix the problem."
    except Exception as err:
        print "ERROR: build failed: %%s" %% str(err)
        sys.exit(-1)
    
    _update_activate(bin_dir)
    
    abshome = os.path.abspath(home_dir)
    
    if failures:
        failmsg = ' (with failures).'
        failures.sort()
        print '\\n\\n***** The following packages failed to install: %%s.' %% failures
    else:
        failmsg = '.'
    print '\\n\\nThe OpenMDAO virtual environment has been installed in\\n %%s%%s' %% (abshome, failmsg)
    print '\\nFrom %%s, type:\\n' %% abshome
    if sys.platform == 'win32':
        print r'Scripts\\activate'
    else:
        print '. bin/activate'
    print "\\nto activate your environment and start using OpenMDAO."
    
    sys.exit(1 if failures else 0)
    """

    reqs = set()
    guireqs = set()
    guitestreqs = set()

    version = '?.?.?'
    excludes = set(['setuptools', 'distribute', 'SetupDocs'] +
                   openmdao_prereqs)
    dists = working_set.resolve([
        Requirement.parse(r[0]) for r in openmdao_packages
        if r[0] != 'openmdao.gui'
    ])
    distnames = set([d.project_name for d in dists]) - excludes
    gui_dists = working_set.resolve([Requirement.parse('openmdao.gui')])
    guinames = set([d.project_name for d in gui_dists]) - distnames - excludes
    guitest_dists = working_set.resolve(
        [Requirement.parse('openmdao.gui[jsTest]')])
    guitest_dists.extend(
        working_set.resolve(
            [Requirement.parse('openmdao.gui[functionalTest]')]))
    guitestnames = set([d.project_name for d in guitest_dists
                        ]) - distnames - excludes - guinames

    try:
        setupdoc_dist = working_set.resolve([Requirement.parse('setupdocs')
                                             ])[0]
    except:
        setupdoc_dist = None

    for dist in dists:
        if dist.project_name not in distnames:
            continue
        if dist.project_name == 'openmdao.main':
            version = dist.version
        if options.dev:  # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                reqs.add('%s' % dist.as_requirement())
        else:
            reqs.add('%s' % dist.as_requirement())

    for dist in gui_dists:
        if dist.project_name not in guinames:
            continue
        if options.dev:  # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                guireqs.add('%s' % dist.as_requirement())
        else:
            guireqs.add('%s' % dist.as_requirement())

    for dist in guitest_dists:
        if dist.project_name not in guitestnames:
            continue
        if options.dev:  # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
            if not dist.project_name.startswith('openmdao.'):
                guitestreqs.add('%s' % dist.as_requirement())
        else:
            guitestreqs.add('%s' % dist.as_requirement())

    # adding setupdocs req is a workaround to prevent Traits from looking elsewhere for it
    if setupdoc_dist:
        _reqs = [str(setupdoc_dist.as_requirement())]
    else:
        _reqs = ['setupdocs>=1.0']
    reqs = _reqs + list(reqs)
    guireqs = list(guireqs)
    guitestreqs = list(guitestreqs)

    optdict = {
        'mkdir_pkg': offline_[3],
        'extarg1': offline_[0],
        'extarg2': offline_[1],
        'dldir': offline_[2],
        'cmds_str': offline_[4],
        'openmdao_cmds_str': offline_[5],
        'reqs': reqs,
        'guireqs': guireqs,
        'guitestreqs': guitestreqs,
        'version': version,
        'url': options.findlinks,
        'make_dev_eggs': make_dev_eggs,
        'make_docs': make_docs,
        'adjust_options': _get_adjust_options(options, version),
        'openmdao_prereqs': openmdao_prereqs,
    }

    dest = os.path.abspath(options.dest)
    if options.dev:
        scriptname = os.path.join(dest, f_prefix + 'go-openmdao-dev.py')
    else:
        scriptname = os.path.join(dest,
                                  f_prefix + 'go-openmdao-%s.py' % version)

    if os.path.isfile(scriptname):
        shutil.copyfile(scriptname, scriptname + '.old')
    with open(scriptname, 'wb') as f:
        f.write(virtualenv.create_bootstrap_script(script_str % optdict))
    os.chmod(scriptname, 0755)
예제 #15
0
def main(options):
    
    if options.dev:
        openmdao_packages.append(('openmdao.devtools', '', 'sdist'))
        sout = StringIO.StringIO()
        pprint.pprint(openmdao_packages, sout)
        pkgstr = sout.getvalue()
        make_dev_eggs = """
        # now install dev eggs for all of the openmdao packages
        topdir = os.path.abspath(os.path.dirname(__file__))
        startdir = os.getcwd()
        absbin = os.path.abspath(bin_dir)
        openmdao_packages = %s
        try:
            for pkg, pdir, _ in openmdao_packages:
                os.chdir(join(topdir, pdir, pkg))
                cmdline = [join(absbin, 'python'), 'setup.py', 
                           'develop', '-N'] + cmds
                subprocess.check_call(cmdline)
        finally:
            os.chdir(startdir)
        """ % pkgstr
        wing = """
    # copy the wing project file into the virtualenv
    proj_template = join(topdir,'config','wing_proj_template.wpr')
    
    shutil.copy(proj_template, 
                join(abshome,'etc','wingproj.wpr'))
                
        """
    else:
        make_dev_eggs = ''
        wing = ''

    if options.test:
        url = 'http://torpedo.grc.nasa.gov:31004/dists'
    else:
        url = 'http://openmdao.org/dists'

    script_str = """

openmdao_prereqs = %(openmdao_prereqs)s

def extend_parser(parser):
    parser.add_option("-r","--req", action="append", type="string", dest='reqs', 
                      help="specify additional required distributions", default=[])

%(adjust_options)s

def _single_install(cmds, req, bin_dir, dodeps=False):
    global logger
    if dodeps:
        extarg = '-Z'
    else:
        extarg = '-NZ'
    cmdline = [join(bin_dir, 'easy_install'), extarg] + cmds + [req]
        # pip seems more robust than easy_install, but won't install binary distribs :(
        #cmdline = [join(bin_dir, 'pip'), 'install'] + cmds + [req]
    logger.debug("running command: %%s" %% ' '.join(cmdline))
    subprocess.check_call(cmdline)

def after_install(options, home_dir):
    global logger, openmdao_prereqs
    
    reqs = %(reqs)s
    url = '%(url)s'
    etc = join(home_dir, 'etc')
    if sys.platform == 'win32':
        lib_dir = join(home_dir, 'Lib')
        bin_dir = join(home_dir, 'Scripts')
    else:
        lib_dir = join(home_dir, 'lib', py_version)
        bin_dir = join(home_dir, 'bin')

    if not os.path.exists(etc):
        os.makedirs(etc)
        
    failed_imports = []
    for pkg in openmdao_prereqs:
        try:
            __import__(pkg)
        except ImportError:
            failed_imports.append(pkg)
    if failed_imports:
        logger.error("ERROR: the following prerequisites could not be imported: %%s." %% failed_imports)
        logger.error("These must be installed in the system level python before installing OpenMDAO.")
        sys.exit(-1)
    
    cmds = ['-f', url]
    try:
        for req in reqs:
            _single_install(cmds, req, bin_dir)
        
%(make_dev_eggs)s

        # add any additional packages specified on the command line
        for req in options.reqs:
            _single_install(cmds, req, bin_dir, True)

    except Exception as err:
        logger.error("ERROR: build failed: %%s" %% str(err))
        sys.exit(-1)

    abshome = os.path.abspath(home_dir)
    
%(wing)s

    print '\\n\\nThe OpenMDAO virtual environment has been installed in %%s.' %% abshome
    print 'From %%s, type:\\n' %% abshome
    if sys.platform == 'win32':
        print r'Scripts\\activate'
    else:
        print '. bin/activate'
    print "\\nto activate your environment and start using OpenMDAO."
    """
    
    reqs = set()
    
    version = '?.?.?'
    dists = working_set.resolve([Requirement.parse(r[0]) for r in openmdao_packages])
    excludes = set(['setuptools', 'distribute']+openmdao_prereqs)
    for dist in dists:
        if dist.project_name == 'openmdao.main':
            version = dist.version
        if dist.project_name not in excludes:
            if options.dev: # in a dev build, exclude openmdao stuff because we'll make them 'develop' eggs
                if not dist.project_name.startswith('openmdao.'):
                    reqs.add('%s' % dist.as_requirement())
            else:
                reqs.add('%s' % dist.as_requirement())

    reqs = openmdao_prereqs + list(reqs)
    
    optdict = { 
        'reqs': reqs, 
        'version': version, 
        'url': url ,
        'make_dev_eggs': make_dev_eggs,
        'wing': wing,
        'adjust_options': get_adjust_options(options, version),
        'openmdao_prereqs': openmdao_prereqs,
    }
    
    dest = os.path.abspath(options.dest)
    if options.dev:
        scriptname = os.path.join(dest,'go-openmdao-dev.py')
    else:
        scriptname = os.path.join(dest,'go-openmdao-%s.py' % version)
    with open(scriptname, 'wb') as f:
        f.write(virtualenv.create_bootstrap_script(script_str % optdict))
    os.chmod(scriptname, 0755)
예제 #16
0
파일: plugin.py 프로젝트: zanachka/pancli
def ensure_plugin(plugin_name):
    logger.debug('ensure_plugin: %s', plugin_name)
    d = working_set.resolve([pkg_resources.Requirement(plugin_name)], 
                        plugin_env, 
                        install_plugin)
    logger.debug(d)