-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.py
executable file
·155 lines (119 loc) · 4.14 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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
MCMTpy is Created on Sun Apr 18 17:24:43 2021
@author: Fu Yin ([email protected]) at USTC
This script:
Nowadays, it’s usually do the research based on a python’s workflow, with
the help of packages such as obspy, numpy, pyasdf and mpi4py. MCMTpy is
Python Package for Simultaneous Inversion of Source Location, Focal
Mechanism, and Rupture Directivity.
Modify history:
1) Apr 18 17:24:43 2021 || Fu Yin at USTC || The initial release.
2) ...
"""
import os
import time
from setuptools import find_packages, setup
############################################
project_root = os.path.dirname(os.path.realpath(__file__)) # Gets the absolute path to the currently executing script
DOCSTRING = __doc__.strip().split("\n") # The above comment document
def make_info_module(project_root,version):
'''Put version and revision information into file MCMTpy/info.py.'''
datestr = time.strftime('%Y-%m-%d_%H:%M:%S')
s = '''# This module is automatically created from setup.py
project_root = %s
version = %s
installed_date = %s
''' % tuple([repr(x) for x in (
project_root, version, datestr)])
try:
f = open(os.path.join('MCMTpy', 'info.py'), 'w')
f.write(s)
f.close()
except Exception:
pass
def readme(project_root):
"""
read 'README.rst'
"""
README_file = os.path.join(project_root, 'README.rst')
with open(README_file) as f:
return f.read()
def get_requires(project_root):
"""
read requirements.txt
"""
requirements_file = os.path.join(project_root, 'requirements.txt')
with open(requirements_file) as f:
install_reqs = f.read().splitlines()
return install_reqs
def get_version(project_root):
"""
get __version__.py version number
"""
version_file = os.path.join(project_root,'MCMTpy', '__version__.py')
with open(version_file,'r') as f:
for line in f:
if line.startswith('__version__'):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
else:
raise RuntimeError("Unable to find version string.")
def get_package_data(project_root):
"""
Read package_data info
Returns a list of all files needed for the installation relative to the
'MCMTpy' subfolder.
"""
filenames = []
# Recursively include all files in these folders:
folders = [
os.path.join(project_root, "data"),
]
for folder in folders:
for directory, _, files in os.walk(folder):
for filename in files:
# Exclude hidden files.
if filename.startswith("."):
continue
filenames.append(
os.path.relpath(os.path.join(
directory, filename), project_root)
)
return filenames
setup_config = dict(
name="MCMTpy",
version=get_version(project_root),
description=DOCSTRING[0],
long_description=readme(project_root),
author="Fu Yin",
author_email="[email protected]",
url="https://www.google.com.hk/", # change later
license="MIT",
packages=find_packages(),
package_data={"MCMTpy": get_package_data(project_root)},
entry_points={
'console_scripts':
['MCMTpy = MCMTpy.apps.MCMTpy:main']
},
classifiers=[
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS",
"Programming Language :: Python :: 3.8",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Physics",
],
install_requires=get_requires(project_root),
)
############################################
if __name__ == "__main__":
version=get_version(project_root)
make_info_module(project_root,version)
setup(
**setup_config
)