forked from spacetelescope/jdaviz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·159 lines (118 loc) · 4.57 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# NOTE: The configuration for the package, including the name, version, and
# other information are set in the setup.cfg file.
import os
import sys
from setuptools import setup
from setuptools.command.develop import develop
# First provide helpful messages if contributors try and run legacy commands
# for tests or docs.
TEST_HELP = """
Note: running tests is no longer done using 'python setup.py test'. Instead
you will need to run:
tox -e test
If you don't already have tox installed, you can install it with:
pip install tox
If you only want to run part of the test suite, you can also use pytest
directly with::
pip install -e .[test]
pytest
For more information, see:
http://docs.astropy.org/en/latest/development/testguide.html#running-tests
"""
if 'test' in sys.argv:
print(TEST_HELP)
sys.exit(1)
DOCS_HELP = """
Note: building the documentation is no longer done using
'python setup.py build_docs'. Instead you will need to run:
tox -e build_docs
If you don't already have tox installed, you can install it with:
pip install tox
You can also build the documentation with Sphinx directly using::
pip install -e .[docs]
cd docs
make html
For more information, see:
http://docs.astropy.org/en/latest/install.html#builddocs
"""
if 'build_docs' in sys.argv or 'build_sphinx' in sys.argv:
print(DOCS_HELP)
sys.exit(1)
VERSION_TEMPLATE = """
# Note that we need to fall back to the hard-coded version if either
# setuptools_scm can't be imported or setuptools_scm can't determine the
# version, so we catch the generic 'Exception'.
try:
from setuptools_scm import get_version
version = get_version(root='..', relative_to=__file__)
except Exception:
version = '{version}'
""".lstrip()
# These are based on jupyter_core.paths
def jupyter_config_dir():
"""Get the Jupyter config directory for this platform and user.
Returns JUPYTER_CONFIG_DIR if defined, else ~/.jupyter
"""
env = os.environ
home_dir = get_home_dir()
if env.get('JUPYTER_NO_CONFIG'):
return _mkdtemp_once('jupyter-clean-cfg')
if env.get('JUPYTER_CONFIG_DIR'):
return env['JUPYTER_CONFIG_DIR']
return os.path.join(home_dir, '.jupyter')
def user_dir():
homedir = os.path.expanduser('~')
# Next line will make things work even when /home/ is a symlink to
# /usr/home as it is on FreeBSD, for example
homedir = os.path.realpath(homedir)
if sys.platform == 'darwin':
return os.path.join(homedir, 'Library', 'Jupyter')
elif os.name == 'nt':
appdata = os.environ.get('APPDATA', None)
if appdata:
return os.path.join(appdata, 'jupyter')
else:
return os.path.join(jupyter_config_dir(), 'data')
else:
# Linux, non-OS X Unix, AIX, etc.
xdg = env.get("XDG_DATA_HOME", None)
if not xdg:
xdg = os.path.join(home, '.local', 'share')
return os.path.join(xdg, 'jupyter')
class DevelopCmd(develop):
prefix_targets = [
("voila/templates", 'jdaviz-default')
]
def run(self):
target_dir = os.path.join(sys.prefix, 'share', 'jupyter')
if '--user' in sys.prefix: # TODO: is there a better way to find out?
target_dir = user_dir()
target_dir = os.path.join(target_dir)
for prefix_target, name in self.prefix_targets:
source = os.path.join('share', 'jupyter', prefix_target, name)
target = os.path.join(target_dir, prefix_target, name)
target_subdir = os.path.dirname(target)
if not os.path.exists(target_subdir):
os.makedirs(target_subdir)
rel_source = os.path.relpath(os.path.abspath(
source), os.path.abspath(target_subdir))
try:
os.remove(target)
except:
pass
print(rel_source, '->', target)
os.symlink(rel_source, target)
super(DevelopCmd, self).run()
# WARNING: all files generated during setup.py will not end up in the source
# distribution
data_files = []
# Add all the templates
for (dirpath, dirnames, filenames) in os.walk('share/jupyter/voila/templates/'):
if filenames:
data_files.append((dirpath, [os.path.join(dirpath, filename)
for filename in filenames]))
setup(data_files=data_files, cmdclass={'develop': DevelopCmd},
use_scm_version={'write_to': os.path.join('jdaviz', 'version.py'),
'write_to_template': VERSION_TEMPLATE})