Setup virtual environment for the provided pack. :param pack_name: Name of the pack to setup the virtualenv for. :type pack_name: ``str`` :param update: True to update dependencies inside the virtual environment. :type update: ``bool`` :param logger: Optional logger insta
(
pack_name,
update=False,
logger=None,
include_pip=True,
include_setuptools=True,
include_wheel=True,
proxy_config=None,
no_download=True,
force_owner_group=True,
inject_parent_virtualenv_sites=True,
)
| 51 | |
| 52 | |
| 53 | def setup_pack_virtualenv( |
| 54 | pack_name, |
| 55 | update=False, |
| 56 | logger=None, |
| 57 | include_pip=True, |
| 58 | include_setuptools=True, |
| 59 | include_wheel=True, |
| 60 | proxy_config=None, |
| 61 | no_download=True, |
| 62 | force_owner_group=True, |
| 63 | inject_parent_virtualenv_sites=True, |
| 64 | ): |
| 65 | |
| 66 | """ |
| 67 | Setup virtual environment for the provided pack. |
| 68 | |
| 69 | :param pack_name: Name of the pack to setup the virtualenv for. |
| 70 | :type pack_name: ``str`` |
| 71 | |
| 72 | :param update: True to update dependencies inside the virtual environment. |
| 73 | :type update: ``bool`` |
| 74 | |
| 75 | :param logger: Optional logger instance to use. If not provided it defaults to the module |
| 76 | level logger. |
| 77 | |
| 78 | :param no_download: Do not download and install latest version of pre-installed packages such |
| 79 | as pip and setuptools. |
| 80 | :type no_download: ``bool`` |
| 81 | """ |
| 82 | logger = logger or LOG |
| 83 | |
| 84 | if not re.match(PACK_REF_WHITELIST_REGEX, pack_name): |
| 85 | raise ValueError('Invalid pack name "%s"' % (pack_name)) |
| 86 | |
| 87 | if pack_name in RESERVED_PACK_LIST: |
| 88 | raise ValueError( |
| 89 | f"Pack name {pack_name} is a reserved name, and cannot be used" |
| 90 | ) |
| 91 | |
| 92 | base_virtualenvs_path = os.path.join(cfg.CONF.system.base_path, "virtualenvs/") |
| 93 | virtualenv_path = os.path.join(base_virtualenvs_path, quote_unix(pack_name)) |
| 94 | |
| 95 | # Ensure pack directory exists in one of the search paths |
| 96 | pack_path = get_pack_directory(pack_name=pack_name) |
| 97 | |
| 98 | logger.debug('Setting up virtualenv for pack "%s" (%s)' % (pack_name, pack_path)) |
| 99 | |
| 100 | if not pack_path: |
| 101 | packs_base_paths = get_packs_base_paths() |
| 102 | search_paths = ", ".join(packs_base_paths) |
| 103 | msg = 'Pack "%s" is not installed. Looked in: %s' % (pack_name, search_paths) |
| 104 | raise Exception(msg) |
| 105 | |
| 106 | # 1. Create virtualenv if it doesn't exist |
| 107 | if not update or not os.path.exists(virtualenv_path): |
| 108 | # 0. Delete virtual environment if it exists |
| 109 | remove_virtualenv(virtualenv_path=virtualenv_path, logger=logger) |
| 110 |