install_wfm_stitching.py 2.22 KB
Newer Older
Owen Arnold's avatar
Owen Arnold committed
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
# -*- coding: utf-8 -*-
""" Script to correctly install wfm-stitching alongside Mantid.
Can either be used to install a specific wfm-stitching package version, or without modification,
will install the latest version.

You should run this script inside MantidPlot from the script window, to ensure that you are using
the same python interpreter that Mantid uses. The installation must use the same python interpreter
that mantid uses.

You can install from the command line using the lauch_mantid_plot executable with the xq
(execute and quit) option set, you can also pass a version to installation script, if not
provided it will fetch the latest wfm_stitching package.

Example:

C:\\MantidInstall\\bin\\launch_mantidplot -x install_wfm_stitching.py

or

C:\\MantidInstall\\bin\\launch_mantidplot -x install_wfm_stitching.py -v v0.1.0
"""
import subprocess
from argparse import ArgumentParser
import os
import sys

def do_wfm_stitching_install(python, required_version):
    url = 'git+http://git.esss.dk/wedel/wfm_stitching.git'
    if required_version:
        url = '{0}@{1}'.format(url, required_version)
    subprocess.check_call([python, '-m' 'pip', 'install', '--user', '--upgrade', url])

def do_wfm_stitching_uninstall(python):
    """Convenience function to allow the removal of the wfm-stitching package"""
    subprocess.check_call([python, '-m' 'pip', 'uninstall', '-y', 'wfm-stitching'])

if __name__ == "__main__":
    parser = ArgumentParser(description='Install WFM package http://git.esss.dk/wedel/wfm_sitching')
    parser.add_argument('-v', '--version', default=None,
                        help='optionally specify the version you wish to use i.e. v0.1.2.'
                             'Defaults to latest version. Version must match git tag version.')
    parser.add_argument('-u', '--uninstall', action='store_true', default=False,  help='uninstall any existing wfm-stitching package')
    args = parser.parse_args()
    interpreter = os.path.join(os.path.dirname(sys.executable), 'python')
    if args.uninstall:
        if args.version:
            print('Warning: version argument is ignored during uninstall')
        do_wfm_stitching_uninstall(interpreter)
    else:
        do_wfm_stitching_install(interpreter, required_version=args.version)