summaryrefslogtreecommitdiffstats
path: root/test/lib/ansible_test/_util/target/tools/virtualenvcheck.py
blob: a38ad0747ec02baed55fca08557a9921116e27a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Detect the real python interpreter when running in a virtual environment created by the 'virtualenv' module."""
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import json

try:
    # virtualenv <20
    from sys import real_prefix
except ImportError:
    real_prefix = None

try:
    # venv and virtualenv >= 20
    from sys import base_exec_prefix
except ImportError:
    base_exec_prefix = None

print(json.dumps(dict(
    real_prefix=real_prefix or base_exec_prefix,
)))