Skip to content
Snippets Groups Projects
Commit 0f8a208a authored by dh00601's avatar dh00601
Browse files

updating the methods for the setup

parent fa68922b
No related branches found
No related tags found
No related merge requests found
...@@ -11,9 +11,25 @@ import setuptools ...@@ -11,9 +11,25 @@ import setuptools
from distutils.core import setup, Extension from distutils.core import setup, Extension
import distutils.command.build import distutils.command.build
# TODO: replace the tasks that call binary_c-config with a single function that handles the return status a bit better. #
this_file = os.path.abspath(__file__)
this_file_dir = os.path.dirname(this_file)
#########
###
REQUIRED_BINARY_C_VERSIONS = ["2.1.7", "2.2pre1", "2.2.0", "2.2.1"]
############################################################
# Defining functionality
############################################################
# Functions
def version(): def version():
""" """
opens VERSION and returns version number opens VERSION and returns version number
...@@ -22,21 +38,36 @@ def version(): ...@@ -22,21 +38,36 @@ def version():
with open("VERSION") as file: with open("VERSION") as file:
return file.read().strip() return file.read().strip()
VERSION_NUMBER = version()
# Functions
def readme(): def readme():
"""Opens readme file and returns content""" """
Opens readme file and returns content
"""
with open("README.md") as file: with open("README.md") as file:
return file.read() return file.read()
def license(): def license():
"""Opens license file and returns the content""" """
Opens license file and returns the content
"""
with open("LICENSE.md") as file: with open("LICENSE.md") as file:
return file.read() return file.read()
def requirements(directory):
"""
Opens requirements.txt and returns content as a list
"""
requirements_file = os.path.join(directory, 'requirements.txt')
# Read out file and construct list
requirements_list = []
with open(requirements_file) as f:
for el in f.readlines():
requirements_list.append(el.strip())
return requirements_list
def check_version(installed_binary_c_version, required_binary_c_versions): def check_version(installed_binary_c_version, required_binary_c_versions):
"""Function to check the installed version and compare it to the required version""" """Function to check the installed version and compare it to the required version"""
...@@ -49,7 +80,6 @@ def check_version(installed_binary_c_version, required_binary_c_versions): ...@@ -49,7 +80,6 @@ def check_version(installed_binary_c_version, required_binary_c_versions):
) )
assert installed_binary_c_version in required_binary_c_versions, message assert installed_binary_c_version in required_binary_c_versions, message
def execute_make(): def execute_make():
""" """
Function to execute the makefile. Function to execute the makefile.
...@@ -74,9 +104,25 @@ def execute_make(): ...@@ -74,9 +104,25 @@ def execute_make():
print(stdout.decode("utf-8")) print(stdout.decode("utf-8"))
print("Successfully built the libbinary_c_api.so") print("Successfully built the libbinary_c_api.so")
def call_binary_c_config(binary_c_dir, command):
"""
Function to call the binary_c config
"""
###
REQUIRED_BINARY_C_VERSIONS = ["2.1.7", "2.2pre1", "2.2.0", "2.2.1"] binary_c_config = os.path.join(BINARY_C_DIR, "binary_c-config")
command_result = (
subprocess.run([binary_c_config, command], stdout=subprocess.PIPE, check=True)
.stdout.decode("utf-8")
.split()
)
return command_result
############################################################
# First level checks
############################################################
#### ####
GSL_DIR = os.getenv("GSL_DIR", None) GSL_DIR = os.getenv("GSL_DIR", None)
...@@ -92,59 +138,23 @@ if not BINARY_C_DIR: ...@@ -92,59 +138,23 @@ if not BINARY_C_DIR:
) )
quit(1) quit(1)
# TODO: write code to know exact parent directory of this file.
CWD = os.getcwd()
############################################################ ############################################################
# Getting information from binary_c # Getting information from binary_c
############################################################ ############################################################
# binary_c must be installed. # binary_c must be installed.
BINARY_C_CONFIG = os.path.join(BINARY_C_DIR, "binary_c-config") BINARY_C_VERSION = call_binary_c_config(BINARY_C_DIR, "version")
BINARY_C_VERSION = (
subprocess.run([BINARY_C_CONFIG, "version"], stdout=subprocess.PIPE, check=True)
.stdout.decode("utf-8")
.split()
)
check_version(BINARY_C_VERSION[0], REQUIRED_BINARY_C_VERSIONS) check_version(BINARY_C_VERSION[0], REQUIRED_BINARY_C_VERSIONS)
BINARY_C_INCDIRS = ( BINARY_C_INCDIRS = call_binary_c_config(BINARY_C_DIR, "incdirs_list")
subprocess.run( BINARY_C_LIBDIRS = call_binary_c_config(BINARY_C_DIR, "libdirs_list")
[BINARY_C_CONFIG, "incdirs_list"], stdout=subprocess.PIPE, check=True BINARY_C_CFLAGS = call_binary_c_config(BINARY_C_DIR, "cflags")
)
.stdout.decode("utf-8")
.split()
)
BINARY_C_LIBDIRS = (
subprocess.run(
[BINARY_C_CONFIG, "libdirs_list"], stdout=subprocess.PIPE, check=True
)
.stdout.decode("utf-8")
.split()
)
BINARY_C_CFLAGS = (
subprocess.run([BINARY_C_CONFIG, "cflags"], stdout=subprocess.PIPE, check=True)
.stdout.decode("utf-8")
.split()
)
# BINARY_C_CFLAGS.remove('-fvisibility=hidden') # BINARY_C_CFLAGS.remove('-fvisibility=hidden')
BINARY_C_LIBS = ( BINARY_C_LIBS = call_binary_c_config(BINARY_C_DIR, "libs_list")
subprocess.run([BINARY_C_CONFIG, "libs_list"], stdout=subprocess.PIPE, check=True) BINARY_C_DEFINES = call_binary_c_config(BINARY_C_DIR, "define_macros")
.stdout.decode("utf-8")
.split()
)
# create list of tuples of defined macros # create list of tuples of defined macros
BINARY_C_DEFINE_MACROS = [] BINARY_C_DEFINE_MACROS = []
DEFINES = (
subprocess.run(
[BINARY_C_CONFIG, "define_macros"], stdout=subprocess.PIPE, check=True
)
.stdout.decode("utf-8")
.split()
)
LONE = re.compile("^-D(.+)$") LONE = re.compile("^-D(.+)$")
PARTNER = re.compile("^-D(.+)=(.+)$") PARTNER = re.compile("^-D(.+)=(.+)$")
for x in DEFINES: for x in DEFINES:
...@@ -160,8 +170,9 @@ for x in DEFINES: ...@@ -160,8 +170,9 @@ for x in DEFINES:
API_h = os.path.join(BINARY_C_DIR, "src", "API", "binary_c_API.h") API_h = os.path.join(BINARY_C_DIR, "src", "API", "binary_c_API.h")
############################################################ ############################################################
# Setting all directories and LIBRARIES to their final values # Determine all directories and libraries
############################################################ ############################################################
INCLUDE_DIRS = [ INCLUDE_DIRS = [
os.path.join(BINARY_C_DIR, "src"), os.path.join(BINARY_C_DIR, "src"),
os.path.join(BINARY_C_DIR, "src", "API"), os.path.join(BINARY_C_DIR, "src", "API"),
...@@ -176,14 +187,14 @@ LIBRARIES = ["binary_c"] + BINARY_C_LIBS ...@@ -176,14 +187,14 @@ LIBRARIES = ["binary_c"] + BINARY_C_LIBS
LIBRARY_DIRS = [ LIBRARY_DIRS = [
os.path.join(BINARY_C_DIR, "src"), os.path.join(BINARY_C_DIR, "src"),
"./", "./",
os.path.join(CWD, "lib/"), os.path.join(this_file_dir, "lib/"),
os.path.join(CWD, "binarycpython/"), os.path.join(this_file_dir, "binarycpython/"),
] + BINARY_C_LIBDIRS ] + BINARY_C_LIBDIRS
RUNTIME_LIBRARY_DIRS = [ RUNTIME_LIBRARY_DIRS = [
os.path.join(BINARY_C_DIR, "src"), os.path.join(BINARY_C_DIR, "src"),
"./", "./",
os.path.join(CWD, "lib/"), os.path.join(this_file_dir, "lib/"),
] + BINARY_C_LIBDIRS ] + BINARY_C_LIBDIRS
# filter out duplicates # filter out duplicates
...@@ -193,21 +204,8 @@ LIBRARIES = list(dict.fromkeys(LIBRARIES)) ...@@ -193,21 +204,8 @@ LIBRARIES = list(dict.fromkeys(LIBRARIES))
LIBRARY_DIRS = list(dict.fromkeys(LIBRARY_DIRS)) LIBRARY_DIRS = list(dict.fromkeys(LIBRARY_DIRS))
RUNTIME_LIBRARY_DIRS = list(dict.fromkeys(RUNTIME_LIBRARY_DIRS)) RUNTIME_LIBRARY_DIRS = list(dict.fromkeys(RUNTIME_LIBRARY_DIRS))
#
# 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 # Making the python-c binding module
############################################################ ############################################################
BINARY_C_PYTHON_API_MODULE = Extension( BINARY_C_PYTHON_API_MODULE = Extension(
...@@ -223,8 +221,9 @@ BINARY_C_PYTHON_API_MODULE = Extension( ...@@ -223,8 +221,9 @@ BINARY_C_PYTHON_API_MODULE = Extension(
language="C", language="C",
) )
headers = ["src/includes/header.h"] headers = ["src/includes/header.h"]
############################################################ ############################################################
# Making the extension function # Custom build command
############################################################ ############################################################
# Override build command # Override build command
...@@ -233,10 +232,13 @@ class CustomBuildCommand(distutils.command.build.build): ...@@ -233,10 +232,13 @@ class CustomBuildCommand(distutils.command.build.build):
# Run the original build command # Run the original build command
distutils.command.build.build.run(self) distutils.command.build.build.run(self)
############################################################
# Main setup function call
############################################################
setup( setup(
name="binarycpython", name="binarycpython",
version=VERSION_NUMBER, version=version(),
description="""This is a python API for binary_c (versions {}) by David Hendriks, Rob Izzard and collaborators. Based on the initial set up by Jeff andrews.""".format( description="""This is a python API for binary_c (versions {}) by David Hendriks, Rob Izzard and collaborators. Based on the initial set up by Jeff andrews.""".format(
",".join(REQUIRED_BINARY_C_VERSIONS), ",".join(REQUIRED_BINARY_C_VERSIONS),
",".join(REQUIRED_BINARY_C_VERSIONS), ",".join(REQUIRED_BINARY_C_VERSIONS),
...@@ -244,7 +246,6 @@ setup( ...@@ -244,7 +246,6 @@ setup(
author="David Hendriks", author="David Hendriks",
author_email="davidhendriks93@gmail.com", author_email="davidhendriks93@gmail.com",
long_description=readme(), long_description=readme(),
# long_description="hello",
long_description_content_type="text/markdown", long_description_content_type="text/markdown",
url="https://gitlab.eps.surrey.ac.uk/ri0005/binary_c-python", url="https://gitlab.eps.surrey.ac.uk/ri0005/binary_c-python",
license="gpl", license="gpl",
...@@ -261,33 +262,7 @@ setup( ...@@ -261,33 +262,7 @@ setup(
"binarycpython.tests", "binarycpython.tests",
"binarycpython.tests.tests_population_extensions", "binarycpython.tests.tests_population_extensions",
], ],
install_requires=[ # TODO: can we centralise this? install_requires=,
"astropy",
"cachetools",
"colorama",
"compress_pickle",
"datasize",
"diskcache",
"flufl.lock",
"h5py",
"halo",
"humanize",
"lib_programname",
"matplotlib",
"msgpack",
"numpy",
"pandas",
"pathos",
"psutil",
"pytest",
"py_rinterpolate",
"seaborn",
"setproctitle",
"str2bool",
"psutil",
"simplejson",
"strip-ansi",
],
include_package_data=True, include_package_data=True,
ext_modules=[BINARY_C_PYTHON_API_MODULE], # binary_c must be loaded ext_modules=[BINARY_C_PYTHON_API_MODULE], # binary_c must be loaded
classifiers=[ classifiers=[
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment