| Total Complexity | 7 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Coverage | 87.5% |
| Changes | 0 | ||
| 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 |