forked from pace-neutrons/Euphonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
101 lines (86 loc) · 3.11 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
import versioneer
try:
from setuptools import setup, find_packages, Extension
from setuptools.command.install import install
except ImportError:
from distutils.core import setup, find_packages, Extension
from distutils.command.install import install
class InstallCommand(install):
user_options = install.user_options + [('python-only', None, 'Install only Python')]
def initialize_options(self):
install.initialize_options(self)
self.python_only = 0
def finalize_options(self):
install.finalize_options(self)
if not bool(self.python_only):
self.distribution.ext_modules = [get_c_extension()]
def get_c_extension():
import os
import numpy as np
from sys import platform
import subprocess
include_dirs = [np.get_include(), 'c']
sources = ['c/_euphonic.c', 'c/dyn_mat.c', 'c/util.c', 'c/py_util.c',
'c/load_libs.c']
if platform == 'win32':
# Windows - assume MSVC compiler
compile_args = ['/openmp']
link_args = None
elif platform == 'darwin':
# OSX - assume brew install llvm
brew_prefix_cmd_return = subprocess.run(["brew", "--prefix"],
stdout=subprocess.PIPE)
brew_prefix = brew_prefix_cmd_return.stdout.decode("utf-8").strip()
os.environ['CC'] = '{}/opt/llvm/bin/clang'.format(brew_prefix)
compile_args = ['-fopenmp']
link_args = ['-L{}/opt/llvm/lib'.format(brew_prefix), '-fopenmp']
else:
# Linux - assume gcc
os.environ['CC'] = 'gcc'
compile_args = ['-fopenmp']
link_args = ['-fopenmp']
euphonic_c_extension = Extension(
'euphonic._euphonic',
extra_compile_args=compile_args,
extra_link_args=link_args,
include_dirs=include_dirs,
sources=sources
)
return euphonic_c_extension
def run_setup(build_c=True):
with open('README.rst', 'r') as f:
long_description = f.read()
packages = ['euphonic',
'euphonic.readers']
scripts = ['scripts/dispersion.py',
'scripts/dos.py',
'scripts/optimise_eta.py']
cmdclass = versioneer.get_cmdclass()
cmdclass['install'] = InstallCommand
setup(
name='euphonic',
version=versioneer.get_version(),
cmdclass=cmdclass,
author='Rebecca Fair',
author_email='[email protected]',
description=(
'Euphonic calculates phonon bandstructures and inelastic '
'neutron scattering intensities from modelling code output '
'(e.g. CASTEP)'),
long_description=long_description,
long_description_content_type='text/x-rst',
url='https://github.com/pace-neutrons/Euphonic',
packages=packages,
install_requires=[
'numpy>=1.9.1',
'scipy>=1.0.0',
'seekpath>=1.1.0',
'pint>=0.10.1'
],
extras_require={
'matplotlib': ['matplotlib>=1.4.2'],
'phonopy_reader': ['h5py>=2.9.0', 'PyYAML>=5.1.2']
},
scripts=scripts
)
run_setup()