forked from sami2py/sami2py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
67 lines (53 loc) · 2.1 KB
/
setup.py
File metadata and controls
67 lines (53 loc) · 2.1 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2017, JK
# Full license can be found in License.md
# -----------------------------------------------------------------------------
"""Setup routine for sami2py.
Notes
-----
Package metadata stored in setup.cfg
"""
import os
from setuptools import setup
import subprocess
import sys
# get home directory
home_dir = os.path.expanduser('~')
# get name of virtual environment
env_name = os.path.split(sys.prefix)[-1]
# generate path for fortran model files
here = os.path.abspath(os.path.dirname(__file__))
fortran_path = os.path.join(here, 'sami2py', 'fortran')
# generate path for test files
test_data_path = os.path.join(here, 'sami2py', 'tests', 'test_data')
# generate path to store test and fortran file paths
file_path = os.path.join(home_dir, '.sami2py', env_name)
# generate path to ExB coefficients
exb_path = os.path.join(fortran_path, 'exb.inp')
# %% build
if not os.path.isfile(os.path.join(fortran_path, 'sami2py.x')):
try: # py27 does not have shutil.which()
cmd = ['gfortran', '-fno-range-check', '-fno-automatic',
'-ffixed-line-length-none', '-o', 'sami2py.x']
src = ['nrlmsise00_modified.f', 'grid-1.00.f', 'sami2py-1.00.f',
'hwm93.f', 'hwm07e_modified.f90', 'apexcord.f90', 'hwm14.f90']
subprocess.call(cmd + src, cwd=fortran_path)
except OSError:
pass
if not os.path.isfile(os.path.join(fortran_path, 'sami2py.x')):
print('\nYou will need to compile the fortran files. Try\n'
'$ make -C {} compile\n'.format(os.path.join('sami2py', 'fortran')),
file=sys.stderr)
if not os.path.isdir(file_path):
os.makedirs(file_path)
print('Created {} directory to store settings.'.format(file_path))
if not os.path.isfile(exb_path):
zero_list = ["0 0"] * 10
with open(exb_path, 'w') as exb:
exb.writelines("%s\n" % line for line in zero_list)
with open(os.path.join(file_path, 'fortran_path.txt'), 'w+') as fout:
fout.write(fortran_path)
with open(os.path.join(file_path, 'test_data_path.txt'), 'w+') as fout:
fout.write(test_data_path)
setup()