Newer
Older
from distutils.core import setup, Extension
# 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")
David Hendriks
committed
# TODO: write code to know exact parent directory of this file.
CWD = os.getcwd()
David Hendriks
committed
# 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(.+)=(.+)$")
David Hendriks
committed
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(
David Hendriks
committed
# 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",
libraries=["binary_c"] + binary_c_libs + ["binary_c_api"],
library_dirs=[
os.environ["BINARY_C"] + "/src",
"./",
os.path.join(CWD, "lib/"),
David Hendriks
committed
# os.path.join(CWD, "binarycpython/core/"),
]
+ binary_c_libdirs,
runtime_library_dirs=[
os.environ["BINARY_C"] + "/src",
"./",
os.path.join(CWD, "lib/"),
David Hendriks
committed
# os.path.join(CWD, "binarycpython/core/"),
]
+ binary_c_libdirs,
define_macros=[] + binary_c_define_macros,
extra_objects=[],
extra_compile_args=[],
David Hendriks
committed
language="C",
with open("README.md") as f:
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",
David Hendriks
committed
# 'binarycpython.core': 'lib',
David Hendriks
committed
packages=[
"binarycpython",
"binarycpython.utils",
David Hendriks
committed
# 'binarycpython.core',
David Hendriks
committed
],
David Hendriks
committed
# package_data={
# 'binarycpython.core': ['libbinary_c_api.so'],
# },
ext_modules=[binary_c_python_api_module], # binary_c must be loaded