__init__.py 3.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
import sys

from distutils import util
from distutils import sysconfig
from distutils import log
from distutils.version import LooseVersion, StrictVersion
import glob
import os
import subprocess
import re 
from distutils.errors import DistutilsError
Eric Coissac committed
12
import tempfile
13

14
from importlib.util import spec_from_file_location  # @UnresolvedImport
15 16 17 18 19 20
import zipimport

import argparse

import base64

21
from .checkpython import is_python_version
22 23 24 25 26 27 28 29 30 31 32
                        
                        
from obidistutils.serenity.rerun import  enforce_good_python
from obidistutils.serenity.rerun import rerun_with_anothe_python

from obidistutils.serenity.virtual import serenity_virtualenv
                        
from obidistutils.serenity.checksystem import is_mac_system, \
                                              is_windows_system
                        
from obidistutils.serenity.checkpackage import install_requirements
33
from obidistutils.serenity.checkpackage import check_requirements
34 35 36 37 38

from obidistutils.serenity.util import save_argv
                        
from obidistutils.serenity.snake import snake
                            
39
    
40
def serenity_snake(envname,package,version):
41 42 43 44 45 46
    old = log.set_threshold(log.INFO)

    log.info("Installing %s (%s) in serenity mode" % (package,version))

    enforce_good_python()

47
    virtualpython=serenity_virtualenv(envname,package,version)
48 49 50 51 52 53 54
    
    if virtualpython!=os.path.realpath(sys.executable):
        log.info("Restarting installation within the %s virtualenv" % (envname))
        rerun_with_anothe_python(virtualpython)
        
    log.info("%s will be installed with python : %s" % (package,virtualpython))
        
55 56 57
    if install_requirements():    
        log.info("Restarting installation with all dependencies ok")
        rerun_with_anothe_python(virtualpython)
58 59 60
    
    log.set_threshold(old)
    
61
def serenity_assert(version):
62
    check_requirements()
63 64


65 66 67
def is_serenity():
    from obidistutils.serenity.globals import local_serenity
    return local_serenity and local_serenity[0]
68 69

def serenity_mode(package,version):
Eric Coissac committed
70
    
71
    save_argv()
72

Eric Coissac committed
73 74
    
    from obidistutils.serenity.globals import saved_args
75
    from obidistutils.serenity.globals import local_serenity
Eric Coissac committed
76
    
Eric Coissac committed
77

78 79 80 81 82 83
    old = log.set_threshold(log.INFO)
    
    argparser = argparse.ArgumentParser(add_help=False)
    argparser.add_argument('--serenity',
                           dest='serenity', 
                           action='store_true',
84
                           default=True, 
85 86
                           help='Switch the installer in serenity mode. Everythings are installed in a virtualenv')

87 88 89 90 91 92
    argparser.add_argument('--no-serenity',
                           dest='serenity', 
                           action='store_false',
                           default=True, 
                           help='Switch the installer in the no serenity mode.')

93 94 95 96 97 98 99 100 101 102 103
    argparser.add_argument('--virtualenv',
                           dest='virtual', 
                           type=str,
                           action='store',
                           default="%s-%s" % (package,version), 
                           help='Specify the name of the virtualenv used by the serenity mode [default: %s-%s]' % (package,version))    
    
    args, unknown = argparser.parse_known_args()
    sys.argv = [sys.argv[0]] + unknown
    
    if args.serenity:
104
        local_serenity.append(True)
105 106
        serenity_snake(args.virtual,package,version)
    else:
107
        local_serenity.append(False)       
108 109 110
    
    log.set_threshold(old)
    
111 112 113 114 115 116 117
    return args.serenity
    
    
def getVersion(source,main,version):
    path  = os.path.join(source,main,'%s.py' % version)
    spec = spec_from_file_location('version',path)
    return spec.loader.load_module().version.strip()
118