Skip to content
Snippets Groups Projects
setup.py 4.95 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

GSL_DIR = os.getenv("GSL_DIR", None)
David Hendriks's avatar
David Hendriks committed
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"
    )
David Hendriks's avatar
David Hendriks committed

# TODO: write code to know exact parent directory of this file.
CWD = os.getcwd()
David Hendriks's avatar
David Hendriks committed
############################################################
# Getting information from binary_c
############################################################

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
############################################################
# Setting all directories and libraries to their final values
############################################################
include_dirs = (
    [os.environ["BINARY_C"] + "/src", os.environ["BINARY_C"] + "/src/API", "include",]
    + binary_c_incdirs
    + [os.path.join(GSL_DIR, "include")]
    if GSL_DIR
    else []
)
David Hendriks's avatar
David Hendriks committed

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
David Hendriks's avatar
David Hendriks committed

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

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

David Hendriks's avatar
David Hendriks committed
############################################################
# Making the extension function
############################################################
# TODO: fix that this one also compiles the code itself

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,
David Hendriks's avatar
David Hendriks committed
    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()

David Hendriks's avatar
David Hendriks committed
############################################################
# Making the extension function
############################################################
David Hendriks's avatar
David Hendriks committed
    version="0.2",
    description="This is a python API for binary_c by David Hendriks, Rob Izzard and collaborators. Based on the initial set up by Jeff andrews",
    author=" David Hendriks, Robert Izzard and Jeff Andrews",
    author_email="davidhendriks93@gmail.com/d.hendriks@surrey.ac.uk, r.izzard@surrey.ac.uk/rob.izzard@gmail.com andrews@physics.uoc.gr",
    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