-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
84 lines (67 loc) · 2.83 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
# Utility function to read the README file.
# Used for the long_description. It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
from setuptools import setup, find_packages
from setuptools.command.install import install
import errno
import os
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
class CustomInstall(install):
"""Customized setuptools install command - creates configuration files."""
def run(self):
self.create_config_files()
install.run(self)
@staticmethod
def create_config_files():
# Creating default configuration files
import configparser as cp
import os
config = cp.RawConfigParser()
config.add_section('fitacf')
config.set('fitacf', 'w_max', '90.0')
config.set('fitacf', 'v_max', '30.0')
config.set('fitacf', 'fitacf_revision_minor', '0')
config.set('fitacf', 'fitacf_revision_major', '3')
config.set('fitacf', 'fluctuation_cutoff_coeff', '2')
config.set('fitacf', 'alpha_cutoff', '2.0')
config.set('fitacf', 'acf_snr_cutoff', '1.0')
config.set('fitacf', 'minimum_lags', '3')
config.add_section('core')
config.set('core', 'hdw_files_path', '/usr/local/hdw')
for loc in os.path.expanduser("~"), "/etc/backscatter":
file_path = os.path.join(loc, "backscatter.ini")
if not os.path.exists(os.path.dirname(file_path)):
try:
os.makedirs(loc)
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
if exc.errno == errno.EACCES:
err_msg = """Could not create installation folder
at {0}. Please manually create or reinstall as
root.""".format(loc)
print(err_msg)
else:
raise
try:
with open(file_path, 'w') as cfg:
config.write(cfg)
except OSError:
err_msg = """Could not install configuration file
at {0}. Please manually copy or reinstall as root.""".format(loc)
print(err_msg)
# Set up arguments for installation
setup_args = {
'name': "backscatter",
'version': "2016.08",
'description': "A Python package of analysis tools for SuperDARN data",
'url': "",
'author': "SuperDARN Canada",
'license': "GNU",
'packages': find_packages(exclude=['contrib', 'docs', 'tests']),
'setup_requires': ['configparser'],
'install_requires': ['numpy>=1.8'],
'cmdclass': {'install': CustomInstall},
}
setup(**setup_args)