-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
114 lines (93 loc) · 3.12 KB
/
setup.py
File metadata and controls
114 lines (93 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
from pathlib import Path
from shutil import rmtree, copy2
from subprocess import check_call
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext
__author__ = "Materialab Research Group"
__contact__ = "oliviero.andreussi@unt.edu"
__version__ = "0.0.1"
__license__ = "GPL"
name = 'pyec'
description = "pyec: Environ Python interface",
long_description = """pyec turns Environ into an engine for embedding or for any other purpose."""
class MakeBuild(build_ext):
"""
Build instructions for wrapping Environ's Fortran code. Executes targets
from Makefile.
"""
def run(self):
"""Executes build."""
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext):
"""Builds extension."""
topdir = './'
self.build_name = self.build_lib + os.sep + name
try:
import multiprocessing as mp
nprocs = mp.cpu_count()
except ImportError:
nprocs = 1
# cleanup
if os.path.exists(self.build_temp): rmtree(self.build_temp)
os.makedirs(self.build_temp)
# remove *.so files
for file in Path(self.build_temp).glob('*.so'):
os.remove(file)
# copy makefiles to temporary build dir
makefiles = list(Path(topdir + '/install/').glob('*'))
makefiles += list(Path(topdir + '/src/').glob('**/*.f90'))
for makefile in makefiles:
copy2(makefile, self.build_temp)
# execute makefiles
check_call(
['make', '-f', 'Makefile'] + ['-j', str(nprocs)],
cwd=self.build_temp,
env=os.environ.copy(),
)
# make build dirs
for path in (self.build_lib, self.build_name):
if not os.path.exists(path): os.makedirs(path)
# copy files to build dir
files = Path(self.build_temp + os.sep + name + os.sep).glob('*')
for file in files:
copy2(file, self.build_name)
# copy libraries to lib dir
for files in Path(self.build_temp).glob('*.so'):
copy2(files, self.build_lib + os.sep)
extensions_pyec = Extension(
"pyec._pyec",
sources=[],
)
ext_modules = [
extensions_pyec,
]
if __name__ == "__main__":
setup(
name=name,
url='',
description=description,
version=__version__,
author=__author__,
author_email=__contact__,
license=__license__,
long_description=long_description,
python_requires='>=3.6',
install_requires=['numpy>=1.18.0', 'f90wrap>=0.2.3'],
extras_require={
'mpi': [
'mpi4py>=3.0.0',
],
},
packages=find_packages('./'),
ext_modules=ext_modules,
cmdclass={"build_ext": MakeBuild},
classifiers=[
'Development Status :: 1 - Beta',
'Intended Audience :: Science/Research',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering :: Chemistry',
'Topic :: Scientific/Engineering :: Physics'
],
)