<commit_before>#!/usr/bin/env python

import os
import sys
import glob
import numpy as np
import re

from setuptools import setup, Extension


def setup_xspec():

    headas_root = os.environ.get("HEADAS")

    if headas_root is None:

        print("No HEADAS env. variable set. Xspec support will not be installed ")

        return None

    library_dirs = [os.path.join(headas_root, 'lib')]

    # Check that the library directories exist

    if not os.path.exists(library_dirs[0]):

        print("\nERROR: the library directory %s of HEADAS does not exist!" % library_dirs[0])

        sys.exit(-1)

    libraries = ['XSFunctions', 'XSModel', 'XSUtil', 'XS']

    # Check that the libraries exist
    for library in libraries:

        library_name = 'lib%s.so' % library

        if not os.path.exists(os.path.join(library_dirs[0], library_name)):

            # See if it has been compiled static (usually libXS is)

            library_name = 'lib%s.a' % library

            if not os.path.exists(os.path.join(library_dirs[0], library_name)):

                # If on OS X look for dylib
                
                library_name = 'lib%s.dylib' % library

                if not os.path.exists(os.path.join(library_dirs[0], library_name)):


                    print("\nERROR: the library %s does not exist in %s while setting up Xspec!" %
                          (library, library_dirs[0]))

    # Now find versions for required libraries

    required_libraries = ['cfitsio_', 'CCfits_', 'wcs-']

    for library_to_probe in required_libraries:

        search_path = os.path.join(library_dirs[0], 'lib%s*.so' % library_to_probe)

        print search_path

        versions = glob.glob(search_path)

        if len(versions) == 0:
            search_path = os.path.join(library_dirs[0], 'lib%s*.dylib' % library_to_probe)
            print search_path

            versions = glob.glob(search_path)
            if len(versions) == 0:
                print("\nERROR: cannot find version for library %s while setting up Xspec" % (library_to_probe))
                sys.exit(-1)

        # Up to there versions[0] is a fully-qualified path
        # we need instead just the name of the library, without
        # the lib prefix nor the .so or .a extension

        name = os.path.basename(versions[0])
        sanitized_name = re.match('lib(.+)\.', name).groups()[0]

        libraries.append(sanitized_name)

    # We also need gfortran
    libraries.append('gfortran')
#    library_dirs.append("/usr/local/lib/gcc/6")
    # Configure the variables to build the external module with the C/C++ wrapper

    ext_modules_configuration = [

        Extension("astromodels.xspec._xspec",

                  ["astromodels/xspec/src/_xspec.cc", ],

                  libraries=libraries,

                  include_dirs=['astromodels/xspec/include', np.get_include()],<commit_msg>added . versions in addtion to _ versions for newer XSPEC<commit_after>#!/usr/bin/env python

import os
import sys
import glob
import numpy as np
import re

from setuptools import setup, Extension


def setup_xspec():

    headas_root = os.environ.get("HEADAS")

    if headas_root is None:

        print("No HEADAS env. variable set. Xspec support will not be installed ")

        return None

    library_dirs = [os.path.join(headas_root, 'lib')]

    # Check that the library directories exist

    if not os.path.exists(library_dirs[0]):

        print("\nERROR: the library directory %s of HEADAS does not exist!" % library_dirs[0])

        sys.exit(-1)

    libraries = ['XSFunctions', 'XSModel', 'XSUtil', 'XS']

    # Check that the libraries exist
    for library in libraries:

        library_name = 'lib%s.so' % library

        if not os.path.exists(os.path.join(library_dirs[0], library_name)):

            # See if it has been compiled static (usually libXS is)

            library_name = 'lib%s.a' % library

            if not os.path.exists(os.path.join(library_dirs[0], library_name)):

                # If on OS X look for dylib
                
                library_name = 'lib%s.dylib' % library

                if not os.path.exists(os.path.join(library_dirs[0], library_name)):


                    print("\nERROR: the library %s does not exist in %s while setting up Xspec!" %
                          (library, library_dirs[0]))

    # Now find versions for required libraries

    required_libraries = ['cfitsio_', 'CCfits_', 'wcs-']
    

    for library_to_probe in required_libraries:

        search_path = os.path.join(library_dirs[0], 'lib%s*.so' % library_to_probe)

        print search_path

        versions = glob.glob(search_path)

        if len(versions) == 0:

            search_path = os.path.join(library_dirs[0], 'lib%s*.so' % (library_to_probe[:-1]+'.'))

            print search_path

            versions = glob.glob(search_path)

            if len(versions) == 0:

            
                search_path = os.path.join(library_dirs[0], 'lib%s*.dylib' % library_to_probe)

                print search_path

                versions = glob.glob(search_path)

                if len(versions) == 0:

                    search_path = os.path.join(library_dirs[0], 'lib%s*.dylib' % (library_to_probe[:-1]+'.'))

                    print search_path

                    versions = glob.glob(search_path)

                    if len(versions) == 0:

                        print("\nERROR: cannot find version for library %s while setting up Xspec" % (library_to_probe))
                        sys.exit(-1)

        # Up to there versions[0] is a fully-qualified path
        # we need instead just the name of the library, without
        # the lib prefix nor the .so or .a extension

        name = os.path.basename(versions[0])
        sanitized_name = re.match('lib(.+)\.', name).groups()[0]

        libraries.append(sanitized_name)

    # We also need gfortran
    libraries.append('gfortran')
#    library_dirs.append("/usr/local/lib/gcc/6")
    # Configure the variables to build the external module with the C/C++ wrapper

    ext_modules_configuration = [

        Extension("astromodels.xspec._xspec",

                  ["astromodels/xspec/src/_xspec.cc", ],

                  libraries=libraries,

                  include_dirs=['astromodels/xspec/include', np.get_include()],
{'fraction_non_alphanumeric': 0.10883603717120806, 'fraction_numerical': 0.0059851945188218614, 'mean_word_length': 2.216818642350557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4677875', 'n_tokens_mistral': 2003, 'n_tokens_neox': 1866, 'n_words': 505}