KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
setup.py
Go to the documentation of this file.
1import os
2import shutil
3import sys
4import functools
5import warnings
6import platform
7import numpy
8from glob import glob
9from setuptools import setup, Extension
10from pybind11.setup_helpers import Pybind11Extension
11from Cython.Build import cythonize
12
13MAJOR_VERSION_NUM = '@KIDS_MAJOR_VERSION@'
14MINOR_VERSION_NUM = '@KIDS_MINOR_VERSION@'
15BUILD_INFO = '@KIDS_BUILD_VERSION@'
16GIT_VERSION = '@KIDS_GIT_VERSION@'
17IS_RELEASED = False
18
20 @functools.wraps(func)
21 def wrapper(*args, **kwargs):
22 warnings.warn(f"Function {func.__name__} is not recommended for use.", category=UserWarning)
23 return func(*args, **kwargs)
24 return wrapper
25
26@not_recommended
27def remove_package(mod, verbose):
28 try:
29 install_path = mod.__path__[0]
30 if os.path.exists(install_path) and verbose:
31 print(f'REMOVING "{install_path}"')
32 shutil.rmtree(install_path)
33 except (AttributeError, IndexError, OSError):
34 pass
35
36@not_recommended
37def uninstall(verbose=True):
38 try:
39 import pykids
40 remove_package(pykids, verbose)
41 except ImportError:
42 pass
43
44def report_error(message):
45 sys.stderr.write("ERROR: {}\n".format(message))
46 sys.exit(1)
47
49 GIT_REVISION = GIT_VERSION
50 VERSION = FULL_VERSION = f"{MAJOR_VERSION_NUM}.{MINOR_VERSION_NUM}.{BUILD_INFO}"
51 if not IS_RELEASED:
52 FULL_VERSION += f'.dev-{GIT_REVISION[:7]}'
53
54 with open('pykids/version.py', 'w') as f:
55 f.write(f"""
56# THIS FILE IS GENERATED FROM SETUP.PY
57short_version = '{VERSION}'
58version = '{VERSION}'
59full_version = '{FULL_VERSION}'
60git_revision = '{GIT_REVISION}'
61release = {str(IS_RELEASED)}
62KIDS_library_path = r'{os.getenv('KIDS_LIB_PATH')}'
63
64if not release:
65 version = full_version
66""")
67
69 if sys.version_info < (2, 7):
70 report_error("KIDS requires Python 2.7 or better.")
71 if platform.system() in ['Darwin', 'Windows']:
72 report_error(f"Not supported on platform {platform.system()}")
73
74 pykids_include_path = os.getenv('KIDS_INCLUDE_PATH')
75 if not pykids_include_path:
76 report_error("Set KIDS_INCLUDE_PATH to point to the include directory for KIDS")
77 pykids_lib_path = os.getenv('KIDS_LIB_PATH')
78 if not pykids_lib_path:
79 report_error("Set KIDS_LIB_PATH to point to the lib directory for KIDS")
80 library_dirs=[pykids_lib_path]
81 include_dirs=pykids_include_path.split(';') + [numpy.get_include()]
82
83 define_macros = [('MAJOR_VERSION', MAJOR_VERSION_NUM),
84 ('MINOR_VERSION', MINOR_VERSION_NUM)]
85
86 libraries = ['KIDS'] #, 'KIDSPlugin']
87
88 extension_args = {
89 "name": "pykids._kids",
90 "sources": ["swig/KIDSSwig.cxx"],
91 "include_dirs": include_dirs,
92 "define_macros": define_macros,
93 "library_dirs": library_dirs,
94 "libraries": libraries,
95 "extra_compile_args": ['-std=c++11'],
96 "extra_link_args": [],
97 "runtime_library_dirs":library_dirs,
98 }
99
100 print(f"library_dirs={library_dirs}")
101 print(f"include_dirs={include_dirs}")
102 print(f"libraries={libraries}")
103
104 setup_kwargs = {
105 "name": "KIDS",
106 "version": f"{MAJOR_VERSION_NUM}.{MINOR_VERSION_NUM}.{BUILD_INFO}",
107 "author": "Xin He | Liu-group",
108 "license": "Python Software Foundation License (BSD-like)",
109 "url": "https://github.com/xshinhe/KIDS",
110 "packages": [
111 "pykids",
112 ],
113 "package_data": {
114 "pykids": ["libpykids_v1.so"],
115 },
116 "platforms": ["Linux"],
117 "description": "Python wrapper for KIDS",
118 "long_description": """
119 KIDS (Kernel Integrated Dynamics Simulator) offers an open-source framework tailored for simulating
120 chemical and physical dynamics, with a primary focus on atomic and molecular scales in condensed matter.
121 It is designed for (classical / qauntum) dynamics simulation of small system, few-body system, reduced
122 systems, and even large many-particle (i.e. molecules &amp; condensed matter) systems. It provides a versatile
123 platform for the development of advanced algorithms, offering ease of use and accessibility at a minimal
124 cost.
125 """,
126 "ext_modules" : [
127 Extension(**extension_args),
128 Pybind11Extension(
129 "pykids.libpykids_v2",
130 sorted(glob("pybind11/libpykids_v2.cpp")),
131 include_dirs=include_dirs,
132 library_dirs=library_dirs,
133 libraries=libraries,
134 extra_compile_args=['-lKIDS', '-Wl,-rpath,/usr/local/kids/lib'],
135 extra_link_args=['-Wl,-R/usr/local/kids/lib'],
136 ),
137 Extension(
138 "pykids.ext.examples",
139 sources=[
140 "ext/examples/test.cpp",
141 # "ext/examples/test.pyx", # Cython
142 ],
143 include_dirs=include_dirs + [
144 "ext/examples/include",
145 numpy.get_include(),
146 ],
147 language="c++",
148 ),
149 ],
150 }
151
152 return setup_kwargs
153
154if __name__ == '__main__':
155 setupKeywords=build_setup_kwargs()
157 setup(**setupKeywords)
write_version_py()
Definition setup.py:48
not_recommended(func)
Definition setup.py:19
uninstall(verbose=True)
Definition setup.py:37
report_error(message)
Definition setup.py:44
remove_package(mod, verbose)
Definition setup.py:27
build_setup_kwargs()
Definition setup.py:68