from distutils.core import setup, Extension # from setuptools import find_packages # from setuptools import setup, find_packages, Extension import os import subprocess import re import sys # TODO: make this clean GSL_DIR = os.getenv('GSL_DIR', None) if not GSL_DIR: print("Warning: GSL_DIR is not set, this might lead to errors along the installation if there is no other version of GSL in the include dirs") # TODO: write code to know exact parent directory of this file. CWD = os.getcwd() # binary_c must be installed. binary_c_config = os.environ["BINARY_C"] + "/binary_c-config" binary_c_incdirs = ( subprocess.run([binary_c_config, "incdirs_list"], stdout=subprocess.PIPE) .stdout.decode("utf-8") .split() ) binary_c_libdirs = ( subprocess.run([binary_c_config, "libdirs_list"], stdout=subprocess.PIPE) .stdout.decode("utf-8") .split() ) binary_c_cflags = ( subprocess.run([binary_c_config, "cflags"], stdout=subprocess.PIPE) .stdout.decode("utf-8") .split() ) # binary_c_cflags.remove('-fvisibility=hidden') binary_c_libs = ( subprocess.run([binary_c_config, "libs_list"], stdout=subprocess.PIPE) .stdout.decode("utf-8") .split() ) # create list of tuples of defined macros binary_c_define_macros = [] defines = ( subprocess.run([binary_c_config, "define_macros"], stdout=subprocess.PIPE) .stdout.decode("utf-8") .split() ) lone = re.compile("^-D(.+)$") partner = re.compile("^-D(.+)=(.+)$") for x in defines: y = partner.match(x) if y: binary_c_define_macros.extend([(y.group(1), y.group(2))]) else: y = lone.match(x) if y: binary_c_define_macros.extend([(y.group(1), None)]) # add API header file API_h = os.environ["BINARY_C"] + "/src/API/binary_c_API.h" binary_c_define_macros.extend([("BINARY_C_API_H", API_h)]) # TODO: move the creeation of all the include stuff to here so its easier to print everything # print('\n') # print("binary_c_config", binary_c_config) # print("incdirs:",binary_c_incdirs) # print("binary_c_libdirs: ", binary_c_libdirs) # print("binary_c_cflags: ",binary_c_cflags) # print("binary_c_libs: ",binary_c_libs) # print("API_h:",API_h) # print("macros:",binary_c_define_macros) # print('\n') binary_c_python_api_module = Extension( # name="binarycpython.core.binary_c", name="binary_c_python_api", sources=["src/binary_c_python.c"], include_dirs=[ os.environ["BINARY_C"] + "/src", os.environ["BINARY_C"] + "/src/API", "include", ] + binary_c_incdirs + [GSL_DIR] if GSL_DIR else [], libraries=["binary_c"] + binary_c_libs + ["binary_c_api"], library_dirs=[ os.environ["BINARY_C"] + "/src", "./", os.path.join(CWD, "lib/"), # os.path.join(CWD, "binarycpython/core/"), ] + binary_c_libdirs, runtime_library_dirs=[ os.environ["BINARY_C"] + "/src", "./", os.path.join(CWD, "lib/"), # os.path.join(CWD, "binarycpython/core/"), ] + binary_c_libdirs, define_macros=[] + binary_c_define_macros, extra_objects=[], extra_compile_args=[], language="C", ) def readme(): with open("README.md") as f: return f.read() setup( name="binarycpython", version="0.1", description="This is a python API for binary_c by Rob Izzard and collaborators", author="Jeff Andrews and Robert Izzard and David Hendriks", author_email="andrews@physics.uoc.gr and r.izzard@surrey.ac.uk and rob.izzard@gmail.com and davidhendriks93@gmail.com", long_description=readme(), url="https://gitlab.eps.surrey.ac.uk/ri0005/binary_c-python", license="", package_dir={ "binarycpython": "binarycpython", "binarycpython.utils": "binarycpython/utils", # 'binarycpython.core': 'lib', }, packages=[ "binarycpython", "binarycpython.utils", # 'binarycpython.core', ], # package_data={ # 'binarycpython.core': ['libbinary_c_api.so'], # }, ext_modules=[binary_c_python_api_module], # binary_c must be loaded )