Пример #1
0
def generate_c_docstrings():
    docstrings = import_file(os.path.join(WCSROOT, 'docstrings.py'))
    docstrings = docstrings.__dict__
    keys = [
        key for key, val in docstrings.items()
        if not key.startswith('__') and isinstance(val, str)
    ]
    keys.sort()
    docs = {}
    for key in keys:
        docs[key] = docstrings[key].encode('utf8').lstrip() + b'\0'

    h_file = io.StringIO()
    h_file.write("""/*
DO NOT EDIT!

This file is autogenerated by astropy/wcs/setup_package.py.  To edit
its contents, edit astropy/wcs/docstrings.py
*/

#ifndef __DOCSTRINGS_H__
#define __DOCSTRINGS_H__

""")
    for key in keys:
        val = docs[key]
        h_file.write(f'extern char doc_{key}[{len(val)}];\n')
    h_file.write("\n#endif\n\n")

    write_if_different(join(WCSROOT, 'include', 'astropy_wcs', 'docstrings.h'),
                       h_file.getvalue().encode('utf-8'))

    c_file = io.StringIO()
    c_file.write("""/*
DO NOT EDIT!

This file is autogenerated by astropy/wcs/setup_package.py.  To edit
its contents, edit astropy/wcs/docstrings.py

The weirdness here with strncpy is because some C compilers, notably
MSVC, do not support string literals greater than 256 characters.
*/

#include <string.h>
#include "astropy_wcs/docstrings.h"

""")
    for key in keys:
        val = docs[key]
        c_file.write(f'char doc_{key}[{len(val)}] = {{\n')
        for i in range(0, len(val), 12):
            section = val[i:i + 12]
            c_file.write('    ')
            c_file.write(''.join(f'0x{x:02x}, ' for x in section))
            c_file.write('\n')

        c_file.write("    };\n\n")

    write_if_different(join(WCSROOT, 'src', 'docstrings.c'),
                       c_file.getvalue().encode('utf-8'))
Пример #2
0
def get_extensions():

    gen = import_file(os.path.join(ERFAPKGDIR, 'erfa_generator.py'))
    gen.main(verbose=False)

    sources = [
        os.path.join(ERFAPKGDIR, fn)
        for fn in ("ufunc.c", "pav2pv.c", "pv2pav.c")
    ]

    include_dirs = [numpy.get_include()]

    libraries = []

    if (int(os.environ.get('ASTROPY_USE_SYSTEM_ERFA', 0))
            or int(os.environ.get('ASTROPY_USE_SYSTEM_ALL', 0))):
        libraries.append('erfa')
    else:
        # get all of the .c files in the cextern/erfa directory
        erfafns = os.listdir(ERFA_SRC)
        sources.extend(
            ['cextern/erfa/' + fn for fn in erfafns if fn.endswith('.c')])

        include_dirs.append('cextern/erfa')

    erfa_ext = Extension(
        name="astropy._erfa.ufunc",
        sources=sources,
        include_dirs=include_dirs,
        libraries=libraries,
        language="c",
    )

    return [erfa_ext]
Пример #3
0
def get_extensions():
    gen_files_exist = all(os.path.isfile(fn) for fn in GEN_FILES)
    gen_files_outdated = False
    if os.path.isdir(ERFA_SRC):
        # assume thet 'erfaversion.c' is updated at each release at least
        src = os.path.join(ERFA_SRC, 'erfaversion.c')
        gen_files_outdated = any(newer(src, fn) for fn in GEN_FILES)
    elif not gen_files_exist:
        raise RuntimeError(
            'Missing "liberfa" source files, unable to generate '
            '"erfa/ufunc.c" and "erfa/core.py". '
            'Please check your source tree. '
            'Maybe "git submodule update" could help.')

    if not gen_files_exist or gen_files_outdated:
        print('Run "erfa_generator.py"')
        #cmd = [sys.executable, 'erfa_generator.py', ERFA_SRC, '--quiet']
        #subprocess.run(cmd, check=True)

        gen = import_file(os.path.join(ERFAPKGDIR, 'erfa_generator.py'))
        gen.main(verbose=False)

    sources = [
        os.path.join(ERFAPKGDIR, fn)
        for fn in ("ufunc.c", "pav2pv.c", "pv2pav.c")
    ]
    include_dirs = [numpy.get_include()]
    libraries = []

    if (int(os.environ.get('ASTROPY_USE_SYSTEM_ERFA', 0))
            or int(os.environ.get('ASTROPY_USE_SYSTEM_ALL', 0))):
        libraries.append('erfa')
    else:
        # get all of the .c files in the cextern/erfa directory
        erfafns = os.listdir(ERFA_SRC)
        sources.extend(
            ['cextern/erfa/' + fn for fn in erfafns if fn.endswith('.c')])

        include_dirs.append('cextern/erfa')

    erfa_ext = Extension(
        name="astropy._erfa.ufunc",
        sources=sources,
        include_dirs=include_dirs,
        libraries=libraries,
        language="c",
    )

    return [erfa_ext]
Пример #4
0
def generate_c_docstrings():
    docstrings = import_file(os.path.join(LOCALROOT, 'docstrings.py'))
    docstrings = docstrings.__dict__
    keys = [
        key for key, val in docstrings.items()
        if not key.startswith('__') and isinstance(val, str)
    ]
    keys.sort()
    docs = {}
    for key in keys:
        docs[key] = docstrings[key].encode('utf8').lstrip() + b'\0'

    h_file = io.StringIO()
    h_file.write("""/*
DO NOT EDIT!

This file is autogenerated by synphot/setup_package.py.  To edit
its contents, edit synphot/docstrings.py
*/

#ifndef __DOCSTRINGS_H__
#define __DOCSTRINGS_H__

#if defined(_MSC_VER)
void fill_docstrings(void);
#endif

""")
    for key in keys:
        val = docs[key]
        h_file.write('extern char doc_{0}[{1}];\n'.format(key, len(val)))
    h_file.write("\n#endif\n\n")

    write_if_different(os.path.join(LOCALROOT, 'include', 'docstrings.h'),
                       h_file.getvalue().encode('utf-8'))

    c_file = io.StringIO()
    c_file.write("""/*
DO NOT EDIT!

This file is autogenerated by synphot/setup_package.py.  To edit
its contents, edit synphot/docstrings.py

The weirdness here with strncpy is because some C compilers, notably
MSVC, do not support string literals greater than 256 characters.
*/

#include <string.h>
#include "docstrings.h"

#if defined(_MSC_VER)
""")
    for key in keys:
        val = docs[key]
        c_file.write('char doc_{0}[{1}];\n'.format(key, len(val)))

    c_file.write("\nvoid fill_docstrings(void)\n{\n")
    for key in keys:
        val = docs[key]
        # For portability across various compilers, we need to fill the
        # docstrings in 256-character chunks
        for i in range(0, len(val), 256):
            chunk = string_escape(val[i:i + 256]).replace('"', '\\"')
            c_file.write('   strncpy(doc_{0} + {1}, "{2}", {3});\n'.format(
                key, i, chunk, min(len(val) - i, 256)))
        c_file.write("\n")
    c_file.write("\n}\n\n")

    c_file.write("#else /* UNIX */\n")

    for key in keys:
        val = docs[key]
        c_file.write('char doc_{0}[{1}] = "{2}";\n\n'.format(
            key, len(val),
            string_escape(val).replace('"', '\\"')))

    c_file.write("#endif\n")

    write_if_different(os.path.join(LOCALROOT, 'src', 'docstrings.c'),
                       c_file.getvalue().encode('utf-8'))
Пример #5
0
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import os
from os.path import join
from collections import defaultdict

from setuptools import Extension

from extension_helpers import import_file

wcs_setup_package = import_file(join('astropy', 'wcs', 'setup_package.py'))


MODELING_ROOT = os.path.relpath(os.path.dirname(__file__))
MODELING_SRC = join(MODELING_ROOT, 'src')
SRC_FILES = [join(MODELING_SRC, 'projections.c.templ'),
             __file__]
GEN_FILES = [join(MODELING_SRC, 'projections.c')]


# This defines the set of projection functions that we want to wrap.
# The key is the projection name, and the value is the number of
# parameters.

# (These are in the order that the appear in the WCS coordinate
# systems paper).
projections = {
    'azp': 2,
    'szp': 3,
    'tan': 0,
    'stg': 0,