Commit 3ff5e0df authored by Owen Arnold's avatar Owen Arnold
Browse files

Script to install latest wfm stitching

If run inside mantidplot, this script will install the latest version of
wfm stitching. Might be possible to make this nicer yet, user still has
to know how to run this from within mantidplot. Also, do we want to have
this within the version control/package itself - I think that's a
circular argument since you need it to install the package in the first
place. Where should we put it instead (or in addition to?)
parent 4f51bf37
# -*- 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 MUST run this script inside MantidPlot from the script window,
or by invoking mantidplot with the -xq option. You need to do this after installing Mantid.
Example:
C:\\MantidInstall\\bin\\launch_mantidplot -x install_wfm_stitching.py
"""
import subprocess
import sys
import re
import os
from distutils.version import LooseVersion
def extract_wfm_version(python):
""" Extract and return the version of any installed wfm-stitching package currently installed.
If the package is not present throws RuntimeError
"""
out = subprocess.Popen([python, '-m' 'pip', 'show', 'wfm-stitching'], stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
package_details = out.communicate()[0]
if not package_details:
raise RuntimeError('No wfm-stitching pip package installed')
else:
# Take the version from the pip information of the package
actual_version = re.search('Version:\s+((\d+\.)(\d+\.)(\*|\d+))', package_details).group(1)
return LooseVersion(actual_version)
def extract_upload_url(python, required_version=None):
""" From gitlab project releases fetch the download url for the release matching the tag
"""
try:
import gitlab
except ImportError:
subprocess.check_call([python, '-m' 'pip', 'install', '--upgrade', '--user', 'python-gitlab'])
import gitlab
gl = gitlab.Gitlab('https://git.esss.dk')
project = gl.projects.list(search='wfm_stitching')[0]
if required_version:
tag = project.tags.get('v{0}'.format(required_version))
else:
# Get the latest tag
tag = project.tags.list(order_by='updated', sort='desc')[0]
description = tag.attributes['release']['description']
# Search for mark-down style upload in the form [link-text](upload-url) and extract upload-url
upload = re.search('\[.*\]\((.*)\)', description).group(1)
# Join with the project web url to obtain the full address
upload_url = project.attributes['web_url'] + upload
return upload_url
def do_wfm_stitching_install(python, required_version):
"""Perform the installation of the wfm-stitching pip (wheel) package.
Updgrades if already installed. Installation goes to user area."""
package_url = extract_upload_url(python, required_version)
# Try to install or upgrade the package
subprocess.check_call([python, '-m' 'pip', 'install', '--upgrade', '--user', package_url])
# Check that the installation or upgrade worked
actual_version = extract_wfm_version(python)
if required_version and (not actual_version == required_version):
print('Warning wrong version installed {0}'.format(actual_version))
print('Successfully installed wfm-stitching {0}'.format(str(actual_version)))
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__":
interpreter = os.path.join(os.path.dirname(sys.executable), 'python')
# Optionally provide a specific tag as required_version argument i.e: LooseVersion('0.1.1')
do_wfm_stitching_install(interpreter, required_version=None)
#do_wfm_stitching_uninstall(python)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment