Newer
Older
from distutils.core import setup, Extension
# from setuptools import setup, find_packages, Extension
import os
import subprocess
import re
import sys
GSL_DIR = os.getenv("GSL_DIR", None)
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()
############################################################
# Getting information from binary_c
############################################################
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)])
############################################################
# 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 []
)
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
os.environ["BINARY_C"] + "/src",
"./",
os.path.join(CWD, "lib/"),
# os.path.join(CWD, "binarycpython/core/"),
] + binary_c_libdirs
# 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')
############################################################
# Making the extension function
############################################################
# TODO: fix that this one also compiles the code itself
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=[],
David Hendriks
committed
language="C",
with open("README.md") as f:
############################################################
# Making the extension function
############################################################
name="binarycpython",
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",
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