-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
141 lines (118 loc) · 4.12 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
# encoding: utf-8
#
# setup.py
#
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from setuptools import setup, find_packages
import os
import argparse
import sys
import re
# It's nice to have a VERSION file, but it costs every time we import.
with open("python/astra/__init__.py", "rt") as fp:
content = fp.read()
NAME = re.search(r"^NAME = ['\"]([^'\"]*)['\"]", content, re.M).group(1)
VERSION = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", content, re.M).group(1)
RELEASE = "dev" in VERSION
def run(packages, install_requires):
setup(
name=NAME,
version=VERSION,
license="BSD3",
description="Description of your project.",
long_description=open("README.rst").read(),
author="Andy Casey",
author_email="[email protected]",
keywords="astronomy software",
url="https://github.com/sdss/astra",
include_package_data=True,
packages=packages,
install_requires=install_requires,
package_dir={"": "python"},
package_data={
"astra.contrib.thepayne_new": [
"apogee_mask.npz",
"apogee_wavelength.npz",
"cannon_cont_pixels_apogee.npz",
"NN_normalized_spectra.npz",
],
},
scripts=[
"bin/astra",
"bin/ferre_chaos_monkey",
"bin/ferre_interpolate_unnormalized_model_flux"
],
# entry_points = {
# 'console_scripts': [
# 'apogeenet=astra.contrib.apogeenet.cli:main',
# 'classifier-train=astra.contrib.classifier.cli:train_model',
# ],
# },
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Topic :: Documentation :: Sphinx",
"Topic :: Software Development :: Libraries :: Python Modules",
],
)
def get_requirements(opts):
"""Get the proper requirements file based on the optional argument"""
if opts.dev:
name = "requirements_dev.txt"
elif opts.doc:
name = "requirements_doc.txt"
else:
name = "requirements.txt"
requirements_file = os.path.join(os.path.dirname(__file__), name)
install_requires = [
line.strip().replace("==", ">=")
for line in open(requirements_file)
if not line.strip().startswith("#") and line.strip() != ""
]
return install_requires
def remove_args(parser):
"""Remove custom arguments from the parser"""
arguments = []
for action in list(parser._get_optional_actions()):
if "--help" not in action.option_strings:
arguments += action.option_strings
for arg in arguments:
if arg in sys.argv:
sys.argv.remove(arg)
if __name__ == "__main__":
# Custom parser to decide whether which requirements to install
parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]))
parser.add_argument(
"-d",
"--dev",
dest="dev",
default=False,
action="store_true",
help="Install all packages for development",
)
parser.add_argument(
"-o",
"--doc",
dest="doc",
default=False,
action="store_true",
help="Install only core + documentation packages",
)
# We use parse_known_args because we want to leave the remaining args for distutils
args = parser.parse_known_args()[0]
# Get the proper requirements file
install_requires = get_requirements(args)
# Now we remove all our custom arguments to make sure they don't interfere with distutils
remove_args(parser)
# Have distutils find the packages
packages = find_packages(where="python")
# Runs distutils
run(packages, install_requires)