<commit_before>from __future__ import division  # confidence high

CONTACT = "<NAME>"
EMAIL = "<EMAIL>"

from distutils.core import Extension
import glob
from os.path import join
import os.path
import sys

from astropy import setup_helpers

WCSROOT = os.path.dirname(__file__)
WCSVERSION = "4.8.2"


def b(s):
    return s.encode('ascii')

if sys.version_info[0] >= 3:

    def string_escape(s):
        s = s.decode('ascii').encode('ascii', 'backslashreplace')
        s = s.replace(b('\n'), b('\\n'))
        return s.decode('ascii')

    from io import StringIO
    string_types = (str, bytes)
else:

    def string_escape(s):
        return s.encode('string_escape')

    from cStringIO import StringIO
    string_types = (str, unicode)


def determine_64_bit_int():
    """
    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, but it is only available in Python 2.5 or later.
    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.
    """
    try:
        try:
            import ctypes
        except ImportError:
            raise ValueError()

        if ctypes.sizeof(ctypes.c_longlong) == 8:
            return "long long int"
        elif ctypes.sizeof(ctypes.c_long) == 8:
            return "long int"
        elif ctypes.sizeof(ctypes.c_int) == 8:
            return "int"
        else:
            raise ValueError()

    except ValueError:
        return "long long int"


def write_wcsconfig_h():
    """
    Writes out the wcsconfig.h header with local configuration.
    """
    h_file = StringIO()
    h_file.write("""
    /* WCSLIB library version number. */
    #define WCSLIB_VERSION {0}

    /* 64-bit integer data type. */
    #define WCSLIB_INT64 {1}
    """.format(WCSVERSION, determine_64_bit_int()))
    setup_helpers.write_if_different(
        join(WCSROOT, 'src', 'wcsconfig.h'),
        h_file.getvalue())

######################################################################
# GENERATE DOCSTRINGS IN C


def generate_c_docstrings():
    from astropy.wcs import docstrings
    docstrings = docstrings.__dict__
    keys = [
        key for key in docstrings.keys()
        if not key.startswith('__') and type(key) in string_types]
    keys.sort()
    for key in keys:
        docstrings[key] = docstrings[key].encode('utf8').lstrip()

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

This file is autogenerated by setup.py.  To edit its contents,
edit doc/docstrings.py
*/

#ifndef __DOCSTRINGS_H__<commit_msg>Leave space for the null termination character in the compiled docstrings.<commit_after>from __future__ import division  # confidence high

CONTACT = "<NAME>"
EMAIL = "<EMAIL>"

from distutils.core import Extension
import glob
from os.path import join
import os.path
import sys

from astropy import setup_helpers

WCSROOT = os.path.dirname(__file__)
WCSVERSION = "4.8.2"


def b(s):
    return s.encode('ascii')

if sys.version_info[0] >= 3:

    def string_escape(s):
        s = s.decode('ascii').encode('ascii', 'backslashreplace')
        s = s.replace(b('\n'), b('\\n'))
        return s.decode('ascii')

    from io import StringIO
    string_types = (str, bytes)
else:

    def string_escape(s):
        return s.encode('string_escape')

    from cStringIO import StringIO
    string_types = (str, unicode)


def determine_64_bit_int():
    """
    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, but it is only available in Python 2.5 or later.
    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.
    """
    try:
        try:
            import ctypes
        except ImportError:
            raise ValueError()

        if ctypes.sizeof(ctypes.c_longlong) == 8:
            return "long long int"
        elif ctypes.sizeof(ctypes.c_long) == 8:
            return "long int"
        elif ctypes.sizeof(ctypes.c_int) == 8:
            return "int"
        else:
            raise ValueError()

    except ValueError:
        return "long long int"


def write_wcsconfig_h():
    """
    Writes out the wcsconfig.h header with local configuration.
    """
    h_file = StringIO()
    h_file.write("""
    /* WCSLIB library version number. */
    #define WCSLIB_VERSION {0}

    /* 64-bit integer data type. */
    #define WCSLIB_INT64 {1}
    """.format(WCSVERSION, determine_64_bit_int()))
    setup_helpers.write_if_different(
        join(WCSROOT, 'src', 'wcsconfig.h'),
        h_file.getvalue())

######################################################################
# GENERATE DOCSTRINGS IN C


def generate_c_docstrings():
    from astropy.wcs import docstrings
    docstrings = docstrings.__dict__
    keys = [
        key for key in docstrings.keys()
        if not key.startswith('__') and type(key) in string_types]
    keys.sort()
    for key in keys:
        docstrings[key] = docstrings[key].encode('utf8').lstrip() + '\0'

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

This file is autogenerated by setup.py.  To edit its contents,
edit doc/docstrings.py
*/

#ifndef __DOCSTRINGS_H__
{'fraction_non_alphanumeric': 0.1272563176895307, 'fraction_numerical': 0.010649819494584838, 'mean_word_length': 2.8134893324156915, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3599184', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1691, 'n_words': 530}