Newer
Older
David Hendriks
committed
"""
Setup script for binarycpython
"""
from distutils.core import setup, Extension
# from setuptools import setup, find_packages, Extension
import os
import subprocess
import re
GSL_DIR = os.getenv("GSL_DIR", None)
David Hendriks
committed
"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"
BINARY_C_DIR = os.getenv("BINARY_C", None)
if not BINARY_C_DIR:
print("Error: the BINARY_C environment variable is not set. Aborting setup")
quit()
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.path.join(BINARY_C_DIR, "binary_c-config")
David Hendriks
committed
BINARY_C_INCDIRS = (
subprocess.run(
[BINARY_C_CONFIG, "incdirs_list"], stdout=subprocess.PIPE, check=True
)
.stdout.decode("utf-8")
.split()
)
David Hendriks
committed
BINARY_C_LIBDIRS = (
subprocess.run(
[BINARY_C_CONFIG, "libdirs_list"], stdout=subprocess.PIPE, check=True
)
.stdout.decode("utf-8")
.split()
)
David Hendriks
committed
BINARY_C_CFLAGS = (
subprocess.run([BINARY_C_CONFIG, "cflags"], stdout=subprocess.PIPE, check=True)
.stdout.decode("utf-8")
.split()
)
David Hendriks
committed
# BINARY_C_CFLAGS.remove('-fvisibility=hidden')
BINARY_C_LIBS = (
subprocess.run([BINARY_C_CONFIG, "libs_list"], stdout=subprocess.PIPE, check=True)
.stdout.decode("utf-8")
.split()
)
# create list of tuples of defined macros
David Hendriks
committed
BINARY_C_DEFINE_MACROS = []
DEFINES = (
subprocess.run(
[BINARY_C_CONFIG, "define_macros"], stdout=subprocess.PIPE, check=True
)
.stdout.decode("utf-8")
.split()
)
David Hendriks
committed
LONE = re.compile("^-D(.+)$")
PARTNER = re.compile("^-D(.+)=(.+)$")
for x in DEFINES:
y = PARTNER.match(x)
David Hendriks
committed
BINARY_C_DEFINE_MACROS.extend([(y.group(1), y.group(2))])
else:
David Hendriks
committed
y = LONE.match(x)
David Hendriks
committed
BINARY_C_DEFINE_MACROS.extend([(y.group(1), None)])
# add API header file
API_h = os.path.join(BINARY_C_DIR, "src", "API", "binary_c_API.h")
David Hendriks
committed
BINARY_C_DEFINE_MACROS.extend([("BINARY_C_API_H", API_h)])
############################################################
David Hendriks
committed
# Setting all directories and LIBRARIES to their final values
############################################################
David Hendriks
committed
INCLUDE_DIRS = (
[
os.path.join(BINARY_C_DIR, "src"),
os.path.join(BINARY_C_DIR, "src", "API"),
"include",
]
David Hendriks
committed
+ BINARY_C_INCDIRS
+ [os.path.join(GSL_DIR, "include")]
if GSL_DIR
else []
)
David Hendriks
committed
LIBRARIES = ["binary_c"] + BINARY_C_LIBS + ["binary_c_api"]
David Hendriks
committed
LIBRARY_DIRS = [
"./",
os.path.join(CWD, "lib/"),
# os.path.join(CWD, "binarycpython/core/"),
David Hendriks
committed
] + BINARY_C_LIBDIRS
David Hendriks
committed
RUNTIME_LIBRARY_DIRS = [
"./",
os.path.join(CWD, "lib/"),
# os.path.join(CWD, "binarycpython/core/"),
David Hendriks
committed
] + BINARY_C_LIBDIRS
David Hendriks
committed
# 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")
David Hendriks
committed
# print("macros: ", str(BINARY_C_DEFINE_MACROS) + "\n")
############################################################
# Making the extension function
############################################################
# TODO: fix that this one also compiles the code itself
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,
David Hendriks
committed
define_macros=[] + BINARY_C_DEFINE_MACROS,
extra_objects=[],
extra_compile_args=[],
David Hendriks
committed
language="C",
David Hendriks
committed
"""Opens readme file and returns content"""
with open("README.md") as file:
return file.read()
def license():
"""Opens license file and returns the content"""
with open("LICENSE.md") as file:
return file.read()
############################################################
# Making the extension function
############################################################
name="binarycpython",
David Hendriks
committed
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",
David Hendriks
committed
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'],
# },
David Hendriks
committed
ext_modules=[BINARY_C_PYTHON_API_MODULE], # binary_c must be loaded