-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
84 lines (70 loc) · 2.8 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
from setuptools import setup
import distutils.cmd
import distutils.log
import os
from setuptools.command.install import install
# from pip.req import parse_requirements
from pip._internal.req import parse_requirements
import numpy as np
class InstallCommand(install):
"""A custom command to install requested package to run Survey Strategy Support Pipeline"""
description = 'Script to install requested package to run Survey Strategy Support Pipeline'
user_options = install.user_options + [
('package=', None, 'package to install')
]
def initialize_options(self):
"""Set default values for options."""
# Each user option must be listed here with their default value.
install.initialize_options(self)
self.package = ''
# self.available_packages = ''
# load available packages and versions
self.packs = np.loadtxt('pack_version.txt', dtype={'names': (
'packname', 'version'), 'formats': ('U15', 'U15')})
def finalize_options(self):
"""Post-process options."""
if self.package:
if self.package not in self.packs['packname'].tolist() and self.package != 'sn_pipe':
print('{} impossible to install'.format(self.package))
install.finalize_options(self)
def run(self):
# install dependencies first
if self.package == 'ztf_pipe':
cmd = 'pip install --user -r requirements.txt --no-deps'
os.system(cmd)
else:
if self.package != 'all':
# now install the requested package
# get the version for this package
idx = self.packs['packname'] == self.package
version = self.packs[idx]['version'].item()
cmd = 'pip install -v --user git+https://github.com/lsstdesc/{}.git@{}'.format(
self.package, version)
os.system(cmd)
else:
for pack in self.packs:
# get the version for this package
packname = pack['packname']
version = pack['version']
cmd = 'pip install --user git+https://github.com/lsstdesc/{}.git@{}'.format(
packname, version)
os.system(cmd)
install.run(self)
# get the version here
pkg_vars = {}
with open("version.py") as fp:
exec(fp.read(), pkg_vars)
setup(
name='sn_pipe',
version=pkg_vars['__version__'],
description='A framework to run the Survey Strategy Support pipeline for supernovae',
url='http://github.com/lsstdesc/sn_pipe',
author='Philippe Gris',
author_email='philippe.gris@clermont.in2p3.fr',
license='BSD',
python_requires='>=3.5',
zip_safe=False,
cmdclass={
'install': InstallCommand,
},
)