a
    ߙfb%                     @   s   d dl Z d dlZd dlmZ d dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dlZd dlmZmZmZmZ ejejeZdZdd	 Zd
d Zdd Zdd Zdd Zdd Zdd ZdS )    Njoin)defaultdict)	Extension)newer_group)import_filewrite_if_differentget_compiler
pkg_configz7.9c                 C   s
   |  dS )Nascii)encodes r   8lib/python3.9/site-packages/astropy/wcs/setup_package.pyb   s    r   c                 C   s4   |  ddd} | dd} | dd} |  dS )Nr   backslashreplace   
s   \n    s   \0)decoder   replacer   r   r   r   string_escape   s    r   c                  C   s   zrzddl } W n ty&   t Y n0 | | jdkr>W dS | | jdkrTW dS | | jdkrjW dS t W n ty   Y dS 0 dS )a  
    The only configuration parameter needed at compile-time is how to
    specify a 64-bit signed integer.  Python's ctypes module can get us
    that information.
    If we can't be absolutely certain, we default to "long long int",
    which is correct on most platforms (x86, x86_64).  If we find
    platforms where this heuristic doesn't work, we may need to
    hardcode for them.
    r   N   zlong long intzlong intint)ctypesImportError
ValueErrorZsizeofZ
c_longlongZc_longZc_int)r   r   r   r   determine_64_bit_int!   s    

r   c                 C   sB   t  }|dtt  | d}| D ]}t|| q.dS )zE
    Writes out the wcsconfig.h header with local configuration.
    aw  
    /* The bundled version has WCSLIB_VERSION */
    #define HAVE_WCSLIB_VERSION 1

    /* WCSLIB library version number. */
    #define WCSLIB_VERSION {}

    /* 64-bit integer data type. */
    #define WCSLIB_INT64 {}

    /* Windows needs some other defines to prevent inclusion of wcsset()
       which conflicts with wcslib's wcsset().  These need to be set
       on code that *uses* astropy.wcs, in addition to astropy.wcs itself.
       */
    #if defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) || defined (__MINGW64__)

    #ifndef YY_NO_UNISTD_H
    #define YY_NO_UNISTD_H
    #endif

    #ifndef _CRT_SECURE_NO_WARNINGS
    #define _CRT_SECURE_NO_WARNINGS
    #endif

    #ifndef _NO_OLDNAMES
    #define _NO_OLDNAMES
    #endif

    #ifndef NO_OLDNAMES
    #define NO_OLDNAMES
    #endif

    #ifndef __STDC__
    #define __STDC__ 1
    #endif

    #endif
    r   N)	ioStringIOwriteformat
WCSVERSIONr   getvaluer   r   )pathsh_fileZcontentpathr   r   r   write_wcsconfig_h>   s    %&r'   c            	      C   s  t tjtd} | j} dd |  D }|  i }|D ]}| | d	 d ||< q:t
 }|d |D ](}|| }|d| dt| d	 qp|d
 tttddd| d t
 }|d |D ]}|| }|d| dt| d tdt|dD ]D}|||d  }|d |ddd |D  |d q|d qtttdd| d d S )Nzdocstrings.pyc                 S   s(   g | ] \}}| d st|tr|qS )__)
startswith
isinstancestr.0keyvalr   r   r   
<listcomp>u   s   z)generate_c_docstrings.<locals>.<listcomp>utf8r   z/*
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__

zextern char doc_[z];
z	
#endif

includeastropy_wcszdocstrings.hzutf-8aH  /*
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"

z	char doc_z] = {
r      z     c                 s   s   | ]}d |ddV  qdS )Z0xZ02xz, Nr   r-   xr   r   r   	<genexpr>       z(generate_c_docstrings.<locals>.<genexpr>
z    };

srcdocstrings.c)r   osr&   r   WCSROOT__dict__itemssortr   lstripr   r   r    lenr   r#   range)	Z
docstringskeysZdocsr.   r%   r/   Zc_fileiZsectionr   r   r   generate_c_docstringsr   sD    




rH   c                    s  dt jv }| d t  | d g d ttj	ddsRttj	ddrt j
dksttd	d
}tj|r~t| tdgdg D ]\}}| | | qnFt| tdd}t|d | d  fdd|D  | d   |r@| d d | d d t j
ds\t j
dks\| d g d n| d d | d d t j
dkrz| d g d t j
dr| d d t dkr| d dg t dv r|s| d g d  d S )!Nz--debuginclude_dirsZdefine_macros))ZECHON)ZWCSTRIG_MACRON)ZASTROPY_WCS_BUILDN)Z_GNU_SOURCENASTROPY_USE_SYSTEM_WCSLIBr   ASTROPY_USE_SYSTEM_ALLZwin32r3   wcsconfig.hwcslibwcscexternCsourcesc                 3   s   | ]}t  |V  qd S Nr   r7   Zwcslib_cpathr   r   r9      r:   z!get_wcslib_cfg.<locals>.<genexpr>)DEBUGNZundef_macrosNDEBUGZsunZextra_compile_args)z-fno-inlinez-O0z-g)rU   NrT   ))ZYY_NO_UNISTD_HN)Z_CRT_SECURE_NO_WARNINGSN)Z_NO_OLDNAMESN)ZNO_OLDNAMESN)Z__STDC__NZlinux)ZHAVE_SINCOSNunixz
-std=gnu99)rV   Zmingw32)z-Wno-strict-prototypesz-Wno-unused-functionz-Wno-unused-valuez-Wno-uninitialized)sysargvappendnumpyZget_includeextendr   r>   environgetplatformr   r?   r&   existsunlinkr
   rA   r'   r)   r	   )cfgwcslib_filesZinclude_pathsdebugZwcsconfig_h_pathkvZwcslib_pathr   rS   r   get_wcslib_cfg   sH    



rf   c                  C   s  t   tt} g d}ttdddttddg}t| || | d ttd g d}| d dd	 |D  d
d | d D | d< tdd	 | 	 D } g d}t
tjddst
tjdds|D ]<}tddd|}tdddd|}t|g|drt|| qtdi | gS )N)zflexed/wcsbth.czflexed/wcspih.czflexed/wcsulex.czflexed/wcsutrn.czcel.czdis.czlin.czlog.czprj.czspc.czsph.czspx.cztab.czwcs.czwcserr.czwcsfix.czwcshdr.czwcsprintf.cz
wcsunits.cz	wcsutil.cr3   r4   rL   rI   )zdistortion.czdistortion_wrap.cr=   z
pipeline.czpyutil.czastropy_wcs.czastropy_wcs_api.czsip.cz
sip_wrap.czstr_list_proxy.czunit_list_proxy.czutil.czwcslib_wrap.czwcslib_auxprm_wrap.czwcslib_tabprm_wrap.czwcslib_wtbarr_wrap.crQ   c                 s   s   | ]}t td |V  qdS )r<   N)r   r?   r7   r   r   r   r9   -  r:   z!get_extensions.<locals>.<genexpr>c                 S   s   g | ]}t |qS r   r+   r7   r   r   r   r0   /  r:   z"get_extensions.<locals>.<listcomp>c                 s   s   | ]\}}t ||fV  qd S rR   rg   r,   r   r   r   r9   0  r:   )
zcel.hzlin.hzprj.hzspc.hzspx.hztab.hzwcs.hzwcserr.hz	wcsmath.hzwcsprintf.hrJ   r   rK   rO   rM   rP   ZastropyrN   Znewerastropy.wcs._wcs)rh   )rH   r   listr   r?   rf   rY   r[   dictrA   r   r>   r\   r]   r   shutilcopyr   )ra   rb   Zwcslib_config_pathsZastropy_wcs_filesZwcslib_headersheadersourcedestr   r   r   get_extensions   s,    
rp   )r   r>   os.pathr   rk   rW   collectionsr   Z
setuptoolsr   Zsetuptools.dep_utilr   rZ   Zextension_helpersr   r   r	   r
   r&   relpathdirname__file__r?   r"   r   r   r   r'   rH   rf   rp   r   r   r   r   <module>   s&   4?C