-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
104 lines (75 loc) · 2.9 KB
/
setup.py
File metadata and controls
104 lines (75 loc) · 2.9 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
100
101
#!/usr/bin/env python
from distutils.core import setup
import glob
import os
import shutil
import sys
def _make_safe_backup(file_name, maxn=100):
"""
Given a file name with full path `file_name`, rename it to
`file_name`.bakN
where N is 0 or a positive integer such that so existing file in the same
directory is clobbered. Give up after `maxn` tries.
Return whether or not a safe backup was created.
"""
for i in range(maxn):
new_name = '%s.bak%d' % (file_name, i)
if(os.path.exists(new_name)):
continue
shutil.move(file_name, new_name)
return(True)
return(False)
if __name__ == "__main__":
SCRIPTS = glob.glob('bin/*.py')
# Copy ./etc to sys.prefix/etc/owl.
src = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'etc')
dst = os.path.join(sys.prefix, 'etc', 'owl')
if(os.path.exists(dst)):
# No need to create it: just copy everything in src to dst.
for file_name in os.listdir(src):
dst_file_name = os.path.join(dst, file_name)
if(os.path.exists(dst_file_name)):
# Move it out of the way.
ok = _make_safe_backup(dst_file_name)
if(not ok):
msg = 'Unable to safely create %s.bakN in %s. Giving up.' \
% (file_name, dst)
raise(RuntimeError(msg))
shutil.copy(os.path.join(src, file_name), dst)
else:
# Copy the whole directory tree.
shutil.copytree(src, dst)
from src import __version__
setup(name = 'owl',
description = "Governance according to good laws",
author = "Francesco Pierfederici",
author_email = "fpierfed@stsci.edu",
license = "BSD",
version=__version__,
scripts=SCRIPTS,
packages=['owl', 'owl.plugins', ],
package_dir={'owl': 'src'},
package_data={'owl': ['templates/*/*/*', ]},
)
# Understand where the scripts were installed. Python has a special treatment of
# Darwin/Mac OS X (see distutils/install.py:install.finalize_options())
bin_dir = os.path.join(sys.prefix, 'bin')
if(sys.platform == 'darwin'):
from sysconfig import get_config_var
bin_dir = get_config_var('BINDIR')
print("""
OWL %(version)s
The full OWL distribution was installed (by default) under
%(install_dir)s/
The OWL command-line tools are (by default) available under
%(bin_dir)s/
Configuration file(s) are (by default) available under
%(config_dir)s/
Please customize the default configuration by creating an owlrc.local file in
the same directory (if you haven't done that already). This installation did not
modify any pre-existing owlrc.local but archived any pre-existing owlrc file
before writing the new one.
""") % {'config_dir': dst,
'install_dir': sys.prefix,
'bin_dir': bin_dir,
'version': __version__}