Passed
Push — master ( 9c9974...8720e9 )
by Konstantinos
53:08 queued 51:03
created

integration_test   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 50
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 7

4 Functions

Rating   Name   Duplication   Size   Complexity  
A install_dependencies() 0 6 1
A pip_install_lib() 0 4 1
A activate_conda_env() 0 3 1
A main() 0 35 4
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