Passed
Push — master ( 0fd795...73442f )
by Emmanuel
14:19
created

package_utils   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 34
ccs 14
cts 16
cp 0.875
rs 10
c 0
b 0
f 0
wmc 7

3 Functions

Rating   Name   Duplication   Size   Complexity  
A get_venv_basedir() 0 9 4
A get_dir() 0 8 2
A get_file() 0 4 1
1
"""Gives useful information about the current virtualenv, files locations if
2
stakkr is installed as a package or directly cloned"""
3
4 1
import os
5 1
import sys
6 1
from distutils.sysconfig import get_config_vars, get_python_lib
7
8
9 1
def get_venv_basedir():
10
    """Returns the base directory of the virtualenv, useful to read configuration and plugins"""
11
12 1
    exec_prefix = get_config_vars()['exec_prefix']
13 1
    has_real_prefix = hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)
14 1
    if has_real_prefix is False or (hasattr(sys, 'real_prefix') and exec_prefix.startswith(sys.real_prefix)):
15
        raise EnvironmentError('You must be in a virtual environment')
16
17 1
    return os.path.abspath(get_config_vars()['exec_prefix'] + '/../')
18
19
20 1
def get_dir(dirname: str):
21
    """Detects if stakkr is a package or a clone and gives the right path for a directory"""
22
23 1
    staticdir = os.path.dirname(os.path.realpath(__file__)) + '/' + dirname
24 1
    if os.path.isdir(staticdir) is True:
25 1
        return staticdir
26
27
    return get_python_lib() + '/stakkr/' + dirname
28
29
30 1
def get_file(dirname: str, filename: str):
31
    """Detects if stakkr is a package or a clone and gives the right path for a file"""
32
33
    return get_dir(dirname) + '/' + filename.lstrip('/')
34