|
1
|
|
|
import os |
|
2
|
|
|
import sys |
|
3
|
|
|
from subprocess import check_call, CalledProcessError |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
def activate_conda_env(conda, env_path): |
|
7
|
|
|
check_call([conda, 'create', '-p', env_path, '-y']) |
|
8
|
|
|
check_call([conda, 'activate', env_path]) |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
def install_dependencies(python, conda): |
|
12
|
|
|
check_call([python, '-m', 'pip', 'install', '--upgrade', 'pip']) |
|
13
|
|
|
check_call([python, '-m', 'pip', 'install', '--upgrade', 'wheel']) |
|
14
|
|
|
check_call([python, '-m', 'pip', 'install', '-r', 'requirements/base.txt']) |
|
15
|
|
|
check_call([python, '-m', 'pip', 'install', '-r', 'requirements/dev.txt']) |
|
16
|
|
|
check_call([conda, 'install', 'somoclu', '-y']) |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
def pip_install_lib(python, package_name='so_magic', pypi_index_url='https://test.pypi.org/simple/'): |
|
20
|
|
|
# use this command because test pypi absolutely not guarantees that it can satsify dependencies (--no-deps flag) by |
|
21
|
|
|
# looking for the packages in the index, simply because they might not exist |
|
22
|
|
|
check_call([python, '-m', 'pip', 'install', '--index-url', pypi_index_url, '--no-deps', package_name]) |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
def main(): |
|
26
|
|
|
# CONSTANTS |
|
27
|
|
|
MY_DIR = os.path.dirname(os.path.realpath(__file__)) |
|
28
|
|
|
tools = type('Executables', (object,), {'python': 'python', 'conda': os.environ.get('CONDA_EXE', 'conda')}) |
|
29
|
|
|
ENV_NAME = 'integration-env' |
|
30
|
|
|
ENV_PATH = os.path.join(MY_DIR, f'../{ENV_NAME}') |
|
31
|
|
|
try: |
|
32
|
|
|
check_call([tools.conda, '--help']) |
|
33
|
|
|
print('------------ CONDA IS ALREADY INSTALLED -------------') |
|
34
|
|
|
except CalledProcessError as ex: # this exception fires if the exit code of the above is not 0 |
|
35
|
|
|
print(ex) |
|
36
|
|
|
tools.conda = None |
|
37
|
|
|
|
|
38
|
|
|
if tools.conda is None: |
|
39
|
|
|
print("Will try to automatically install anaconda ..") |
|
40
|
|
|
print('------------ INSTALLING CONDA -------------') |
|
41
|
|
|
check_call(['chmod', '+x', './scripts/install_anaconda.sh']) |
|
42
|
|
|
try: |
|
43
|
|
|
check_call(['bash', 'scripts/install_anaconda.sh']) |
|
44
|
|
|
tools.conda = 'conda' |
|
45
|
|
|
except CalledProcessError as ex2: |
|
46
|
|
|
print("Failed to install anaconda, so cannot satisfy the somoclu feature of training a new map, which is " |
|
47
|
|
|
"required by one test case.\n Exitting with 1.") |
|
48
|
|
|
raise ex2 |
|
49
|
|
|
print('------------ CREATING ENV -------------') |
|
50
|
|
|
check_call([tools.conda, 'create', '-p', ENV_PATH, '-y']) |
|
51
|
|
|
print('------------ ACTIVATING ENV -------------') |
|
52
|
|
|
check_call([tools.conda, 'activate', ENV_PATH]) |
|
53
|
|
|
|
|
54
|
|
|
# activate_conda_env(tools.conda, ENV_PATH) |
|
55
|
|
|
# install_dependencies(tools.python, tools.conda) |
|
56
|
|
|
# pip_install_lib(tools.python) |
|
57
|
|
|
|
|
58
|
|
|
print("SUCCESS!!!") |
|
59
|
|
|
print("Successfully installed the library emnulating the real 'pip install' scenario using the test-pypi server.") |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
if __name__ == '__main__': |
|
63
|
|
|
try: |
|
64
|
|
|
main() |
|
65
|
|
|
print("OK.") |
|
66
|
|
|
except Exception as e: |
|
67
|
|
|
print(e) |
|
68
|
|
|
print("FAILED") |
|
69
|
|
|
sys.exit(1) |
|
70
|
|
|
|