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
f32bc908
Commit
f32bc908
authored
4 years ago
by
David Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
Modified makefile s.t. setup actually builds the libraries
parent
07f0c5a4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Makefile
+17
-13
17 additions, 13 deletions
Makefile
setup.py
+57
-16
57 additions, 16 deletions
setup.py
with
74 additions
and
29 deletions
Makefile
+
17
−
13
View file @
f32bc908
...
@@ -22,6 +22,7 @@ TARGET_LIB_DIR := lib
...
@@ -22,6 +22,7 @@ TARGET_LIB_DIR := lib
CC
:=
gcc
CC
:=
gcc
LD
:=
gcc
LD
:=
gcc
MAKE
:=
/usr/bin/make
MAKE
:=
/usr/bin/make
MKDIR_P
:=
mkdir
-p
# Libraries
# Libraries
LIBS
:=
-lbinary_c
$(
shell
$(
BINARY_C
)
/binary_c-config
--libs
)
LIBS
:=
-lbinary_c
$(
shell
$(
BINARY_C
)
/binary_c-config
--libs
)
...
@@ -38,27 +39,30 @@ OBJECTS := $(C_SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
...
@@ -38,27 +39,30 @@ OBJECTS := $(C_SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
OBJ_FLAGS
:=
-c
OBJ_FLAGS
:=
-c
# Shared lib files and flags
# Shared lib files and flags
SO_NAME
:=
$(
TARGET_LIB_DIR
)
/libbinary_c_api.so
SO_NAME
:=
$(
TARGET_LIB_DIR
)
/libbinary_c_
python_
api.so
SO_FLAGS
:=
-shared
SO_FLAGS
:=
-shared
# To create python shared library
all
:
create_directories create_objects create_library
PY_EXEC
:=
python3
PY_SETUP
:=
setup.py
#PY_OPTIONS := build_ext --build-lib $(TARGET_LIB_DIR)
PY_OPTIONS
:=
build_ext
--inplace
all
:
debug
:
create_directories create_objects_debug create_library_debug
create_directories
:
${
MKDIR_P
}
${
TARGET_LIB_DIR
}
${
MKDIR_P
}
${
OBJ_DIR
}
create_objects
:
$(
CC
)
-DBINARY_C
=
$(
BINARY_C
)
$(
CFLAGS
)
$(
INCDIRS
)
$(
C_SRC
)
-o
$(
OBJECTS
)
$(
OBJ_FLAGS
)
$(
LIBS
)
$(
CC
)
-DBINARY_C
=
$(
BINARY_C
)
$(
CFLAGS
)
$(
INCDIRS
)
$(
C_SRC
)
-o
$(
OBJECTS
)
$(
OBJ_FLAGS
)
$(
LIBS
)
$(
CC
)
-DBINARY_C
=
$(
BINARY_C
)
$(
SO_FLAGS
)
-o
$(
SO_NAME
)
$(
OBJECTS
)
$(
PY_EXEC
)
$(
PY_SETUP
)
$(
PY_OPTIONS
)
debug
:
create_objects_
debug
:
$(
CC
)
-DBINARY_C
=
$(
BINARY_C
)
-DBINARY_C_PYTHON_DEBUG
$(
CFLAGS
)
$(
INCDIRS
)
$(
C_SRC
)
-o
$(
OBJECTS
)
$(
OBJ_FLAGS
)
$(
LIBS
)
$(
CC
)
-DBINARY_C
=
$(
BINARY_C
)
-DBINARY_C_PYTHON_DEBUG
$(
CFLAGS
)
$(
INCDIRS
)
$(
C_SRC
)
-o
$(
OBJECTS
)
$(
OBJ_FLAGS
)
$(
LIBS
)
$(
CC
)
-DBINARY_C
=
$(
BINARY_C
)
-DBINARY_C_PYTHON_DEBUG
$(
SO_FLAGS
)
-o
$(
SO_NAME
)
$(
OBJECTS
)
$(
PY_EXEC
)
$(
PY_SETUP
)
$(
PY_OPTIONS
)
create_library
:
$(
CC
)
-DBINARY_C
=
$(
BINARY_C
)
$(
SO_FLAGS
)
-o
$(
SO_NAME
)
$(
OBJECTS
)
create_library_debug
:
$(
CC
)
-DBINARY_C
=
$(
BINARY_C
)
-DBINARY_C_PYTHON_DEBUG
$(
SO_FLAGS
)
-o
$(
SO_NAME
)
$(
OBJECTS
)
test
:
echo_vars
:
@
echo
OBJECTS:
$(
OBJECTS
)
@
echo
OBJECTS:
$(
OBJECTS
)
@
echo
LIBS:
$(
LIBS
)
@
echo
LIBS:
$(
LIBS
)
@
echo
C_SRC:
$(
C_SRC
)
@
echo
C_SRC:
$(
C_SRC
)
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
57
−
16
View file @
f32bc908
"""
"""
Setup script for binarycpython
Setup script for binarycpython
"""
"""
import
setuptools
from
distutils.core
import
setup
,
Extension
import
os
import
os
import
subprocess
import
subprocess
import
re
import
re
import
sys
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.
# Functions
# Functions
def
readme
():
def
readme
():
...
@@ -24,13 +29,39 @@ def license():
...
@@ -24,13 +29,39 @@ def license():
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
"""
message
=
"""
message
=
"""
The binary_c version that is installed ({}) does not match the binary_c versions ({})
Something went wrong. Make sure that binary_c config exists.
Possibly the binary_c version that is installed ({}) does not match the binary_c versions ({})
that this release of the binary_c python module requires.
that this release of the binary_c python module requires.
"""
.
format
(
"""
.
format
(
installed_binary_c_version
,
required_binary_c_versions
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
():
"""
Function to execute the makefile.
This makefile builds the binary_c_python_api library that python will use to interface wth
"""
# Custom extra command:
make_command
=
[
"
make
"
]
p
=
subprocess
.
run
(
make_command
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
stdout
=
p
.
stdout
# stdout = normal output
stderr
=
p
.
stderr
# stderr = error output
if
p
.
returncode
!=
0
:
print
(
"
Something went wrong when executing the makefile:
"
)
print
(
stderr
.
decode
(
'
utf-8
'
))
print
(
"
Aborting
"
)
sys
.
exit
(
-
1
)
else
:
print
(
stdout
.
decode
(
"
utf-8
"
))
print
(
"
Successfully built the libbinary_c_api.so
"
)
###
###
REQUIRED_BINARY_C_VERSIONS
=
[
"
2.1.7
"
]
REQUIRED_BINARY_C_VERSIONS
=
[
"
2.1.7
"
]
...
@@ -129,7 +160,7 @@ INCLUDE_DIRS = (
...
@@ -129,7 +160,7 @@ INCLUDE_DIRS = (
else
[]
else
[]
)
)
LIBRARIES
=
[
"
binary_c
"
]
+
BINARY_C_LIBS
+
[
"
binary_c_api
"
]
LIBRARIES
=
[
"
binary_c
"
]
+
BINARY_C_LIBS
+
[
"
binary_c_
python_
api
"
]
LIBRARY_DIRS
=
[
LIBRARY_DIRS
=
[
os
.
path
.
join
(
BINARY_C_DIR
,
"
src
"
),
os
.
path
.
join
(
BINARY_C_DIR
,
"
src
"
),
...
@@ -163,7 +194,6 @@ RUNTIME_LIBRARY_DIRS = list(dict.fromkeys(RUNTIME_LIBRARY_DIRS))
...
@@ -163,7 +194,6 @@ RUNTIME_LIBRARY_DIRS = list(dict.fromkeys(RUNTIME_LIBRARY_DIRS))
# print("macros: ", str(BINARY_C_DEFINE_MACROS) + "\n")
# print("macros: ", str(BINARY_C_DEFINE_MACROS) + "\n")
# print('\n')
# print('\n')
#quit()
############################################################
############################################################
# Making the extension function
# Making the extension function
############################################################
############################################################
...
@@ -171,7 +201,7 @@ RUNTIME_LIBRARY_DIRS = list(dict.fromkeys(RUNTIME_LIBRARY_DIRS))
...
@@ -171,7 +201,7 @@ RUNTIME_LIBRARY_DIRS = list(dict.fromkeys(RUNTIME_LIBRARY_DIRS))
BINARY_C_PYTHON_API_MODULE
=
Extension
(
BINARY_C_PYTHON_API_MODULE
=
Extension
(
# name="binarycpython.core.binary_c",
# name="binarycpython.core.binary_c",
name
=
"
binary
_c_
python
_api
"
,
name
=
"
binary
c
python
._binary_c_bindings
"
,
sources
=
[
"
src/binary_c_python.c
"
],
sources
=
[
"
src/binary_c_python.c
"
],
include_dirs
=
INCLUDE_DIRS
,
include_dirs
=
INCLUDE_DIRS
,
libraries
=
LIBRARIES
,
libraries
=
LIBRARIES
,
...
@@ -187,6 +217,16 @@ BINARY_C_PYTHON_API_MODULE = Extension(
...
@@ -187,6 +217,16 @@ BINARY_C_PYTHON_API_MODULE = Extension(
# Making the extension function
# Making the extension function
############################################################
############################################################
# Override build command
class
CustomBuildCommand
(
distutils
.
command
.
build
.
build
):
def
run
(
self
):
execute_make
()
# Run the original build command
# print(super().run())
distutils
.
command
.
build
.
build
.
run
(
self
)
setup
(
setup
(
name
=
"
binarycpython
"
,
name
=
"
binarycpython
"
,
version
=
"
0.2
"
,
version
=
"
0.2
"
,
...
@@ -201,22 +241,20 @@ setup(
...
@@ -201,22 +241,20 @@ setup(
),
),
author
=
"
David Hendriks
"
,
author
=
"
David Hendriks
"
,
author_email
=
"
davidhendriks93@gmail.com
"
,
author_email
=
"
davidhendriks93@gmail.com
"
,
long_description_content_type
=
'
text/markdown
'
,
long_description
=
readme
(),
long_description
=
readme
(),
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
"
,
package_dir
=
{
keywords
=
[
'
binary_c
'
,
'
astrophysics
'
,
'
stellar evolution
'
,
'
population synthesis
'
],
# Keywords that define your package best
"
binarycpython
"
:
"
binarycpython
"
,
"
binarycpython.utils
"
:
"
binarycpython/utils
"
,
# 'binarycpython.core': 'lib',
},
packages
=
[
packages
=
[
"
binarycpython
"
,
"
binarycpython
"
,
"
binarycpython.utils
"
,
"
binarycpython.utils
"
,
# 'binarycpython.core',
"
binarycpython.core
"
,
"
binarycpython.tests
"
,
"
binarycpython.tests.core
"
,
],
],
# package_data={
install_requires
=
[
"
numpy
"
,
"
pytest
"
,
"
h5py
"
],
# 'binarycpython.core': ['libbinary_c_api.so'],
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
=
[
...
@@ -231,4 +269,7 @@ setup(
...
@@ -231,4 +269,7 @@ setup(
"
Topic :: Scientific/Engineering :: Physics
"
,
"
Topic :: Scientific/Engineering :: Physics
"
,
"
Topic :: Software Development :: Libraries :: Python Modules
"
,
"
Topic :: Software Development :: Libraries :: Python Modules
"
,
],
],
cmdclass
=
{
'
build
'
:
CustomBuildCommand
},
)
)
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