python-cnorxz/setup.py

91 lines
3.2 KiB
Python
Raw Normal View History

2023-02-21 19:31:14 +01:00
#!/usr/bin/env python
2024-02-06 01:41:49 +01:00
#import numpy
import setuptools
from distutils.core import setup, Extension
2023-02-21 19:31:14 +01:00
import sysconfig
2023-02-22 01:04:45 +01:00
import subprocess
2023-02-21 19:31:14 +01:00
libname = "cnorxz"
author = "Christian Zimmermann"
author_email = "chizeta@f3l.de"
2023-02-22 02:37:51 +01:00
path_to_cnorxz = "/home/chizeta/repos/cnorxz/install"
2023-02-22 01:04:45 +01:00
expected_cnorxz_version = "1.0.0" # dummy for now; in the future this is supposed to be the c++ version which is guaranteed to be compatible with py cnorxz
git_hash = subprocess.run(['git','rev-parse','HEAD'],stdout=subprocess.PIPE).stdout.decode('ascii')[:-1]
git_tags = subprocess.run(['git', 'tag', '-l', '--sort=refname', 'v*'],stdout=subprocess.PIPE).stdout.decode('ascii').split()
2023-02-22 02:37:51 +01:00
cnorxz_version = subprocess.run([path_to_cnorxz+"/bin/cnorxz-config",'--version'],stdout=subprocess.PIPE).stdout.decode('ascii')[:-1]
2023-02-22 01:04:45 +01:00
2023-02-22 02:37:51 +01:00
assert len(git_tags) != 0, "no version tags found"
git_tag = git_tags[-1]
version = git_tag[1:] + 'dev'
2023-02-22 13:21:47 +01:00
git_hash_tag = subprocess.run(['git','rev-list','-n','1',git_tag],stdout=subprocess.PIPE).stdout.decode('ascii')[:-1]
2023-02-22 02:37:51 +01:00
if git_hash_tag == git_hash and expected_cnorxz_version != cnorxz_version:
version = git_tag[1:]
2023-02-22 01:04:45 +01:00
2023-02-21 19:31:14 +01:00
inc_dirs = list()
2023-02-22 01:04:45 +01:00
if path_to_cnorxz != "":
inc_dirs.append( path_to_cnorxz + "/include/cnorxz" )
inc_dirs.append( "cnorxz/core/include" )
2024-02-06 01:41:49 +01:00
#inc_dirs.append( numpy.get_include() )
inc_dirs.append( "/home/chizeta/my_env/lib/python3.11/site-packages/numpy/core/include" )
2023-02-21 19:31:14 +01:00
lib_dirs = list()
lib_dirs.append( "/usr/lib" )
lib_dirs.append( "/usr/local/lib" )
2023-02-22 01:04:45 +01:00
if path_to_cnorxz != "":
inc_dirs.append( path_to_cnorxz + "/lib" )
lib_dirs.append( "/home/chizeta/repos/cnorxz/install/lib" )
2023-02-21 19:31:14 +01:00
extra_compile_args = sysconfig.get_config_var('CFLAGS').split()
2023-02-22 02:37:51 +01:00
cnorxz_flags = subprocess.run([path_to_cnorxz+"/bin/cnorxz-config",'--flags'],stdout=subprocess.PIPE).stdout.decode('ascii').split()
2024-02-06 01:41:49 +01:00
cnorxz_flags.remove("-Werror")
2024-02-08 01:01:47 +01:00
cnorxz_flags.append("-Wno-write-strings")
2023-02-22 02:37:51 +01:00
extra_compile_args += cnorxz_flags
2023-02-21 19:31:14 +01:00
default_extension_args = dict(
language = "c++",
include_dirs = inc_dirs,
libraries = [libname],
library_dirs = lib_dirs,
extra_compile_args = extra_compile_args,
)
if __name__ == "__main__":
print("Include directories:")
for d in inc_dirs:
print("\t",d)
print("Library directories:")
for d in lib_dirs:
print("\t",d)
#extensions = list()
#extensions.append(
# setuptools.Extension(
# #name = libname + ".core",
# name = libname,
# sources = [
# "cnorxz/core/core.cpp",
# "cnorxz/core/lib/array_wrapper.cpp"
# ],
# define_macros=[('HAVE_CEREAL',None)],
# **default_extension_args
# )
#)
2023-02-21 19:31:14 +01:00
# append further extensions (cereal, hdf5, mpi ...) here
setup(
2023-02-21 19:31:14 +01:00
name = libname,
packages = setuptools.find_packages(),
2023-02-22 01:04:45 +01:00
version = version,
2023-02-21 19:31:14 +01:00
include_dirs = inc_dirs,
ext_modules = [Extension(
2024-02-08 01:01:47 +01:00
'cnorxz', ['cnorxz/core/core.cpp','cnorxz/core/lib/array_wrapper.cpp','cnorxz/core/lib/range_wrapper.cpp'],
define_macros=[('HAVE_CEREAL',None)],
**default_extension_args
)],
#ext_modules = Cython.Build.cythonize(extensions),
2023-02-21 19:31:14 +01:00
author = author,
author_email = author_email,
)