-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
164 lines (152 loc) · 6.03 KB
/
Copy pathsetup.py
File metadata and controls
164 lines (152 loc) · 6.03 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# -*- coding: utf-8 -*-
##############################################################################
# Copyright (c), Gianfranco Ulian and Giovanni Valdre'. #
# All rights reserved. #
# #
# This file is part of the Quantas code. #
# #
# For further information on the license, see the LICENSE file #
##############################################################################
import os
import sys
from setuptools import setup
from distutils.core import Extension
try:
from Cython.Build import cythonize
from Cython.Distutils import build_ext
except ImportError:
print('\nError: Cython package not found')
print('\nCython is required to prooceed with the installation of Quantas')
print("\nPlease, install Cython via 'pip install cython'")
print('before installing this package')
print('\nWill now exit')
sys.exit(1)
# ----------------------------------------------------------------
# Setup utilities
# ----------------------------------------------------------------
def convert_path(string):
""" Convert a string containing a path into a string containing a module."""
if sys.platform == 'win32':
new_string = string.replace('\\','.')
else:
new_string = string.replace('/','.')
return new_string
def get_quantas_package(root_dir, cwd):
""" Collect all the modules within the Quantas package. """
package = {}
modules = []
modules.append(root_dir)
paths = []
paths.append(os.path.join(cwd, root_dir))
for root, dirs, files in os.walk(root_dir):
for directory in dirs:
modules.append(os.path.join(root, directory).replace('\\','.'))
paths.append(os.path.join(cwd, root, directory))
modules.sort()
paths.sort()
for i in range(len(modules)):
package[modules[i]] = paths[i]
return package, modules, paths
def get_extension_modules(root_dir):
""" Collect all the cython extensions. """
extensions = []
# ------------------------------------------------------------
# Compiler flags for 'cythonized' modules
# ------------------------------------------------------------
if sys.platform == 'win32':
extra_compile_args = ['/openmp']
extra_link_args = []
elif sys.platform == 'linux':
extra_compile_args = ['-fopenmp']
extra_link_args = ['-fopenmp']
else:
extra_compile_args = []
extra_link_args = []
# ------------------------------------------------------------
# Start collection
# ------------------------------------------------------------
for root, dirs, files in os.walk(root_dir):
for filename in files:
if os.path.splitext(filename)[1] == '.pyx':
module = convert_path(
os.path.splitext(os.path.join(root, filename))[0]
)
path = [os.path.join(root, filename)]
extensions.append(
Extension(module, path,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args
)
)
return extensions
# ----------------------------------------------------------------
# Quantas description
# ----------------------------------------------------------------
with open("README.md", "r") as fh:
long_description = fh.read()
# ----------------------------------------------------------------
# Package requirements
# ----------------------------------------------------------------
requirements = [
'cython>=0.29',
'click>=7.0',
'numpy>=1.18',
'scipy>=1.4',
'pyyaml>=5.3',
'h5py>=2.10'
]
# ----------------------------------------------------------------
# Package modules and folders
# ----------------------------------------------------------------
cwd = os.path.join(os.path.dirname(__file__))
package, modules, paths = get_quantas_package('quantas', '.')
# ----------------------------------------------------------------
# Compiler flags for 'cythonized' modules
# ----------------------------------------------------------------
if sys.platform == 'win32':
extra_compile_args = ['/openmp']
extra_link_args = []
elif sys.platform == 'linux':
extra_compile_args = ['-fopenmp']
extra_link_args = ['-fopenmp']
else:
extra_compile_args = []
extra_link_args = []
# ----------------------------------------------------------------
# Setup
# ----------------------------------------------------------------
setup(name='quantas',
version='0.9.1',
description='QUANtistic Thermomechanical Analysis of Solids',
long_description=long_description,
classifiers=[
'Development Status :: 4 - Beta',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Operating System :: OS Independent',
'Environment :: Console',
'Topic :: Scientific/Engineering :: Chemistry',
'Topic :: Scientific/Engineering :: Physics',
'Intended Audience :: Science/Research'
],
url='https://github.com/gfulian/quantas',
author='Gianfranco Ulian',
author_email='gianfranco.ulian2@unibo.it',
license='BSD',
package_dir=package,
packages=modules,
entry_points={
'console_scripts': [
'quantas = quantas.cmdline.commands.cmd_quantas:cli'
]
},
ext_modules=cythonize(get_extension_modules('quantas')),
python_requires='>=3.5',
install_requires=requirements,
include_package_data=True,
zip_safe=False)