KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
setup_old1.py
Go to the documentation of this file.
1import ast
2import re
3import os
4import sys
5import platform
6import numpy
7from glob import glob
8from setuptools import setup
9from Cython.Build import cythonize
10
11MAJOR_VERSION_NUM='@KIDS_MAJOR_VERSION@'
12MINOR_VERSION_NUM='@KIDS_MINOR_VERSION@'
13BUILD_INFO='@KIDS_BUILD_VERSION@'
14GIT_VERSION='@KIDS_GIT_VERSION@'
15IS_RELEASED=False
16
17__author__ = "Xin He"
18__version__ = "%s.%s" % (MAJOR_VERSION_NUM, MINOR_VERSION_NUM)
19
20def reportError(message):
21 sys.stdout.write("ERROR: ")
22 sys.stdout.write(message)
23 sys.stdout.write("\nExiting\n")
24 sys.exit(1)
25
27 for file in os.listdir(dir):
28 path = os.path.join(dir, file)
29 if os.path.isdir(path):
30 removeRecursive(path)
31 else:
32 os.remove(path)
33 os.rmdir(dir)
34
35def removePackage(mod, verbose):
36 try:
37 pathList = mod.__path__
38 except AttributeError:
39 return
40 if len(pathList) > 1:
41 raise Exception("more than one item in KIDS.__path__")
42 installPath = pathList[0]
43 if os.path.exists(installPath):
44 if verbose:
45 sys.stdout.write('REMOVING "%s"\n' % installPath)
46 removeRecursive(installPath)
47
48def uninstall(verbose=True):
49 save_path=sys.path[:]
50 sys.path=[]
51 for item in save_path:
52 if item!='.' and item!=os.getcwd():
53 sys.path.append(item)
54 try:
55 import pykids
56 removePackage(pykids, verbose)
57 except ImportError:
58 pass
59 sys.path=save_path
60
62 filename="pykids/version.py", # @deprecated from cmake config other than from file
63 major_version_num=MAJOR_VERSION_NUM,
64 minor_version_num=MINOR_VERSION_NUM,
65 build_info=BUILD_INFO):
66 cnt = """
67# THIS FILE IS GENERATED FROM KIDS SETUP.PY
68short_version = '%(version)s'
69version = '%(version)s'
70full_version = '%(full_version)s'
71git_revision = '%(git_revision)s'
72release = %(isrelease)s
73KIDS_library_path = r'%(path)s'
74
75if not release:
76 version = full_version
77"""
78 ''' @deprecated
79 if os.path.exists(filename):
80 with open(filename) as f:
81 text = f.read()
82 match = re.search(r"git_revision\s+=\s+(.*)", text, re.MULTILINE)
83 try:
84 git_revision = ast.literal_eval(match.group(1))
85 except:
86 git_revision = 'Unknown'
87 else:
88 git_revision = 'Unknown'
89 '''
90 git_revision = GIT_VERSION
91 version = full_version = '%s.%s.%s' % (major_version_num, minor_version_num, build_info)
92 if not IS_RELEASED:
93 full_version += '.dev-' + git_revision[:7]
94 with open(filename, 'w') as a:
95 a.write(cnt % {'version': version,
96 'full_version' : full_version,
97 'git_revision' : git_revision,
98 'isrelease': str(IS_RELEASED),
99 'path': os.getenv('KIDS_LIB_PATH')})
100
101def buildKeywordDictionary(major_version_num=MAJOR_VERSION_NUM,
102 minor_version_num=MINOR_VERSION_NUM,
103 build_info=BUILD_INFO):
104 from setuptools import Extension
105 try:
106 from pybind11.setup_helpers import Pybind11Extension
107 print('%'*100)
108 except ImportError:
109 from setuptools import Extension as Pybind11Extension
110
111 if platform.system() == "Windows" or platform.system() == 'Darwin':
112 reportError("Not support now for platform %s"%platform.system())
113
114 setupKeywords = {}
115 setupKeywords["name"] = "KIDS"
116 setupKeywords["version"] = "%s.%s.%s" % (major_version_num,
117 minor_version_num,
118 build_info)
119 setupKeywords["author"] = "Xin He | Liu-group"
120 setupKeywords["license"] = "Python Software Foundation License (BSD-like)"
121 setupKeywords["url"] = "https://github.com/xshinhe/KIDS"
122 setupKeywords["packages"] = [
123 "pykids",
124 "pykids.ext",
125 # "pykids.chem",
126 # "pykids.core",
127 # "pykids.models",
128 # "pykids.solvers",
129 # "pykids.app"
130 ]
131 setupKeywords["data_files"] = []
132 setupKeywords["package_data"] = {"pykids" : [
133 "libpykids_v1.so",
134 ],
135 # "pykids.app" : ['data/*.json', 'data/*.dat', 'data/*.ds'],
136 }
137 setupKeywords["platforms"] = ["Linux"] #, "Mac OS X", "Windows"]
138 setupKeywords["description"] = "Python wrapper for KIDS"
139 setupKeywords["long_description"] = \
140 """
141 KIDS (Kernel Integrated Dynamics Simulator) offers an open-source framework tailored for simulating
142 chemical and physical dynamics, with a primary focus on atomic and molecular scales in condensed matter.
143 It is designed for (classical / qauntum) dynamics simulation of small system, few-body system, reduced
144 systems, and even large many-particle (i.e. molecules & condensed matter) systems. It provides a versatile
145 platform for the development of advanced algorithms, offering ease of use and accessibility at a minimal
146 cost.
147 """
148
149 define_macros = [('MAJOR_VERSION', major_version_num),
150 ('MINOR_VERSION', minor_version_num)]
151
152 libraries=['KIDS'] #, 'KIDSPlugins']
153
154 pykids_include_path = os.getenv('KIDS_INCLUDE_PATH')
155 if not pykids_include_path:
156 reportError("Set KIDS_INCLUDE_PATH to point to the include directory for KIDS")
157 pykids_lib_path = os.getenv('KIDS_LIB_PATH')
158 if not pykids_lib_path:
159 reportError("Set KIDS_LIB_PATH to point to the lib directory for KIDS")
160
161
162
163 extra_compile_args=['-std=c++11']
164 extra_link_args=[] # fix for crossing platform @todo
165 library_dirs=[pykids_lib_path]
166 include_dirs=pykids_include_path.split(';')
167 include_dirs.append(numpy.get_include())
168 extensionArgs = {"name": "pykids._kids", # swig library
169 "sources": ["swig/KIDSSwig.cxx"],
170 "include_dirs": include_dirs,
171 "define_macros": define_macros,
172 "library_dirs": library_dirs,
173 "libraries": libraries,
174 "extra_compile_args": extra_compile_args,
175 "extra_link_args": extra_link_args}
176 extensionArgs["runtime_library_dirs"] = library_dirs
177 setupKeywords["ext_modules"] = [Extension(**extensionArgs)]
178
179
180 setupKeywords["ext_modules"] += [Pybind11Extension(
181 "pykids.libpykids_v2",
182 sorted(glob("pybind11/libpykids_v2.cpp")),
183 # include_dirs=include_dirs,
184 # library_dirs=library_dirs,
185 ),
186 ]
187
188
190 setupKeywords["ext_modules"] += cythonize(Extension(
191 "pykids.ext.examples",
192 sources=[
193 "ext/examples/src/test.cpp",
194 "ext/examples/test.pyx",
195 ],
196 include_dirs=include_dirs +[
197 "ext/examples/include",
198 "ext/examples/",
199 numpy.get_include(),
200 ],
201 language="c++",
202 ))
203
204 outputString = ''
205 firstTab = 40
206 secondTab = 60
207 for key in sorted(iter(setupKeywords)):
208 value = setupKeywords[key]
209 outputString += key.rjust(firstTab) + str( value ).rjust(secondTab) + "\n"
210 # sys.stdout.write("%s" % outputString)
211 return setupKeywords
212
213def main():
214 if sys.version_info < (2, 7):
215 reportError("KIDS requires Python 2.7 or better.")
216 if platform.system() == 'Darwin' or platform.system() == 'Windows':
217 reportError("Not support now for platform %s"%platform.system())
218 try:
219 uninstall()
220 except:
221 pass
222 setupKeywords=buildKeywordDictionary()
224 print(setupKeywords)
225 setup(**setupKeywords)
226
227if __name__ == '__main__':
228 main()
removeRecursive(dir)
Definition setup_old1.py:26
reportError(message)
Definition setup_old1.py:20
uninstall(verbose=True)
Definition setup_old1.py:48
writeVersionPy(filename="pykids/version.py", major_version_num=MAJOR_VERSION_NUM, minor_version_num=MINOR_VERSION_NUM, build_info=BUILD_INFO)
Definition setup_old1.py:65
buildKeywordDictionary(major_version_num=MAJOR_VERSION_NUM, minor_version_num=MINOR_VERSION_NUM, build_info=BUILD_INFO)
removePackage(mod, verbose)
Definition setup_old1.py:35