-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
103 lines (92 loc) · 3.44 KB
/
setup.py
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
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext
import subprocess
import sys
import os
import platform
# Check if PyBind11 is installed
try:
import pybind11
except ImportError:
print("PyBind11 is not installed. Installing...")
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pybind11'])
import pybind11
class CustomBuildExtCommand(build_ext):
"""Custom build command."""
def check_and_install_package_linux(self, package):
try:
subprocess.check_call(['dpkg', '-l', package])
except subprocess.CalledProcessError:
print(f"{package} not found. Installing via apt-get...")
subprocess.check_call(['sudo', 'apt-get', 'install', '-y', package])
def check_and_install_package_macos(self, package):
try:
subprocess.check_call(['brew', 'list', package])
except subprocess.CalledProcessError:
print(f"{package} not found. Installing via Homebrew...")
subprocess.check_call(['brew', 'install', package])
def run(self):
if platform.system() == 'Linux':
self.check_and_install_package_linux('liblapack-dev')
self.check_and_install_package_linux('libblas-dev')
elif platform.system() == 'Darwin':
self.check_and_install_package_macos('lapack')
# Compile wannier90-3.1.0
print("Compiling wannier90-3.1.0")
original_dir = os.getcwd()
try:
os.chdir('./wannier90-3.1.0')
subprocess.check_call(['make', 'all'])
subprocess.check_call(['make', 'lib'])
except subprocess.CalledProcessError as e:
print(f"Error occurred while compiling wannier90-3.1.0: {e}")
sys.exit(1)
finally:
os.chdir(original_dir)
build_ext.run(self)
# Extension definition
ext_modules = [
Extension(
'libwannier90',
sources=['src/libwannier90.cpp'],
include_dirs=['wannier90-3.1.0', pybind11.get_include()],
library_dirs=['wannier90-3.1.0'],
libraries=['lapack', 'blas', 'wannier'],
extra_compile_args=['-O3', '-Wall', '-shared', '-std=c++11', '-fPIC', '-D_UF'],
extra_link_args=['-Wl,-rpath,wannier90-3.1.0'],
language='c++'
)
]
if platform.system() == 'Linux':
ext_modules[0].include_dirs.append('/usr/include')
ext_modules[0].library_dirs.append('/usr/lib/x86_64-linux-gnu')
elif platform.system() == 'Darwin':
ext_modules[0].include_dirs.append('/opt/homebrew/opt/lapack/include')
ext_modules[0].library_dirs.append('/opt/homebrew/opt/lapack/lib')
# Setup configuration
setup(
name='libwannier90',
version='0.2.1',
author='Hung Q. Pham',
author_email='pqh3.14@gmail.com',
url='https://github.com/hungpham2017/libwannier90',
description='Wannier90 library for python wrapper pyWannier90',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
license='GPLv2',
packages=find_packages(),
install_requires=[
'pybind11>=2.6.0'
],
ext_modules=ext_modules,
classifiers=[
'Programming Language :: Python :: 3',
'Programming Language :: C++',
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
'Operating System :: OS Independent',
],
cmdclass={
'build_ext': CustomBuildExtCommand,
},
python_requires='>=3.0',
)