-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
140 lines (123 loc) · 4.4 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: ESDC team
@contact: [email protected]
European Space Astronomy Centre (ESAC)
European Space Agency (ESA)
Created on 5 Aug. 2019
"""
import os
import shutil
from os.path import isfile, join
from setuptools import setup
from setuptools.command.develop import develop
from setuptools.command.install import install
import re
import ast
import sys
import fileinput
folder = "esa_p2sa"
packages = []
for dirname, dirnames, filenames in os.walk(folder):
if '__init__.py' in filenames:
packages.append(dirname.replace('/', '.'))
# Filter test packages
toFilter = []
for package in packages:
if 'test' in package:
toFilter.append(package)
for filter in toFilter:
packages.remove(filter)
############################
# Parse the profile argument
############################
profile = 'dev' # default value
for argument in sys.argv[1:]:
print(argument)
if argument.startswith('-P'):
profile = argument[2:]
sys.argv.remove(argument)
print('Profile:', profile)
def copyFolder(src, dest):
directory = os.path.dirname(dest)
if not os.path.exists(directory):
os.makedirs(directory)
src_files = os.listdir(src)
for file_name in src_files:
full_file_name = os.path.join(src, file_name)
if os.path.isfile(full_file_name):
print('Copying %s into %s ... ' % (full_file_name, dest))
shutil.copy(full_file_name, dest)
def loadReplaceDictionary():
propsfile = 'conf/%s.properties' % profile
print('Loading %s ... ' % propsfile)
return reading(propsfile)
def reading(propsfile):
props = {}
with open(propsfile, 'r') as f:
for line in f:
line = re.sub('\s+', '', line) # remove whitespace and '\n' chars
if "=" not in line:
continue # skips blanks and comments w/o =
if line.startswith("#"):
continue # skips comments which contain =
k, v = line.split("=", 1)
props[k] = v
return props
def replacePython(file):
print('Processing file:', file)
replaced = []
replaceDictionary = loadReplaceDictionary()
REGEX = re.compile(r'[=]\s*\S*$', re.IGNORECASE)
# Variable substitution in python code
for line in fileinput.input(file, inplace=True):
l = re.sub('\s+', '', line) # Remove all the spaces from the line
for key in replaceDictionary:
pattern = '%s=' % key
if l.startswith(pattern):
line = REGEX.sub('= "%s"' % replaceDictionary[key], line)
replaced.append(line.strip())
print(line, end='')
for line in replaced:
print('Replaced:', line)
def replaceNotebooks(file):
print('Processing file:', file)
replaceDictionary = loadReplaceDictionary()
for line in fileinput.input(file, inplace=True):
for key in replaceDictionary:
value = "'%s'" % replaceDictionary[key]
line = line.replace(key, value)
print(line, end='')
# https://stackoverflow.com/questions/20288711/post-install-script-with-python-setuptools
class PostInstallCommand(install):
"""Post-installation for installation mode."""
def run(self):
print("*********** POST INSTALL COMMAND ***************")
# Copy demos into the build folder
copyFolder('demo/', 'build/demo/')
# Variable substitution
# Python code
FILES2UPDATE = [ 'build/lib/esa_p2sa/__init__.py' ]
for file in FILES2UPDATE:
replacePython(file)
# Notebook demos
folder = './build/demo/'
FILES2UPDATE = [join(folder, filename) for filename in os.listdir(folder) if os.path.splitext(filename)[1] == '.ipynb' ]
for file in FILES2UPDATE:
replaceNotebooks(file)
print("*********** POST INSTALL COMMAND END ***********")
install.run(self)
setup(name='esa_p2sa',
version='1.1',
description='First version of p2sa_core to access the data stored in PROBA2 archive',
url='https://repos.cosmos.esa.int/socci/scm/esdc_ptwosa/p2sa-python.git',
author='ESDC',
author_email='[email protected]',
license='ESDC',
packages=packages,
zip_safe=False,
install_requires=['astroquery', 'astropy', 'pytest', 'IPython', 'requests', 'six', 'python-dateutil'],
cmdclass={
'install': PostInstallCommand,
})