1# Licensed under a 3-clause BSD style license - see LICENSE.rst 2 3import os 4from os.path import join 5from collections import defaultdict 6 7from setuptools import Extension 8 9from extension_helpers import import_file 10 11wcs_setup_package = import_file(join('astropy', 'wcs', 'setup_package.py')) 12 13 14MODELING_ROOT = os.path.relpath(os.path.dirname(__file__)) 15MODELING_SRC = join(MODELING_ROOT, 'src') 16SRC_FILES = [join(MODELING_SRC, 'projections.c.templ'), 17 __file__] 18GEN_FILES = [join(MODELING_SRC, 'projections.c')] 19 20 21# This defines the set of projection functions that we want to wrap. 22# The key is the projection name, and the value is the number of 23# parameters. 24 25# (These are in the order that the appear in the WCS coordinate 26# systems paper). 27projections = { 28 'azp': 2, 29 'szp': 3, 30 'tan': 0, 31 'stg': 0, 32 'sin': 2, 33 'arc': 0, 34 'zea': 0, 35 'air': 1, 36 'cyp': 2, 37 'cea': 1, 38 'mer': 0, 39 'sfl': 0, 40 'par': 0, 41 'mol': 0, 42 'ait': 0, 43 'cop': 2, 44 'coe': 2, 45 'cod': 2, 46 'coo': 2, 47 'bon': 1, 48 'pco': 0, 49 'tsc': 0, 50 'csc': 0, 51 'qsc': 0, 52 'hpx': 2, 53 'xph': 0, 54} 55 56 57def get_extensions(): 58 59 from jinja2 import Environment, FileSystemLoader 60 61 # Prepare the jinja2 templating environment 62 env = Environment(loader=FileSystemLoader(MODELING_SRC)) 63 64 c_in = env.get_template('projections.c.templ') 65 c_out = c_in.render(projections=projections) 66 67 with open(join(MODELING_SRC, 'projections.c'), 'w') as fd: 68 fd.write(c_out) 69 70 wcslib_files = [ # List of wcslib files to compile 71 'prj.c', 72 'wcserr.c', 73 'wcsprintf.c', 74 'wcsutil.c' 75 ] 76 77 wcslib_config_paths = [ 78 join(MODELING_SRC, 'wcsconfig.h') 79 ] 80 81 cfg = defaultdict(list) 82 83 wcs_setup_package.get_wcslib_cfg(cfg, wcslib_files, wcslib_config_paths) 84 85 cfg['include_dirs'].append(MODELING_SRC) 86 87 astropy_files = [ # List of astropy.modeling files to compile 88 'projections.c' 89 ] 90 cfg['sources'].extend(join(MODELING_SRC, x) for x in astropy_files) 91 92 cfg['sources'] = [str(x) for x in cfg['sources']] 93 cfg = dict((str(key), val) for key, val in cfg.items()) 94 95 return [Extension('astropy.modeling._projections', **cfg)] 96