-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
99 lines (85 loc) · 3.13 KB
/
Copy pathsetup.py
File metadata and controls
99 lines (85 loc) · 3.13 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
import os
import sys
import fileinput
import platform
import subprocess
from setuptools.command.install import install
from setuptools import setup, find_packages
from platform import system as current_platform
import shutil
from glob import glob
def get_bin_path():
# Get environment bin/ directory
bindir = None
# check if the --user option was set
userdir = None
for u in install.user_options:
if u[0]=='user':
# "install in user site-package '/Users/nidever/.local/lib/python3.7/site-packages'"
uline = u[2]
userdir = uline[uline.find('site-package')+13:]
userdir = userdir.replace("'","")
if userdir is not None:
# /Users/nidever/.local/bin
bindir = os.path.dirname(os.path.dirname(os.path.dirname(userdir)))+'/bin'
if os.path.exists(bindir)==False:
bindir = False
# Try virtual environment using sys.prefix
if bindir is None:
venv = get_virtualenv_path()
if venv is not None:
bindir = venv+'/bin'
if os.path.exists(bindir)==False:
bindir = None
# Get bin/ directory from python executable
if bindir is None:
out = subprocess.run(['which','python'],shell=True)
if type(out) is bytes:
out = out.decode()
bindir = os.path.dirname(out)
if os.path.exists(bindir)==False:
bindir = None
if bindir is None:
raise Exception('No bin/ directory found')
return bindir
def compilesynspec():
""" Compile the Synspec Fortran code."""
src_path = './src/'
# Identify the platform
platform = current_platform()
# Check for platform first
#if platform not in ('Darwin', 'Linux'):
# sys.stderr.write("Platform '%s' not recognised!\n" % platform)
# sys.exit()
# Install the software
print('Compiling the Fortran code')
ret = subprocess.run(['make'], cwd=src_path, shell=True)
# Get the path for the binaries
bindir = get_bin_path()
# Copy fortran binaries to bin/ directory
for f in ['synspec54','rotin','list2bin']:
if os.path.exists('bin/'+f):
if os.path.exists(bindir+f): os.remove(bindir+f)
print('Copying bin/'+f+' -> '+bindir+'/'+f)
shutil.copyfile('bin/'+f,bindir+'/'+f)
# Make executable
os.chmod(bindir+'/'+f,0o755)
else:
print('bin/'+f+' NOT FOUND')
# Download the linelists and convert to binary
print('Downloading linelists')
ret = subprocess.run(['make'], cwd='./python/synspec/linelists/', shell=True)
# We need to build Synspec
if 'install' in sys.argv or 'develop' in sys.argv or 'bdist_wheel' in sys.argv:
compilesynspec()
setup(name='synspec',
version='1.0.3',
description='Synspec spectral synthesis code and python wrapper',
author='David Nidever',
author_email='dnidever@montana.edu',
url='https://github.com/dnidever/synspec',
requires=['numpy','astropy(>=4.0)','scipy','matplotlib','dlnpyutils'],
include_package_data=True,
packages = ['synspec'],
package_dir={"": "python"}
)