Skip to content
Snippets Groups Projects
setup.py 4.33 KiB
Newer Older
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

David Hendriks's avatar
David Hendriks committed
# 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_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(.+)=(.+)$")
    if y:
        binary_c_define_macros.extend([(y.group(1), y.group(2))])
        if y:
            binary_c_define_macros.extend([(y.group(1), None)])
API_h = os.environ["BINARY_C"] + "/src/API/binary_c_API.h"
binary_c_define_macros.extend([("BINARY_C_API_H", API_h)])
David Hendriks's avatar
David Hendriks committed
# 
include_dirs = [
        os.environ["BINARY_C"] + "/src",
        os.environ["BINARY_C"] + "/src/API",
David Hendriks's avatar
David Hendriks committed
        "include", ] + binary_c_incdirs + [os.path.join(GSL_DIR,'include')] 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/"),
David Hendriks's avatar
David Hendriks committed
    ] + binary_c_libdirs

runtime_library_dirs = [
        os.environ["BINARY_C"] + "/src",
        "./",
        os.path.join(CWD, "lib/"),
        # os.path.join(CWD, "binarycpython/core/"),
David Hendriks's avatar
David Hendriks committed
    ] + binary_c_libdirs

# TODO: move the creeation of all the include stuff to here so its easier to print everything
David Hendriks's avatar
David Hendriks committed
# print('\n')
# print("binary_c_config: ", str(binary_c_config) + "\n")
# print("incdirs: ", str(include_dirs) + "\n")
# print("binary_c_libs: ", str(binary_c_libs) + "\n")
# print("libraries: ", str(libraries) + "\n")
# print("library_dirs: ", str(library_dirs) + "\n")
# print("runtime_library_dirs: ", str(runtime_library_dirs) + "\n")
# print("binary_c_cflags: ", str(binary_c_cflags) + "\n")
# print("API_h: ", str(API_h) + "\n")
# print("macros: ", str(binary_c_define_macros) + "\n")
# print('\n')
David Hendriks's avatar
David Hendriks committed

binary_c_python_api_module = Extension(
    # name="binarycpython.core.binary_c",
    name="binary_c_python_api",
    sources=["src/binary_c_python.c"],
    include_dirs= include_dirs,
    libraries=libraries,
    library_dirs=library_dirs,
    runtime_library_dirs=runtime_library_dirs,
    define_macros=[] + binary_c_define_macros,
    extra_objects=[],
    extra_compile_args=[],
def readme():
    with open("README.md") as f:
        return f.read()

    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",
    package_dir={
        "binarycpython": "binarycpython",
        "binarycpython.utils": "binarycpython/utils",
        "binarycpython",
        "binarycpython.utils",
    # package_data={
    #     'binarycpython.core': ['libbinary_c_api.so'],
    # },
    ext_modules=[binary_c_python_api_module],  # binary_c must be loaded