-
Notifications
You must be signed in to change notification settings - Fork 29
/
setup.py
86 lines (69 loc) · 2.83 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
import os, subprocess
import setuptools
from setuptools.command.build_py import build_py
from setuptools.command.develop import develop
# ================ paths and files
version_file = os.path.join('srfpython', 'version.py')
fortran_src_path = os.path.join('srfpython', 'Herrmann', 'src')
fortran_bin_path = os.path.join('srfpython', 'Herrmann', 'bin')
packages = setuptools.find_packages()
# checks
assert os.path.isfile(version_file), "{} not found".format(version_file)
assert os.path.isdir(fortran_src_path), "{} not found".format(fortran_src_path)
# ================ get version number from version file
if not os.path.isfile(version_file):
raise IOError(version_file)
with open(version_file, "r") as fid:
for line in fid:
if line.strip('\n').strip().startswith('__version__'):
__version__ = line.strip('\n').split('=')[-1].split()[0].strip().strip('"').strip("'")
break
else:
raise Exception('could not detect __version__ affectation in {version_file}'.format(version_file=version_file))
# ================ load description
with open("README.md", "r") as fh:
long_description = fh.read()
# ============= Custom build_py
def make():
# run command "make all" in ./srfpython/Herrmann/src
if not os.path.isdir(fortran_bin_path):
os.makedirs(fortran_bin_path)
proc = subprocess.Popen(
['/usr/bin/make', 'all'],
shell=True, cwd=fortran_src_path)
proc.wait()
class CustomBuilder(build_py):
# needed if the package is built, i.e. files will be copied to a site-packages directory
def run(self):
# it is important to run the make file before building the python packages
# so that the shared library files (.so) will be copied to the site-packages directory
# they must appear in the MANIFEST.in file !
make()
build_py.run(self)
class CustomDevelop(develop):
# needed if the package is installed in editable mode
def run(self):
make()
develop.run(self)
setuptools.setup(
name='srfpython',
version=__version__,
packages=packages,
url='https://github.com/obsmax/srfpython',
license='',
author='Maximilien Lehujeur',
author_email='[email protected]',
description='compute/inverse surface waves dispersion curves, based on Hermmann codes CPS',
long_description=long_description,
install_requires=['numpy', 'scipy', 'matplotlib', 'future'],
python_requires=">=3.7,<3.12",
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: Linux"],
cmdclass={"build_py": CustomBuilder,
"develop": CustomDevelop},
scripts=['srfpython/bin/srfpython_tester.py',
'srfpython/bin/m96',
'srfpython/bin/s96',
'srfpython/bin/HerrMet',
'srfpython/bin/sker17'])