Exemple #1
0
 def run(self):
     # On dry-run ignore missing source files.
     if self.dry_run:
         mode = 'newer'
     else:
         mode = 'error'
     # Work on all files
     for infile in self.distribution.configure_files:
         # We copy the files to build/
         outfile = os.path.join(self.build_dir, infile)
         # check if the file is out of date
         if self.force or dep_util.newer_group([infile, 'setup.py'], outfile, mode):
             # It is. Configure it
             self.configure_one_file(infile, outfile)
Exemple #2
0
 def run(self):
     # On dry-run ignore missing source files.
     if self.dry_run:
         mode = 'newer'
     else:
         mode = 'error'
     # Work on all files
     for infile in self.distribution.configure_files:
         # We copy the files to build/
         outfile = os.path.join(self.build_dir, infile)
         # check if the file is out of date
         if self.force or dep_util.newer_group([infile, 'setup.py'], outfile, mode):
             # It is. Configure it
             self.configure_one_file(infile, outfile)
Exemple #3
0
def cython_run(
    source, target=None,
    depends=(), includes=(),
    workdir=None, force=False,
    VERSION=None,
):
    if target is None:
        target = os.path.splitext(source)[0]+'.c'
    cwd = os.getcwd()
    try:
        if workdir:
            os.chdir(workdir)
        alldeps = [source]
        for dep in depends:
            alldeps += glob.glob(dep)
        if not (force or dep_util.newer_group(alldeps, target)):
            log.debug("skipping '%s' -> '%s' (up-to-date)",
                      source, target)
            return
    finally:
        os.chdir(cwd)
    require = 'Cython'
    if VERSION is not None:
        require += '>=%s' % VERSION
    if not cython_chk(VERSION, verbose=False):
        try:
            import warnings
            import setuptools
            install_setup_requires = setuptools._install_setup_requires
            with warnings.catch_warnings():
                category = setuptools.SetuptoolsDeprecationWarning
                warnings.simplefilter('ignore', category)
                log.info("fetching build requirement %s" % require)
                install_setup_requires(dict(setup_requires=[require]))
        except Exception:
            log.info("failed to fetch build requirement %s" % require)
    if not cython_chk(VERSION):
        raise DistutilsError("requires %s" % require)
    #
    log.info("cythonizing '%s' -> '%s'", source, target)
    from cythonize import cythonize
    err = cythonize(
        source, target,
        includes=includes,
        workdir=workdir,
    )
    if err:
        raise DistutilsError(
            "Cython failure: '%s' -> '%s'" % (source, target)
        )
Exemple #4
0
 def run(self):
     """Generate the man pages... this is currently done through POD,
     possible future version may do this through some Python mechanism
     (maybe conversion from ReStructured Text (.rst))...
     """
     # On dry-run ignore missing source files.
     if self.dry_run:
         mode = 'newer'
     else:
         mode = 'error'
     # Work on all files
     for infile in self.distribution.man_pages:
         # We copy the files to build/
         outfile = os.path.join(self.build_dir, os.path.splitext(infile)[0] + '.gz')
         # check if the file is out of date
         if self.force or dep_util.newer_group([infile], outfile, mode):
             # It is. Configure it
             self.build_one_file(infile, outfile)
Exemple #5
0
 def run(self):
     """Generate the man pages... this is currently done through POD,
     possible future version may do this through some Python mechanism
     (maybe conversion from ReStructured Text (.rst))...
     """
     # On dry-run ignore missing source files.
     if self.dry_run:
         mode = 'newer'
     else:
         mode = 'error'
     # Work on all files
     for infile in self.distribution.man_pages:
         # We copy the files to build/
         outfile = os.path.join(self.build_dir, os.path.splitext(infile)[0] + '.gz')
         # check if the file is out of date
         if self.force or dep_util.newer_group([infile], outfile, mode):
             # It is. Configure it
             self.build_one_file(infile, outfile)
Exemple #6
0
 def build_extension (self, ext):
     fullname = self.get_ext_fullname(ext.name)
     filename = os.path.join(
         self.build_lib, self.get_ext_filename(fullname))
     depends = ext.sources + ext.depends
     if not (self.force or
             dep_util.newer_group(depends, filename, 'newer')):
         log.debug("skipping '%s' extension (up-to-date)", ext.name)
         return
     #
     self.compiler = self.compiler_mpi
     self.config_extension(ext)
     cmd_build_ext.build_ext.build_extension(self, ext)
     #
     if ext.name == 'mpi4py.MPI':
         dest_dir = os.path.dirname(filename)
         self.mkpath(dest_dir)
         mpi_cfg = os.path.join(dest_dir, 'mpi.cfg')
         log.info("writing %s" % mpi_cfg)
         if not self.dry_run:
             self.config.dump(filename=mpi_cfg)
Exemple #7
0
def get_extensions():
    generate_c_docstrings()

    ######################################################################
    # DISTUTILS SETUP
    cfg = defaultdict(list)

    wcslib_files = [  # List of wcslib files to compile
        'flexed/wcsbth.c', 'flexed/wcspih.c', 'flexed/wcsulex.c',
        'flexed/wcsutrn.c', 'cel.c', 'dis.c', 'lin.c', 'log.c', 'prj.c',
        'spc.c', 'sph.c', 'spx.c', 'tab.c', 'wcs.c', 'wcserr.c', 'wcsfix.c',
        'wcshdr.c', 'wcsprintf.c', 'wcsunits.c', 'wcsutil.c'
    ]

    wcslib_config_paths = [
        join(WCSROOT, 'include', 'astropy_wcs', 'wcsconfig.h'),
        join(WCSROOT, 'include', 'wcsconfig.h')
    ]

    get_wcslib_cfg(cfg, wcslib_files, wcslib_config_paths)

    cfg['include_dirs'].append(join(WCSROOT, "include"))

    astropy_wcs_files = [  # List of astropy.wcs files to compile
        'distortion.c', 'distortion_wrap.c', 'docstrings.c', 'pipeline.c',
        'pyutil.c', 'astropy_wcs.c', 'astropy_wcs_api.c', 'sip.c',
        'sip_wrap.c', 'str_list_proxy.c', 'unit_list_proxy.c', 'util.c',
        'wcslib_wrap.c', 'wcslib_auxprm_wrap.c', 'wcslib_tabprm_wrap.c',
        'wcslib_wtbarr_wrap.c'
    ]
    cfg['sources'].extend(join(WCSROOT, 'src', x) for x in astropy_wcs_files)

    cfg['sources'] = [str(x) for x in cfg['sources']]
    cfg = dict((str(key), val) for key, val in cfg.items())

    # Copy over header files from WCSLIB into the installed version of Astropy
    # so that other Python packages can write extensions that link to it. We
    # do the copying here then include the data in [options.package_data] in
    # the setup.cfg file

    wcslib_headers = [
        'cel.h',
        'lin.h',
        'prj.h',
        'spc.h',
        'spx.h',
        'tab.h',
        'wcs.h',
        'wcserr.h',
        'wcsmath.h',
        'wcsprintf.h',
    ]

    if not (int(os.environ.get('ASTROPY_USE_SYSTEM_WCSLIB', 0))
            or int(os.environ.get('ASTROPY_USE_SYSTEM_ALL', 0))):
        for header in wcslib_headers:
            source = join('cextern', 'wcslib', 'C', header)
            dest = join('astropy', 'wcs', 'include', 'wcslib', header)
            if newer_group([source], dest, 'newer'):
                shutil.copy(source, dest)

    return [Extension('astropy.wcs._wcs', **cfg)]
Exemple #8
0
    def build_executable (self, exe):
        sources = list(exe.sources)
        depends = list(exe.depends)
        exe_fullpath = self.get_exe_fullpath(exe)
        depends = sources + depends
        if not (self.force or
                dep_util.newer_group(depends, exe_fullpath, 'newer')):
            log.debug("skipping '%s' executable (up-to-date)", exe.name)
            return

        self.config_executable(exe)
        log.info("building '%s' executable", exe.name)

        # Next, compile the source code to object files.

        # XXX not honouring 'define_macros' or 'undef_macros' -- the
        # CCompiler API needs to change to accommodate this, and I
        # want to do one thing at a time!

        macros = exe.define_macros[:]
        for undef in exe.undef_macros:
            macros.append((undef,))

        # Two possible sources for extra compiler arguments:
        #   - 'extra_compile_args' in Extension object
        #   - CFLAGS environment variable (not particularly
        #     elegant, but people seem to expect it and I
        #     guess it's useful)
        # The environment variable should take precedence, and
        # any sensible compiler will give precedence to later
        # command line args.  Hence we combine them in order:
        extra_args = exe.extra_compile_args[:]

        objects =  self.compiler.compile(
            sources,
            output_dir=self.build_temp,
            macros=macros,
            include_dirs=exe.include_dirs,
            debug=self.debug,
            extra_postargs=extra_args,
            depends=exe.depends)
        self._built_objects = objects[:]

        # Now link the object files together into a "shared object" --
        # of course, first we have to figure out all the other things
        # that go into the mix.
        if exe.extra_objects:
            objects.extend(exe.extra_objects)
        extra_args = exe.extra_link_args[:]
        # Get special linker flags for building a executable with
        # bundled Python library, also fix location of needed
        # python.exp file on AIX
        ldflags = sysconfig.get_config_var('PY_LDFLAGS') or ''
        linkshared = sysconfig.get_config_var('LINKFORSHARED') or ''
        linkshared = linkshared.replace('-Xlinker ', '-Wl,')
        if sys.platform == 'darwin': # fix wrong framework paths
            fwkprefix = sysconfig.get_config_var('PYTHONFRAMEWORKPREFIX')
            fwkdir = sysconfig.get_config_var('PYTHONFRAMEWORKDIR')
            if fwkprefix and fwkdir and fwkdir != 'no-framework':
                for flag in shlex.split(linkshared):
                    if flag.startswith(fwkdir):
                        fwkpath = os.path.join(fwkprefix, flag)
                        linkshared = linkshared.replace(flag, fwkpath)
        if sys.platform.startswith('aix'):
            python_lib = sysconfig.get_python_lib(standard_lib=1)
            python_exp = os.path.join(python_lib, 'config', 'python.exp')
            linkshared = linkshared.replace('Modules/python.exp', python_exp)
        # Detect target language, if not provided
        language = exe.language or self.compiler.detect_language(sources)
        self.compiler.link(
            self.compiler.EXECUTABLE,
            objects, exe_fullpath,
            output_dir=None,
            libraries=self.get_libraries(exe),
            library_dirs=exe.library_dirs,
            runtime_library_dirs=exe.runtime_library_dirs,
            extra_preargs=shlex.split(ldflags) + shlex.split(linkshared),
            extra_postargs=extra_args,
            debug=self.debug,
            target_lang=language)