コード例 #1
0
    def run (self):
        '''
        Also install shared libraries and executables
        '''
        old_install_lib.run(self)

        lib = 'lib'
        if struct.calcsize('P') == 8:
            lib = 'lib64'
        build = self.get_finalized_command('build')
        build_shlib = self.get_finalized_command('build_shlib')
        install = self.get_finalized_command('install')
        self.verbose = options.DEBUG

        if install.prefix is None:
            target_dir = os.path.join(install.install_base, lib)
        else:
            target_dir = os.path.join(install.prefix, lib)
        mkdir(target_dir)
        if build_shlib.install_shared_libraries:
            for lib in build_shlib.install_shared_libraries:
                target = target_dir + os.sep
                source = os.path.join(build_shlib.build_clib, lib[1])
                self.copy_file(source, target)

        if self.distribution.extra_install_modules:
            ## prefer updated packages
            local_pkgs_dir = os.path.join(build.build_base,
                                          options.local_lib_dir)
            insertions = 0
            if os.path.exists(local_pkgs_dir):
                sys.path.insert(0, os.path.abspath(local_pkgs_dir))
                insertions += 1
                for ent in os.listdir(os.path.abspath(local_pkgs_dir)):
                    if os.path.isdir(os.path.join(local_pkgs_dir, ent)) and \
                            ent[-4:] == '.egg':
                        pth = os.path.join(local_pkgs_dir, ent)
                        sys.path.insert(0, os.path.abspath(pth))
                        insertions += 1

            module_dir = install.install_platlib
            for mod in self.distribution.extra_install_modules:
                if mod in EXCEPTIONS:
                    continue
                source = get_module_location(mod, local_pkgs_dir)
                if os.path.isdir(source):
                    self.copy_tree(source, os.path.join(module_dir, mod))
                else:
                    self.copy_file(source, module_dir)
            for _ in range(insertions):
                sys.path.pop(0)

        if self.distribution.extra_install_libraries:
            for pkg_tpl in self.distribution.extra_install_libraries:
                for lib_tpl in pkg_tpl[1]:
                    libpath = lib_tpl[0]
                    for libname in lib_tpl[1]:
                        for source in glob.glob(os.path.join(libpath,
                                                             libname + '*')):
                            self.copy_file(source, target_dir)
コード例 #2
0
ファイル: building.py プロジェクト: sean-m-brennan/pysysdevel
def configure_file(var_dict, filepath, newpath=None, suffix='.in',
                   style=DEFAULT_STYLE):
    '''
    Given a dictionary of environment variables and a path,
    replace all occurrences of @@{VAR} with the value of the VAR key.
    If style is AUTOCONF_STYLE, use the style $(VAR).
    If style is AUTOMAKE_STYLE, use the style @VAR@.
    VAR may not have whitespace in the string.
    '''
    if newpath is None:
        newpath = filepath[:-(len(suffix))]
    if os.path.exists(newpath) and \
            (os.path.getmtime(filepath) < os.path.getmtime(newpath)):
        ## i.e. original is older than existing generated file
        return
    if options.VERBOSE:
        print('Configuring ' + newpath)
    orig = open(filepath, 'r')
    newdir = os.path.dirname(newpath)
    if not os.path.exists(newdir):
        mkdir(newdir)
    new = open(newpath, 'w')
    for line in orig:
        line = nested_values(line, var_dict, style=style)
        new.write(line)
    orig.close()
    new.close()
コード例 #3
0
ファイル: fetching.py プロジェクト: sean-m-brennan/pysysdevel
def unarchive(archive, target, archive_dir=None):
    if archive_dir is None:
        archive_dir = options.download_dir
    here = os.path.abspath(os.getcwd())
    if not os.path.isabs(archive_dir):
        archive_dir = os.path.join(here, archive_dir)
    if not os.path.exists(os.path.join(options.target_build_dir, target)):
        mkdir(options.target_build_dir)
        os.chdir(options.target_build_dir)
        z, members = open_archive(archive, archive_dir)
        root = os.path.commonprefix(members)
        if root.endswith(os.sep):
            root = root[:-1]
        if root == '':
            root = target
            mkdir(target)
            os.chdir(target)
        if archive.endswith('.zip'):
            zipextractall(z)
        else:
            tarextractall(z)
        z.close()
        if root != target:
            shutil.move(root, target)
        os.chdir(here)
コード例 #4
0
ファイル: homebrew.py プロジェクト: sean-m-brennan/pysysdevel
 def install(self, environ, version, strict=False, locally=True):
     if not 'darwin' in platform.system().lower():
         return
     python_version = ''
     mkdir(options.target_build_dir)
     log = open(os.path.join(options.target_build_dir,
                             'homebrew_build.log'), 'w')
     if not self.found:
         check_call('ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"',
                    stdout=log, stderr=log)
     if not self.brews_found:
         call(['brew', 'doctor'], stdout=log, stderr=log)
         call(['brew', 'install', 'git'], stdout=log, stderr=log)
         for repo in self.repositories:
             call(['brew', 'tap', repo], stdout=log, stderr=log)
         call(['brew', 'install', 'python' + python_version, '--universal',
                     '--framework'], stdout=log, stderr=log)
         call([pip_executable(), 'install', 'numpy'],
                    stdout=log, stderr=log)
         call([pip_executable(), 'install', 'distribute'],
                    stdout=log, stderr=log)
         call(['brew', 'install', 'sip'], stdout=log, stderr=log)
         call(['brew', 'install', 'pyqt'], stdout=log, stderr=log)
         call([pip_executable(), 'install', 'py2app'],
                    stdout=log, stderr=log)
     log.close()
     if not self.is_installed(environ, version. strict):
         raise Exception("Homebrew installation failed.")
コード例 #5
0
    def run(self):
        environ = self.distribution.environment

        if self.sysdevel_server:
            for target in self.sysdevel_server:
                if self.distribution.verbose:
                    print('adding sysdevel support to ' + target)
                target_dir = os.path.join(os.path.abspath(self.build_lib),
                                          *target.split('.'))
                mkdir(target_dir)
                source_dir = SERVER_SUPPORT_DIR
                for mod in SERVER_SUPPORT_MODULES:
                    src_file = os.path.join(source_dir, mod + '.py.in')
                    if not os.path.exists(src_file):
                        src_file = src_file[:-3]
                    dst_file = os.path.join(target_dir, mod + '.py')
                    configure_file(environ, src_file, dst_file)


        if self.antlr_modules:
            here = os.getcwd()
            for grammar in self.antlr_modules:
                if self.distribution.verbose:
                    print('building antlr grammar "' + \
                        grammar.name + '" sources')
                ##TODO build in build_src, add to build_lib modules
                target = os.path.join(os.path.abspath(self.build_lib),
                                      grammar.directory)
                mkdir(target)
                source_dir = os.path.abspath(grammar.directory)
                os.chdir(target)

                reprocess = True
                ref = os.path.join(target, grammar.name + '2Py.py')
                if os.path.exists(ref):
                    reprocess = False
                    for src in grammar.sources:
                        src_path = os.path.join(source_dir, src)
                        if os.path.getmtime(ref) < os.path.getmtime(src_path):
                            reprocess = True
                if reprocess:
                    for src in grammar.sources:
                        ## ANTLR cannot parse from a separate directory
                        shutil.copy(os.path.join(source_dir, src), '.')
                        cmd_line = list(environ['ANTLR'])
                        cmd_line.append(src)
                        status = subprocess.call(cmd_line)
                        if status != 0:
                            raise Exception("Command '" + str(cmd_line) +
                                            "' returned non-zero exit status "
                                            + str(status))
                    ## Cleanup so that it's only Python modules
                    for f in glob.glob('*.g'):
                        os.unlink(f)
                    for f in glob.glob('*.tokens'):
                        os.unlink(f)
                os.chdir(here)

        if self.distribution.has_ext_modules():
            _build_src.run(self)
コード例 #6
0
def autotools_install_without_fetch(environ, src_dir, locally=True,
                                    extra_cfg=None, addtnl_env=None):
    if extra_cfg is None:
        extra_cfg = []
    if addtnl_env is None:
        addtnl_env = dict()
    here = os.path.abspath(os.getcwd())

    if locally:
        prefix = os.path.abspath(options.target_build_dir)
        if not prefix in options.local_search_paths:
            options.add_local_search_path(prefix)
    else:
        prefix = options.global_prefix
    prefix = convert2unixpath(prefix)  ## MinGW shell strips backslashes

    build_dir = os.path.join(options.target_build_dir,
                             src_dir)  ## build in-place
    mkdir(build_dir)
    os.chdir(build_dir)
    log = open('build.log', 'w')
    try:
        if 'windows' in platform.system().lower():
            ## Assumes MinGW present, detected, and loaded in environment
            if not os.path.exists('configure'):
                mingw_check_call(environ, ['autoreconf', '-i'],
                                 stdout=log, stderr=log)
            mingw_check_call(environ, ['./configure',
                                       '--prefix="' + prefix + '"'] +
                             extra_cfg, stdout=log, stderr=log,
                             addtnl_env=addtnl_env)
            mingw_check_call(environ, ['make'], stdout=log, stderr=log,
                             addtnl_env=addtnl_env)
            try:
                mingw_check_call(environ, ['make', 'install'],
                                 stdout=log, stderr=log, addtnl_env=addtnl_env)
            except subprocess.CalledProcessError:
                pass
        else:
            os_environ = os.environ.copy()
            os_environ = dict(list(os_environ.items()) +
                              list(addtnl_env.items()))
            if not os.path.exists('configure'):
                check_call(['autoreconf', '-i'], stdout=log, stderr=log)
            check_call(['./configure', '--prefix=' + prefix] + extra_cfg,
                       stdout=log, stderr=log, env=os_environ)
            check_call(['make'], stdout=log, stderr=log, env=os_environ)
            try:
                if locally:
                    check_call(['make', 'install'], stdout=log, stderr=log,
                               env=os_environ)
                else:
                    admin_check_call(['make', 'install'], stdout=log,
                                     stderr=log, addtnl_env=addtnl_env)
            except subprocess.CalledProcessError:
                pass
    finally:
        log.close()
        os.chdir(here)
コード例 #7
0
def is_pypi_listed(pkg):
    if not os.path.exists(options.target_build_dir):
        mkdir(options.target_build_dir)
    listing = os.path.join(options.target_build_dir, '.' + pkg + '_list_test')
    try:
        urlretrieve(pypi_url(pkg, False), listing)
        return True
    except (DownloadError, URLError, HTTPError, ContentTooShortError):
        return False
コード例 #8
0
ファイル: fetching.py プロジェクト: sean-m-brennan/pysysdevel
def zipextractall(zip_file):
    ## zip_file.extractall not in 2.4
    for name in zip_file.namelist():
        (dirname, filename) = os.path.split(name)
        if not os.path.exists(dirname):
            mkdir(dirname)
        if not filename == '':
            f = open(name, 'w')
            f.write(zip_file.read(name))
            f.close()
コード例 #9
0
 def run (self):
     old_data.run(self)
     mkdir(self.data_install_dir)
     if (not hasattr(self.distribution, 'using_py2exe') or \
             not self.distribution.using_py2exe) and self.data_dirs:
         for tpl in self.data_dirs:
             target = os.path.join(self.data_install_dir, tpl[0])
             for d in tpl[1]:
                 copy_tree(d, target, excludes=['.svn*', 'CVS*',
                                                'Makefile*'])
コード例 #10
0
ファイル: fetching.py プロジェクト: sean-m-brennan/pysysdevel
def fetch(website, remote, local, dwnld_dir=options.download_dir, force=False):
    mkdir(dwnld_dir)
    set_downloading_file(remote)
    if force or not os.path.exists(os.path.join(dwnld_dir, local)):
        url = website + '/' + remote
        if website.endswith('/'):
            url = website + remote
        urlretrieve(url, os.path.join(dwnld_dir, local), download_progress)
        if options.VERBOSE:
            sys.stdout.write('\n')
コード例 #11
0
ファイル: fruit.py プロジェクト: sean-m-brennan/pysysdevel
    def install(self, environ, version, strict=False, locally=True):
        if not self.found:
            src_dir = self.download(environ, version, strict)
            source_dir = os.path.join(options.target_build_dir, src_dir, "src")
            install_dir = os.path.abspath(options.target_build_dir, "src", "fruit")
            mkdir(install_dir)
            for src in self.sources:
                shutil.copy(os.path.join(source_dir, src), os.path.join(install_dir, src))

            if not self.is_installed(environ, version, strict):
                raise Exception("FRUIT installation failed.")
コード例 #12
0
def save_cache(environ):
    cache_file = os.path.join(options.target_build_dir, '.cache')
    if not os.path.isdir(options.target_build_dir):
        if os.path.exists(options.target_build_dir):
            os.remove(options.target_build_dir)
        mkdir(options.target_build_dir)
    cache = open(cache_file, 'wb')
    cached = dict()
    cached['local_search_paths'] = options.local_search_paths
    cached['environment'] = environ
    json.dump(cached, cache)
    cache.close()
コード例 #13
0
def global_install(what, website_tpl, winstaller=None,
                   brew=None, port=None, deb=None, rpm=None):
    sys.stdout.write('INSTALLING ' + what + ' in the system\n')
    sys.stdout.flush()
    mkdir(options.target_build_dir)
    if website_tpl is None:
        website_tpl = ('','')
    log = open(os.path.join(options.target_build_dir, what + '.log'), 'w')
    if 'windows' in platform.system().lower() and winstaller:
        fetch(''.join(website_tpl), winstaller, winstaller)
        installer = os.path.join(options.download_dir, winstaller)
        try:
            admin_check_call(installer, stdout=log, stderr=log)
        except subprocess.CalledProcessError:
            ## some installers do not exit cleanly
            pass

    elif 'darwin' in platform.system().lower():
        if system_uses_homebrew() and brew:
            check_call(['brew', 'install',] + brew.split(),
                                  stdout=log, stderr=log)

        elif system_uses_macports() and port:
            admin_check_call(['port', 'install',] + port.split(),
                             stdout=log, stderr=log)
        else:
            log.close()
            raise PrerequisiteError('Unsupported OSX pkg manager. Install ' +
                                    what + ' by hand. See ' + website_tpl[0])

    elif 'linux' in platform.system().lower():
        if system_uses_apt_get() and deb:
            admin_check_call(['apt-get', 'install',] + deb.split(),
                             stdout=log, stderr=log)
        elif system_uses_yum() and rpm:
            admin_check_call(['yum', 'install',] + rpm.split(),
                             stdout=log, stderr=log)
        else:
            log.close()
            raise PrerequisiteError('Unsupported Linux flavor. Install ' +
                                    what + ' by hand. See ' + website_tpl[0])
    else:
        log.close()
        raise PrerequisiteError('Unsupported platform (' + platform.system() +
                                '). Install ' + what + ' by hand. See ' +
                                website_tpl[0])
    log.close()
コード例 #14
0
ファイル: atlas.py プロジェクト: sean-m-brennan/pysysdevel
 def install(self, environ, version, strict=False, locally=True):
     if not self.found:
         if locally or 'windows' in platform.system().lower():
             ## NB: broken on Windows!
             src_dir = self.download(environ, version, strict)
             here = os.path.abspath(os.getcwd())
             if locally:
                 prefix = os.path.abspath(options.target_build_dir)
                 if not prefix in options.local_search_paths:
                     options.add_local_search_path(prefix)
             else:
                 prefix = options.global_prefix
             prefix = convert2unixpath(prefix)  ## MinGW shell strips backslashes
             build_dir = os.path.join(options.target_build_dir,
                                      src_dir, '_build')
             mkdir(build_dir)
             os.chdir(build_dir)
             log = open('build.log', 'w')
             if 'windows' in platform.system().lower():
                 # Assumes MinGW present, detected, and loaded in environment
                 mingw_check_call(environ, ['../configure',
                                            '--prefix="' + prefix + '"',
                                            '--shared', #'-O ',
                                            '-b 32', '-Si nocygin 1'],
                                  stdout=log, stderr=log)
                 mingw_check_call(environ, ['make'], stdout=log, stderr=log)
                 mingw_check_call(environ, ['make', 'install'],
                                  stdout=log, stderr=log)
             else:
                 check_call(['../configure', '--prefix=' + prefix,
                             '--shared'], stdout=log, stderr=log)
                 check_call(['make'], stdout=log, stderr=log)
                 if locally:
                     check_call(['make', 'install'], stdout=log, stderr=log)
                 else:
                     admin_check_call(['make', 'install'],
                                      stdout=log, stderr=log)
             log.close()
             os.chdir(here)
         else:
             global_install('ATLAS', None,
                            ## part of XCode
                            deb='libatlas-dev', rpm='atlas-devel')
         if not self.is_installed(environ, version, strict):
             raise Exception('ATLAS installation failed.')
コード例 #15
0
    def run(self):
        mkdir(self.build_dir)
        if self.create_scripts:
            if not self.scripts:
                self.scripts = []
            for tpl in self.create_scripts:
                outfile = os.path.join(self.build_dir, os.path.basename(tpl[0]))
                create_runscript(tpl[1], tpl[2], outfile, tpl[3])
                self.scripts.append(outfile)

            prev_list = list(self.scripts)
            for s in prev_list:
                if '.py' in s:
                    create_script_wrapper(s, self.build_dir)
                    self.scripts.append(s)

        if self.scripts:
            self.copy_scripts()
コード例 #16
0
def pypi_archive(which, version):
    try:
        all_versions = available_versions(which, pypi_url(which),
                                          which + '-*', True)
        if version is None or not version in all_versions:
            print('Warning: version ' + str(version) + ' of ' + which +
                  ' is not available.')
            version = earliest_pypi_version(which)
    except:
        raise DownloadError('No PyPi version of ' + which + ' available.')
    if version is None:
        raise DownloadError('No PyPi version of ' + which + ' available.')
    ex = None
    try:
        if not os.path.exists(options.target_build_dir):
            mkdir(options.target_build_dir)
        listing = os.path.join(options.target_build_dir, '.' + which + '_list')
        if not os.path.exists(listing):
            urlretrieve(pypi_url(which), listing)
        f = open(listing, 'r')
        contents = f.read()
        f.close()
        l = len(which + '-' + version)
        idx = contents.find(which + '-' + version)
        while idx >= 0:
            for archive in archive_types:
                if contents[idx+l:].startswith(archive):
                    return archive
            idx = contents.find(which + '-' + version, idx+1)
        raise DownloadError('Invalid PyPi page for ' + which + '.')
    except (DownloadError, URLError, HTTPError, ContentTooShortError) as e:
        ex = e

    ## Default to whatever is in the third_party directory
    file_list = glob.glob(os.path.join(options.download_dir, which + '*'))
    for f in file_list:
        for archive in archive_types:
            if archive in f:
                return archive
    if ex:
        raise ex
    raise DownloadError('No PyPi version of ' + which + ' available.')
コード例 #17
0
def create_breathe_stylesheet(dirname):
    dirs = os.path.split(dirname)
    if (dirs[1] == '' and not dirs[0].endswith('_static')) or \
            (dirs[1] != '' and dirs[1] != '_static'):
        dirname = os.path.join(dirname, '_static')
    mkdir(dirname)
    f = open(os.path.join(dirname, 'breathe.css'), 'w')
    f.write('''
/* -- breathe specific styles ----------------------------------------------- */

/* So enum value descriptions are displayed inline to the item */
.breatheenumvalues li tt + p {
	display: inline;
}

/* So parameter descriptions are displayed inline to the item */
.breatheparameterlist li tt + p {
	display: inline;
}

''')
    f.close()
コード例 #18
0
ファイル: macports.py プロジェクト: sean-m-brennan/pysysdevel
 def install(self, environ, version, strict=False, locally=True):
     if not 'darwin' in platform.system().lower():
         return
     mkdir(options.target_build_dir)
     log = open(os.path.join(options.target_build_dir,
                             'macports_setup.log'), 'w')
     python_version = '26'  ## Hard coded due to wxPython
     if not self.found:
         if version is None:
             version = '2.1.3'
         website = ('https://distfiles.macports.org/MacPorts/',)
         src_dir = 'MacPorts-' + str(version)
         archive = src_dir + '.tar.gz'
         autotools_install(environ, website, archive, src_dir, False)
         patch_file('/opt/local/share/macports/Tcl/port1.0/portconfigure.tcl',
                    'default configure.ldflags',
                    '{-L${prefix}/lib}',
                    '{"-L${prefix}/lib -Xlinker -headerpad_max_install_names"}')
         patch_file('/opt/local/etc/macports/macports.conf',
                    'build_arch  i386', '#', '')  ## Also due to wxPython
         admin_check_call(['port', 'selfupdate'], stdout=log, stderr=log)
     if not self.ports_found:
         admin_check_call(['port', 'install', 'python' + python_version,
                           'python_select'], stdout=log, stderr=log)
         admin_check_call(['port', 'select', '--set', 'python',
                           'python' + python_version],
                          stdout=log, stderr=log)
         admin_check_call(['port', 'install',
                           'py' + python_version + '-numpy'],
                          stdout=log, stderr=log)
         admin_check_call(['port', 'install',
                           'py' + python_version + '-py2app'],
                          stdout=log, stderr=log)
     log.close()
     if not self.is_installed(environ, version, strict):
         raise Exception("Macports installation failed.")
コード例 #19
0
ファイル: __init__.py プロジェクト: sean-m-brennan/pysysdevel
def configure_system(
    prerequisite_list,
    version,
    required_python_version="2.4",
    install=None,
    quiet=False,
    sublevel=None,
    out=sys.stdout,
    err=sys.stderr,
    locally=None,
    download=None,
    options=dict(),
):
    """
    Given a list of required software and optionally a Python version,
    verify that python is the proper version and that
    other required software is installed.
    Install missing prerequisites that have an installer defined.
    """
    if locally is None:  ## parameter value overrides
        if "locally" in options.keys():
            locally = options["locally"]
        else:
            locally = True  ## default value
    if install is None:  ## parameter value overrides
        if "install" in options.keys():
            install = options["install"]
        else:
            install = True  ## default value
    if download is None:  ## parameter value overrides
        if "download" in options.keys():
            download = options["download"]
        else:
            download = False  ## default value
    if sublevel is None:  ## parameter value overrides
        if "sublevel" in options.keys():
            opts.set_top_level(options["sublevel"])

    environment = dict()
    try:
        environment = read_cache()
        skip = False
        for arg in sys.argv:
            if arg.startswith("clean"):
                skip = True
                quiet = True

        pyver = simplify_version(platform.python_version())
        reqver = simplify_version(required_python_version)
        if pyver < reqver:
            raise FatalError("Python version >= " + reqver + " is required.  " + "You are running version " + pyver)

        if not quiet:
            out.write("CONFIGURE  ")
            if len(environment):
                out.write("(from cache)")
            out.write("\n")

        environment["PACKAGE_VERSION"] = version

        prerequisite_list.insert(0, "httpsproxy_urllib2")
        if (
            "windows" in platform.system().lower()
            and in_prerequisites("mingw", prerequisite_list)
            and in_prerequisites("boost", prerequisite_list)
            and not in_prerequisites("msvcrt", prerequisite_list)
        ):
            err.write("WARNING: if you're using the boost-python DLL, " + "also add 'msvcrt' as a prerequisite.\n")
        if (
            "darwin" in platform.system().lower()
            and not in_prerequisites("macports", prerequisite_list)
            and not in_prerequisites("homebrew", prerequisite_list)
        ):
            if system_uses_macports():
                prerequisite_list.insert(0, "macports")
            elif system_uses_homebrew():
                prerequisite_list.insert(0, "homebrew")
            else:
                err.write(
                    "WARNING: neither MacPorts nor Homebrew "
                    + "detected. All required libraries will be "
                    + "built locally.\n"
                )

        for help_name in prerequisite_list:
            if len(help_name) > 0:
                environment = find_package_config(
                    help_name, __run_helper__, environment, skip, install, quiet, out, err, locally, download
                )
        save_cache(environment)
    except Exception:  # pylint: disable=W0703
        logfile = os.path.join(opts.target_build_dir, "config.log")
        if not os.path.exists(opts.target_build_dir):
            mkdir(opts.target_build_dir)
        log = open(logfile, "a")
        log.write("** Configuration error. **\n" + traceback.format_exc())
        log.close()
        err.write(
            "Configuration error; see "
            + logfile
            + " for details.\n"
            + "If the build fails, run 'python setup.py dependencies "
            + "--show'\nand install the listed packages by hand.\n"
        )
        raise
    return environment
コード例 #20
0
def install_pypkg_without_fetch(name, env=None, src_dir=None, locally=True,
                                patch=None, extra_cmds=None, extra_args=None,
                                not_python=False):
    compiler = []
    if 'windows' in platform.system().lower():
        # TODO compiler=mingw32 iff windows is using mingw (handle vcpp also?)
        compiler.append('--compiler=mingw32')
    if src_dir is None:
        src_dir = name
    if extra_cmds is None:
        extra_cmds = []
    if extra_args is None:
        extra_args = []
    here = os.path.abspath(os.getcwd())
    target_dir = os.path.abspath(options.target_build_dir)
    target_lib_dir = os.path.join(target_dir, options.local_lib_dir)

    if not os.path.exists(os.path.join(target_dir, src_dir)):
        mkdir(os.path.join(target_dir, src_dir))
    if patch:
        patch(os.path.join(target_dir, src_dir))

    if options.VERBOSE:
        sys.stdout.write('PREREQUISITE ' + name + ' ')
    if not os.path.exists(target_lib_dir):
        os.makedirs(target_lib_dir)
    try:
        os.chdir(os.path.join(target_dir, src_dir))
        environ = os.environ.copy()
        shell = False
        if 'windows' in platform.system().lower():
            shell = True
        if env:
            for e in env:
                (key, value) = e.split('=')
                environ[key] = value
        environ['LDFLAGS'] = '-shared'
        if locally:
            environ['PYTHONPATH'] = target_lib_dir
            if not_python:
                cmd_line = [sys.executable, 'setup.py'] + extra_cmds + \
                           ['build'] + compiler + ['install',
                            '--prefix=' + target_dir,] + extra_args
            else:
                cmd_line = [sys.executable, 'setup.py'] + extra_cmds + \
                           ['build'] + compiler + ['install_lib',
                            '--install-dir=' + target_lib_dir,] + extra_args
        else:
            sudo_prefix = []
            if not as_admin():
                sudo_prefix = ['sudo']
            cmd_line = sudo_prefix + [sys.executable, 'setup.py'] + \
                extra_cmds + ['build'] + compiler + ['install'] + extra_args
        log_file = os.path.join(target_dir, name + '.log')
        log = open(log_file, 'w')
        log.write(str(cmd_line) + '\n')
        if options.VERBOSE:
            log.write('Env: ' + str(environ) + '\n')
        log.write('\n')
        log.flush()
        status = install_pypkg_process(cmd_line, environ, log, shell)
        failed = False
        if status != 0:
            log = open(log_file, 'r')
            prefix_error = False
            err = "error: must supply either home or prefix/exec-prefix -- not both"
            for line in log:
                if err in line:
                    prefix_error = True
                break
            log.close()
            failed = True
            if prefix_error:
                log = open(log_file, 'a')
                log.write("\nRETRYING\n")
                log.flush()
                cmd_line.append("--prefix=")
                status = install_pypkg_process(cmd_line, environ, log, shell)
                if status == 0:
                    failed = False
        if failed:
            sys.stdout.write(' failed; See ' + log_file)
            raise ConfigError(name, 'Required, but could not be ' +
                              'installed; See ' + log_file)
        else:
            if options.VERBOSE:
                sys.stdout.write(' done\n')
        if locally:
            if not target_lib_dir in sys.path:
                sys.path.insert(0, target_lib_dir)
        os.chdir(here)
    except Exception:  # pylint: disable=W0703
        os.chdir(here)
        raise ConfigError(name, 'Unable to install:\n' +
                          str(sys.exc_info()[1]) + '\n' +
                          traceback.format_exc())
    if not_python:
        return None
    if locally:
        return target_lib_dir
    try:
        __import__(name)
        module = sys.modules[name]
        return os.path.dirname(module.__file__)
    except ImportError:
        return get_python_lib()
コード例 #21
0
ファイル: gccxml.py プロジェクト: sean-m-brennan/pysysdevel
    def install(self, environ, version, strict=False, locally=True):
        if not self.found:
            if locally or ('darwin' in platform.system().lower() and
                           system_uses_homebrew()):
                here = os.path.abspath(os.getcwd())
                if locally:
                    prefix = os.path.abspath(options.target_build_dir)
                    if not prefix in options.local_search_paths:
                        options.add_local_search_path(prefix)
                else:
                    prefix = options.global_prefix
                ## MinGW shell strips backslashes
                prefix = convert2unixpath(prefix)

                src_dir = 'gccxml'
                if not os.path.exists(os.path.join(here, options.download_dir,
                                                   src_dir)):
                    os.chdir(options.download_dir)
                    gitsite = 'https://github.com/gccxml/gccxml.git'
                    check_call([environ['GIT'], 'clone', gitsite, src_dir])
                    os.chdir(here)
                build_dir = os.path.join(options.download_dir,
                                         src_dir, '_build')
                mkdir(build_dir)
                os.chdir(build_dir)
                log = open('build.log', 'w')
                if 'windows' in platform.system().lower():
                    if 'MSVC' in environ:
                        config_cmd = [environ['CMAKE'], '..',
                                      '-G', '"NMake Makefiles"',
                                      '-DCMAKE_INSTALL_PREFIX=' + prefix]
                        #TODO test msvc cmake build; probably wrong
                        check_call([environ['MSVC_VARS']],
                                   stdout=log, stderr=log)
                        check_call(config_cmd, stdout=log, stderr=log)
                        check_call([environ['NMAKE']], stdout=log, stderr=log)
                        check_call([environ['NMAKE'], 'install'],
                                   stdout=log, stderr=log)
                    else:  ## MinGW
                        config_cmd = [environ['CMAKE'], '..',
                                      '-G', '"MSYS Makefiles"',
                                      '-DCMAKE_INSTALL_PREFIX=' + prefix,
                                      '-DCMAKE_MAKE_PROGRAM=/bin/make.exe']
                        mingw_check_call(environ, config_cmd,
                                         stdout=log, stderr=log)
                        mingw_check_call(environ, ['make'],
                                         stdout=log, stderr=log)
                        mingw_check_call(environ, ['make', 'install'],
                                         stdout=log, stderr=log)
                else:
                    config_cmd = [environ['CMAKE'], '..',
                                  '-G', 'Unix Makefiles',
                                  '-DCMAKE_INSTALL_PREFIX=' + prefix]
                    check_call(config_cmd, stdout=log, stderr=log)
                    check_call(['make'], stdout=log, stderr=log)
                    if locally:
                        check_call(['make', 'install'], stdout=log, stderr=log)
                    else:
                        admin_check_call(['make', 'install'],
                                         stdout=log, stderr=log)
                log.close()
                os.chdir(here)
            else:
                if version is None:
                    version = '0.6.0'
                website = ('http://www.gccxml.org/',
                           'files/v' + major_minor_version(version) + '/')
                global_install('GCCXML', website,
                               winstaller='gccxml-' + str(version) + '-win32.exe',
                               brew=None, port='gccxml-devel',
                               deb='gccxml', rpm='gccxml')
            if not self.is_installed(environ, version, strict):
                raise Exception('GCC-XML installation failed.')
コード例 #22
0
def make_doc(src_file, target_dir=None, stylesheet=None):
    (XSLTPROC, JAVA_SAXON, NET_SAXON) = range(3)

    src_dir = os.path.abspath(os.path.dirname(src_file))
    if target_dir is None:
        pth = os.path.relpath(os.path.dirname(src_file)).split(os.sep)[1:]
        # pylint: disable=W0142
        target_dir = os.path.join(options.target_build_dir, *pth)
    if stylesheet is None:
        stylesheet = 'http://docbook.sourceforge.net/release/fo/docbook.xsl'

    fop_exe = find_program('fop')
    java_exe = find_program('java')
    try:  ## prefer xsltproc
        xslt_exe = [find_program('xsltproc')]
        which = XSLTPROC
    except Exception:  # pylint: disable=W0703
        try:
            classpaths = []
            try:
                for path in os.environ['CLASSPATH'].split(os.pathsep):
                    classpaths.append(os.path.dirname(path))
            except KeyError:
                pass
            try:
                classpaths.append(os.path.join(os.environ['JAVA_HOME'], 'lib'))
            except KeyError:
                pass
            saxon_jar = find_file('saxon*.jar',
                                  ['/usr/share/java', '/usr/local/share/java',
                                   '/opt/local/share/java',] + classpaths)
            resolver_jar = find_file('resolver*.jar',
                                     ['/usr/share/java',
                                      '/usr/local/share/java',
                                      '/opt/local/share/java',] + classpaths)
            xslt_exe = [java_exe, '-classpath',
                        os.pathsep.join([saxon_jar, resolver_jar]),
                        '-jar', saxon_jar]
            which = JAVA_SAXON
        except Exception:  # pylint: disable=W0703
            xslt_exe = [find_program('saxon')]
            which = NET_SAXON

    if not os.path.exists(target_dir):
        mkdir(target_dir)
    copy_tree(src_dir, target_dir)

    ## Need to respect relative paths
    here = os.getcwd()
    os.chdir(target_dir)
    src_base = os.path.basename(src_file)
    fo_src = os.path.splitext(src_base)[0] + '.fo'
    pdf_dst = os.path.splitext(src_base)[0] + '.pdf'

    if which == XSLTPROC:
        cmd_line = xslt_exe + ['-xinclude', '-o', fo_src, stylesheet, src_base]
    elif which == JAVA_SAXON:
        cmd_line = xslt_exe + ['-o', fo_src, src_base, stylesheet]
    else:
        cmd_line = xslt_exe + [src_base, '-o:' + fo_src, '-xsl:' + stylesheet]
        if 'XML_CATALOG_FILES' in os.environ:
            cmd_line += ['-catalog:' + os.environ['XML_CATALOG_FILES']]
    subprocess.check_call(" ".join(cmd_line), shell=True)

    cmd_line = [fop_exe, '-fo', fo_src, '-pdf', pdf_dst]
    subprocess.check_call(" ".join(cmd_line), shell=True)
    os.chdir(here)
コード例 #23
0
    def run(self):
        if not self.distribution.doc_modules:
            return

        ## Make sure that sources are complete in build_lib.
        self.run_command('build_src')
        ## Ditto extensions
        self.run_command('build_ext')

        build = self.get_finalized_command('build')
        buildpy = self.get_finalized_command('build_py')
        ## packages and files are in build.build_lib (see build_py.py)
        target = os.path.join(os.path.abspath(build.build_base), 'http')
        mkdir(target)
        build_verbose = self.distribution.verbose
        environ = self.distribution.environment

        for dext in self.distribution.doc_modules:
            if self.distribution.verbose:
                print('building documentation "' + dext.name + '" sources')

            doc_dir = os.path.abspath(dext.source_directory)
            extra_dirs = dext.extra_directories
            src_dir = os.path.abspath(dext.name)
            here = os.getcwd()

            reprocess = True
            ref = os.path.join(target, dext.name + '.html')
            root_dir = dext.name
            if os.path.exists(ref) and not self.force:
                reprocess = False
                for root, _, filenames in os.walk(src_dir):
                    for fn in fnmatch.filter(filenames, '*.rst'):
                        doc = os.path.join(root, fn)
                        if os.path.getmtime(ref) < os.path.getmtime(doc):
                            reprocess = True
                            break
                        src = os.path.join(root_dir, root[len(doc_dir)+1:],
                                            fn[:-3] + 'py')
                        if os.path.exists(src):
                            if os.path.getmtime(ref) < os.path.getmtime(src):
                                reprocess = True
                                break
            if reprocess:
                working_dir = os.path.abspath(build.build_lib)
                for package in buildpy.packages:
                    pkgdir = buildpy.get_package_dir(package)
                    pkgsrcdir = os.path.join(os.path.dirname(src_dir), pkgdir)
                    configure_files(environ, pkgsrcdir,
                                    '*.rst', os.path.join(working_dir, pkgdir))

                cfg_dir = os.path.join(working_dir, dext.source_directory)
                environ['BUILD_DIR'] = working_dir

                copy_tree(doc_dir, working_dir, True,
                          excludes=[dext.name, '.svn', 'CVS', '.git', '.hg*'])
                copy_tree(os.path.join(doc_dir, dext.name),
                          os.path.join(cfg_dir, dext.name), True,
                          excludes=['.svn', 'CVS', '.git', '.hg*'])
                for d in extra_dirs:
                    subdir = os.path.basename(os.path.normpath(d))
                    copy_tree(d, os.path.join(target, subdir), True,
                              excludes=['.svn', 'CVS', '.git', '.hg*'])

                if os.path.exists(os.path.join(doc_dir, dext.doxygen_cfg)):
                    ## Doxygen + breathe
                    print('Config ' + os.path.join(doc_dir, dext.doxygen_cfg))
                    configure_file(environ,
                                   os.path.join(doc_dir, dext.doxygen_cfg),
                                   os.path.join(working_dir, dext.doxygen_cfg),
                                   style=dext.style)
                    for s in dext.doxygen_srcs:
                        configure_file(environ,
                                       os.path.join(doc_dir, s),
                                       os.path.join(working_dir, s),
                                       style=dext.style)
                    try:
                        doxygen_exe = find_program('doxygen')
                    except Exception:  # pylint: disable=W0703
                        sys.stderr.write('ERROR: Doxygen not installed ' +
                                         '(required for documentation).\n')
                        return

                    reprocess = True
                    ref = os.path.join(working_dir, 'html', 'index.html')
                    if os.path.exists(ref) and not self.force:
                        reprocess = False
                        for d in environ['C_SOURCE_DIRS'].split(' '):
                            for orig in glob.glob(os.path.join(d, '*.h*')):
                                if os.path.getmtime(ref) < \
                                   os.path.getmtime(orig):
                                    reprocess = True
                                    break
                    if reprocess:
                        if self.distribution.verbose:
                            out = sys.stdout
                            err = sys.stderr
                        else:
                            out = err = open('doxygen.log', 'w')
                        os.chdir(working_dir)
                        cmd_line = [doxygen_exe, dext.doxygen_cfg]
                        status = subprocess.call(cmd_line,
                                                 stdout=out, stderr=err)
                        if status != 0:
                            raise Exception("Command '" + str(cmd_line) +
                                            "' returned non-zero exit status "
                                            + str(status))

                        if not self.distribution.verbose:
                            out.close()
                        copy_tree('html', os.path.join(target, 'html'), True,
                                  excludes=['.svn', 'CVS', '.git', '.hg*'])
                        copy_tree('xml', os.path.join(cfg_dir, 'xml'), True)
                        os.chdir(here)
                        create_breathe_stylesheet(target)

                for f in dext.extra_docs:
                    shutil.copy(os.path.join(doc_dir, f), target)

                ## Sphinx
                if dext.without_sphinx:
                    return
                if dext.sphinx_config is None:
                    level_up = os.path.dirname(os.path.dirname(__file__))
                    dext.sphinx_config = os.path.join(level_up,
                                                      'sphinx_conf.py.in')
                elif os.path.dirname(dext.sphinx_config) == '':
                    dext.sphinx_config =  os.path.join(doc_dir,
                                                       dext.sphinx_config)
                configure_file(environ, dext.sphinx_config,
                               os.path.join(cfg_dir, 'conf.py'))
                import warnings
                try:
                    import sphinx  # pylint: disable=W0612
                except ImportError:
                    configure_package('breathe')  ## requires sphinx
                    sys.path.insert(0, os.path.join(options.target_build_dir,
                                                    options.local_lib_dir))

                from sphinx.application import Sphinx
                if 'windows' in platform.system().lower() or \
                   not build_verbose:
                    from sphinx.util.console import nocolor
                warnings.filterwarnings("ignore",
                                        category=PendingDeprecationWarning)
                warnings.filterwarnings("ignore", category=UserWarning)

                status = sys.stdout
                if not build_verbose:
                    status = open('sphinx.log', 'w')
                if 'windows' in platform.system().lower() or not build_verbose:
                    nocolor()
                try:
                    ## args: srcdir, confdir, outdir, doctreedir, buildername
                    sphinx_app = Sphinx(os.path.join(working_dir, dext.name),
                                        cfg_dir, target,
                                        os.path.join(target, '.doctrees'),
                                        'html', status=status)
                    sphinx_app.build(force_all=True, filenames=None)
                except Exception:  # pylint: disable=W0703
                    if build_verbose:
                        print('ERROR: ' + str(sys.exc_info()[1]))
                    else:
                        pass
                if not build_verbose:
                    status.close()
                warnings.resetwarnings()
コード例 #24
0
ファイル: build_js.py プロジェクト: sean-m-brennan/pysysdevel
    def run(self):
        if not self.web_ext_modules:
            return

        ## Make sure that extension sources are complete.
        self.run_command('build_src')
        build = self.get_finalized_command('build')
        environ = self.distribution.environment

        for wext in self.web_ext_modules:
            if self.distribution.verbose:
                print('building web extension "' + \
                    os.path.join(wext.public_subdir, wext.name) + '" sources')

            target = os.path.abspath(os.path.join(options.target_build_dir,
                                                  'http', wext.public_subdir))
            mkdir(target)
            here = os.getcwd()
            src_dir = os.path.abspath(wext.source_directory)
            working_dir = os.path.abspath(os.path.join(build.build_temp,
                                                       'web', wext.name))
            mkdir(working_dir)

            for support in wext.extra_support_files:
                src_file = os.path.join(CLIENT_SUPPORT_DIR, support + '.in')
                if not os.path.exists(src_file):
                    src_file = src_file[:-3]
                dst_file = os.path.join(working_dir, support)
                configure_file(environ, src_file, dst_file)

            reprocess = True
            ref = os.path.join(target, wext.name + '.html')
            if os.path.exists(ref) and not self.force:
                reprocess = False
                for src in wext.sources:
                    if os.path.getmtime(ref) < os.path.getmtime(src):
                        reprocess = True
            if reprocess:
                ## Special handling for 'public' directory
                configure_files(environ, os.path.join(src_dir, 'public'),
                                '*', os.path.join(working_dir, 'public'),
                                excludes=['.svn', 'CVS'])

                if len(wext.sources) > 0:
                    for s in wext.sources:
                        configure_file(environ, s,
                                       os.path.join(working_dir,
                                                    os.path.basename(s)))
                    #import pyjs  # pylint: disable=F0401,W0611,W0612
                    ## TODO: use pyjs module directly (instead of 'pyjsbuild')
                    try:
                        compiler = environ['PYJSBUILD']
                    except KeyError:
                        compiler = self.pyjscompiler
                    if compiler is None:
                        env = configure_package('pyjamas')
                        compiler = env['PYJSBUILD']
                        if compiler is None:
                            raise DistutilsExecError("no pyjsbuild executable found or given")
                    cmd_line = [os.path.abspath(compiler)]
                    for arg in wext.extra_compile_args:
                        if 'debug' in arg.lower():
                            cmd_line.append('--debug')
                            cmd_line.append('--print-statements')
                        else:
                            cmd_line.append(arg)
                    if self.distribution.verbose:
                        cmd_line.append('--log-level=' + str(logging.INFO))
                    else:
                        cmd_line.append('--log-level=' + str(logging.ERROR))
                    cmd_line.append('--output=' + target)
                    cmd_line.append(wext.name)

                    os.chdir(working_dir)
                    status = subprocess.call(cmd_line)
                    if status != 0:
                        raise Exception("Command '" + str(cmd_line) +
                                        "' returned non-zero exit status "
                                        + str(status))
                    os.chdir(here)

            pubdir = os.path.join(working_dir, 'public')
            excludes = ['.svn', 'CVS']
            if len(wext.sources) < 1:  ## PYJS did not run
                copy_tree(pubdir, target, excludes=excludes,
                          verbose=self.distribution.verbose)

            for filename in wext.extra_public_files:
                filepath = os.path.join(CLIENT_SUPPORT_DIR, filename + '.in')
                if not os.path.exists(filepath):
                    filepath = filepath[:-3]
                targetfile = os.path.join(target, filename)
                if '.js' in filename:
                    targetfile = os.path.join(target,
                                              options.javascript_dir, filename)
                if '.css' in filename:
                    targetfile = os.path.join(target,
                                              options.stylesheet_dir, filename)
                if not os.path.exists(targetfile):
                    configure_file(environ, filepath, targetfile)

            ## Copy over downloaded files
            js_dir = os.path.join(options.target_build_dir,
                                  options.javascript_dir)
            if os.path.exists(js_dir):
                copy_tree(js_dir, os.path.join(target, options.javascript_dir))
            css_dir = os.path.join(options.target_build_dir,
                                   options.stylesheet_dir)
            if os.path.exists(css_dir):
                copy_tree(css_dir, os.path.join(target, options.stylesheet_dir))
            php_dir = os.path.join(options.target_build_dir, options.script_dir)
            if os.path.exists(php_dir):
                copy_tree(php_dir, target)

            ## pyjs processing ignores hidden files in public
            hidden = []
            for root, _, filenames in os.walk(pubdir):
                for ex in excludes:
                    if fnmatch.fnmatch(root, ex):
                        continue
                for filename in fnmatch.filter(filenames, ".??*"):
                    hidden.append(os.path.join(root[len(pubdir)+1:], filename))
            for filepath in hidden:
                targetfile = os.path.join(target, filepath)
                if not os.path.exists(targetfile):
                    shutil.copyfile(os.path.join(pubdir, filepath), targetfile)

            stat_info = os.stat(os.path.join(src_dir, 'public'))
            uid = stat_info.st_uid
            gid = stat_info.st_gid
            recursive_chown(target, uid, gid)

            if not os.path.lexists(os.path.join(target, 'index.html')) and \
                    os.path.lexists(os.path.join(target, wext.name + '.html')):
                shutil.copyfile(os.path.join(target, wext.name + '.html'),
                                os.path.join(target, 'index.html'))
            if not os.path.lexists(os.path.join(target, 'index.php')) and \
                    os.path.lexists(os.path.join(target, wext.name + '.php')):
                shutil.copyfile(os.path.join(target, wext.name + '.php'),
                                os.path.join(target, 'index.php'))
コード例 #25
0
def make_doc(src_file, target_dir=None, mode='docbook'):
    if target_dir is None:
        pth = os.path.relpath(os.path.dirname(src_file)).split(os.sep)[1:]
        # pylint: disable=W0142
        target_dir = os.path.join(options.target_build_dir, *pth)

    emacs_exe = find_program('emacs')
    src_dir = os.path.abspath(os.path.dirname(src_file))
    mkdir(target_dir)
    copy_tree(src_dir, target_dir)
    cfg_filename = os.path.join(target_dir, '.emacs')
    cfg = open(cfg_filename, 'w')
    cfg.write("(require 'org-latex)\n" +
              "(unless (boundp 'org-export-latex-classes)\n" +
              "  (setq org-export-latex-classes nil))\n" +
              "(add-to-list 'org-export-latex-classes\n" +
              "             '(\"short-book\"\n" +
              "               \"\\\\documentclass{book}\"\n" +
              "               (\"\\\\chapter{%s}\" . \"\\\\chapter*{%s}\")\n" +
              "               (\"\\\\section{%s}\" . \"\\\\section*{%s}\")\n" +
              "               (\"\\\\subsection{%s}\" . \"\\\\subsection*{%s}\")\n" +
              "               (\"\\\\subsubsection{%s}\" . \"\\\\subsubsection*{%s}\"))\n" +
              "             )\n"
          )
    cfg.close()

    ## Check version of org-mode
    cmd_line = [emacs_exe, '--batch', "--execute='(message (org-version))'"]
    p = subprocess.Popen(" ".join(cmd_line), shell=True,
                         stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    _, err = p.communicate()
    version_eight = False
    try:
        last = err.split('\n')[-2]
        if int(last[:last.index('.')]) > 7:
            version_eight = True
    except:
        raise Exception("Emacs does not have Org mode support.")

    ## Emacs Org mode export
    cmd_line = [emacs_exe, '--batch',
                "--execute='(load-file \"" + cfg_filename + "\"))'",
                '--visit=' + src_file]
    base_filename = os.path.splitext(os.path.basename(src_file))[0]
    if 'pdflatex' in mode:
        cmd_line.append("--execute='(org-export-as-pdf nil)'")
        result_files = [base_filename + '.tex', base_filename + '.pdf',]
    elif 'latex' in mode:
        cmd_line.append("--execute='(org-export-as-latex nil)'")
        result_files = [base_filename + '.tex']
    elif 'html' in mode:
        cmd_line.append("--execute='(org-export-as-html nil)'")
        result_files = [base_filename + '.html']
    else:
        if version_eight:
            ## TODO  texinfo for org v8.0+
            raise Exception("Emacs Org mode v8.0+ is not (yet) supported")
        else:
            cmd_line.append("--execute='(org-export-as-docbook nil)'")
            result_files = [base_filename + '.xml']

    subprocess.check_call(" ".join(cmd_line), shell=True)
    os.remove(cfg_filename)

    for r in result_files:
        shutil.move(os.path.join(src_dir, r),
                    os.path.join(target_dir, r))
    return os.path.join(target_dir, result_files[-1])