-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for Python only install (#72)
* Add option for Python only install * Update changelog
- Loading branch information
1 parent
2d0a7c0
commit 34ca252
Showing
3 changed files
with
79 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,63 @@ | ||
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 | ||
|
||
|
||
def run_setup(build_c=True): | ||
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()] | ||
|
||
if build_c: | ||
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_extension = Extension( | ||
'euphonic._euphonic', | ||
extra_compile_args=compile_args, | ||
extra_link_args=link_args, | ||
include_dirs=include_dirs, | ||
sources=sources | ||
) | ||
ext_modules = [euphonic_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: | ||
ext_modules = None | ||
# 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() | ||
|
||
|
@@ -55,10 +68,13 @@ def run_setup(build_c=True): | |
'scripts/dos.py', | ||
'scripts/optimise_eta.py'] | ||
|
||
cmdclass = versioneer.get_cmdclass() | ||
cmdclass['install'] = InstallCommand | ||
|
||
setup( | ||
name='euphonic', | ||
version=versioneer.get_version(), | ||
cmdclass=versioneer.get_cmdclass(), | ||
cmdclass=cmdclass, | ||
author='Rebecca Fair', | ||
author_email='[email protected]', | ||
description=( | ||
|
@@ -79,17 +95,7 @@ def run_setup(build_c=True): | |
'matplotlib': ['matplotlib>=1.4.2'], | ||
'phonopy_reader': ['h5py>=2.9.0', 'PyYAML>=5.1.2'] | ||
}, | ||
scripts=scripts, | ||
ext_modules=ext_modules | ||
scripts=scripts | ||
) | ||
|
||
|
||
try: | ||
run_setup() | ||
except: | ||
print('*'*79) | ||
print(('Failed to build Euphonic C extension, installing pure ' | ||
'Python version instead')) | ||
print('*'*79) | ||
print("Unexpected error: {}".format(sys.exc_info()[0])) | ||
run_setup(build_c=False) | ||
run_setup() |