Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
binary_c-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Izzard, Robert Dr (Maths & Physics)
binary_c-python
Commits
0f8a208a
Commit
0f8a208a
authored
3 years ago
by
dh00601
Browse files
Options
Downloads
Patches
Plain Diff
updating the methods for the setup
parent
fa68922b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
requirements.txt
+25
-0
25 additions, 0 deletions
requirements.txt
setup.py
+76
-101
76 additions, 101 deletions
setup.py
with
101 additions
and
101 deletions
requirements.txt
0 → 100644
+
25
−
0
View file @
0f8a208a
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
\ No newline at end of file
This diff is collapsed.
Click to expand it.
setup.py
+
76
−
101
View file @
0f8a208a
...
...
@@ -11,9 +11,25 @@ import setuptools
from
distutils.core
import
setup
,
Extension
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
():
"""
opens VERSION and returns version number
...
...
@@ -22,21 +38,36 @@ def version():
with
open
(
"
VERSION
"
)
as
file
:
return
file
.
read
().
strip
()
VERSION_NUMBER
=
version
()
# Functions
def
readme
():
"""
Opens readme file and returns content
"""
"""
Opens readme file and returns content
"""
with
open
(
"
README.md
"
)
as
file
:
return
file
.
read
()
def
license
():
"""
Opens license file and returns the content
"""
"""
Opens license file and returns the content
"""
with
open
(
"
LICENSE.md
"
)
as
file
:
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
):
"""
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):
)
assert
installed_binary_c_version
in
required_binary_c_versions
,
message
def
execute_make
():
"""
Function to execute the makefile.
...
...
@@ -74,9 +104,25 @@ def execute_make():
print
(
stdout
.
decode
(
"
utf-8
"
))
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
)
...
...
@@ -92,59 +138,23 @@ if not BINARY_C_DIR:
)
quit
(
1
)
# TODO: write code to know exact parent directory of this file.
CWD
=
os
.
getcwd
()
############################################################
# Getting information from binary_c
############################################################
# binary_c must be installed.
BINARY_C_CONFIG
=
os
.
path
.
join
(
BINARY_C_DIR
,
"
binary_c-config
"
)
BINARY_C_VERSION
=
(
subprocess
.
run
([
BINARY_C_CONFIG
,
"
version
"
],
stdout
=
subprocess
.
PIPE
,
check
=
True
)
.
stdout
.
decode
(
"
utf-8
"
)
.
split
()
)
BINARY_C_VERSION
=
call_binary_c_config
(
BINARY_C_DIR
,
"
version
"
)
check_version
(
BINARY_C_VERSION
[
0
],
REQUIRED_BINARY_C_VERSIONS
)
BINARY_C_INCDIRS
=
(
subprocess
.
run
(
[
BINARY_C_CONFIG
,
"
incdirs_list
"
],
stdout
=
subprocess
.
PIPE
,
check
=
True
)
.
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_INCDIRS
=
call_binary_c_config
(
BINARY_C_DIR
,
"
incdirs_list
"
)
BINARY_C_LIBDIRS
=
call_binary_c_config
(
BINARY_C_DIR
,
"
libdirs_list
"
)
BINARY_C_CFLAGS
=
call_binary_c_config
(
BINARY_C_DIR
,
"
cflags
"
)
# 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
()
)
BINARY_C_LIBS
=
call_binary_c_config
(
BINARY_C_DIR
,
"
libs_list
"
)
BINARY_C_DEFINES
=
call_binary_c_config
(
BINARY_C_DIR
,
"
define_macros
"
)
# create list of tuples of defined 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(.+)$
"
)
PARTNER
=
re
.
compile
(
"
^-D(.+)=(.+)$
"
)
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
"
)
############################################################
#
S
et
t
in
g
all directories and
LIBRARIES to their final valu
es
#
D
et
erm
in
e
all directories and
librari
es
############################################################
INCLUDE_DIRS
=
[
os
.
path
.
join
(
BINARY_C_DIR
,
"
src
"
),
os
.
path
.
join
(
BINARY_C_DIR
,
"
src
"
,
"
API
"
),
...
...
@@ -176,14 +187,14 @@ LIBRARIES = ["binary_c"] + BINARY_C_LIBS
LIBRARY_DIRS
=
[
os
.
path
.
join
(
BINARY_C_DIR
,
"
src
"
),
"
./
"
,
os
.
path
.
join
(
CWD
,
"
lib/
"
),
os
.
path
.
join
(
CWD
,
"
binarycpython/
"
),
os
.
path
.
join
(
this_file_dir
,
"
lib/
"
),
os
.
path
.
join
(
this_file_dir
,
"
binarycpython/
"
),
]
+
BINARY_C_LIBDIRS
RUNTIME_LIBRARY_DIRS
=
[
os
.
path
.
join
(
BINARY_C_DIR
,
"
src
"
),
"
./
"
,
os
.
path
.
join
(
CWD
,
"
lib/
"
),
os
.
path
.
join
(
this_file_dir
,
"
lib/
"
),
]
+
BINARY_C_LIBDIRS
# filter out duplicates
...
...
@@ -193,21 +204,8 @@ LIBRARIES = list(dict.fromkeys(LIBRARIES))
LIBRARY_DIRS
=
list
(
dict
.
fromkeys
(
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
(
...
...
@@ -223,8 +221,9 @@ BINARY_C_PYTHON_API_MODULE = Extension(
language
=
"
C
"
,
)
headers
=
[
"
src/includes/header.h
"
]
############################################################
#
Making the extension function
#
Custom build command
############################################################
# Override build command
...
...
@@ -233,10 +232,13 @@ class CustomBuildCommand(distutils.command.build.build):
# Run the original build command
distutils
.
command
.
build
.
build
.
run
(
self
)
############################################################
# Main setup function call
############################################################
setup
(
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
(
"
,
"
.
join
(
REQUIRED_BINARY_C_VERSIONS
),
"
,
"
.
join
(
REQUIRED_BINARY_C_VERSIONS
),
...
...
@@ -244,7 +246,6 @@ setup(
author
=
"
David Hendriks
"
,
author_email
=
"
davidhendriks93@gmail.com
"
,
long_description
=
readme
(),
# long_description="hello",
long_description_content_type
=
"
text/markdown
"
,
url
=
"
https://gitlab.eps.surrey.ac.uk/ri0005/binary_c-python
"
,
license
=
"
gpl
"
,
...
...
@@ -261,33 +262,7 @@ setup(
"
binarycpython.tests
"
,
"
binarycpython.tests.tests_population_extensions
"
,
],
install_requires
=
[
# TODO: can we centralise this?
"
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
"
,
],
install_requires
=
,
include_package_data
=
True
,
ext_modules
=
[
BINARY_C_PYTHON_API_MODULE
],
# binary_c must be loaded
classifiers
=
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment