forked from AppliedMechanics/AMfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
116 lines (97 loc) · 4.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import sys
"""
Setup file for automatic installation of AMfe in development mode.
Run: 'python setup.py sdist' for Source Distribution
Run: 'python setup.py install' for Installation
Run: 'python setup.py bdist_wheel' for Building Binary-Wheel
(recommended for windows-distributions)
Attention: For every python-minor-version an extra wheel has to be built
Use environments and install different python versions by using
conda create -n python34 python=3.4 anaconda
Run: 'pip install wheelfile.whl' for Installing Binary-Wheel
Run: 'python setup_develop.py bdist --format=<format> für Binary-Distribution:
<format>=gztar|ztar|tar|zip|rpm|pgktool|sdux|wininst|msi
Recommended: tar|zip|wininst (evtl. msi)
Run: 'python setup_develop.py bdist --help-formats' to find out which distribution
formats are available
"""
# Uncomment next line for debugging
# DISTUTILS_DEBUG='DEBUG'
def query_yes_no(question, default="yes"):
"""
Ask a yes/no question and return their answer.
Parameters
----------
question: String
The question to be asked
default: String "yes" or "no"
The default answer
Returns
-------
answer: Boolean
Answer: True if yes, False if no.
"""
valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
if default is None:
prompt = " [y/n] "
elif default == "yes":
prompt = " [Y/n] "
elif default == "no":
prompt = " [y/N] "
else:
raise ValueError("invalid default answer: '%s'" % default)
while True:
sys.stdout.write(question + prompt)
choice = input().lower()
if default is not None and choice == '':
return valid[default]
elif choice in valid:
return valid[choice]
else:
sys.stdout.write("Please respond with 'yes' or 'no'.\n")
no_fortran_str = '''
###############################################################################
############### Compilation of Fortran sources is disabled! ##################
###############################################################################
'''
no_extension_str = '''
###############################################################################
############### Fortran-Extensions cannot be installed! ##################
############### Install Numpy before installing AMfe ##################
###############################################################################
'''
if __name__ == '__main__':
from setuptools.config import read_configuration
config_raw = read_configuration('./meta.cfg')
config = dict()
config.update(config_raw['metadata'])
config.update(config_raw['options'])
ext_modules = []
if 'no_fortran' in sys.argv:
sys.argv.remove('no_fortran')
from setuptools import setup
setup(**config)
else:
try:
from numpy.distutils.core import Extension, setup
ext_assembly = Extension(name='amfe.f90_assembly',
sources=['amfe/fortran/assembly.f90'],
language='f90',)
ext_element = Extension(name='amfe.f90_element',
sources=['amfe/fortran/element.pyf',
'amfe/fortran/element.f90'],
language='f90',)
ext_material = Extension(name='amfe.f90_material',
sources=['amfe/fortran/material.f90'],
language='f90',)
ext_modules = [ext_assembly, ext_element, ext_material]
config.update({'ext_modules': ext_modules})
setup(**config)
except ModuleNotFoundError:
# from distutils.core import setup
print(no_extension_str)
print('Fortran files cannot be installed. \
It is recommended to abort installation and \
first install numpy. Then retry \
installation of AMfe.')
raise ImportError('Numpy not found')