File: getcython.py

package info (click to toggle)
obitools 1.2.13%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,652 kB
  • sloc: python: 18,199; ansic: 1,542; makefile: 98
file content (72 lines) | stat: -rw-r--r-- 2,208 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'''
Created on 2 oct. 2014

@author: coissac
'''

import imp
import importlib

from distutils.errors import DistutilsError
from distutils.version import StrictVersion  
from distutils import log       

from obidistutils.serenity.globals import local_cython  # @UnusedImport

from obidistutils.serenity.checkpip import get_a_pip_module

from obidistutils.serenity.checkpackage import get_package_requirement
from obidistutils.serenity.checkpackage import parse_package_requirement
from obidistutils.serenity.checkpackage import is_installed
from obidistutils.serenity.checkpackage import pip_install_package

from obidistutils.serenity.util import get_serenity_dir


def get_a_cython_module(pip=None):
    
    global local_cython

    if not local_cython:
        if pip is None:
            pip = get_a_pip_module()
         
        
        cython_req = get_package_requirement('Cython',pip)
        if cython_req is None:
            cython_req='Cython'
        
        requirement_project,requirement_relation,minversion = parse_package_requirement(cython_req)  # @UnusedVariable
        
        
        
        if cython_req is None or not is_installed(cython_req, pip):
            tmpdir = get_serenity_dir()
            
            ok = pip_install_package(cython_req,directory=tmpdir,pip=pip)
            
            log.debug('temp install dir : %s' % tmpdir)
                
            if ok!=0:
                raise DistutilsError("I cannot install a cython package")
    
            f, filename, description = imp.find_module('Cython', [tmpdir])
            
            cythonmodule = imp.load_module('Cython', f, filename, description)
            
            if minversion is not None:
                assert StrictVersion(cythonmodule.__version__) >= minversion, \
                       "Unable to find suitable version of cython get %s instead of %s" % (cythonmodule.__version__,
                                                                                        minversion)
    
        else:
            cythonmodule = importlib.import_module('Cython') 
            
        local_cython.append(cythonmodule)
           
    return local_cython[0]