Setup Python virtual environments for all the registered or the provided pack.
(recreate_virtualenvs=False)
| 107 | |
| 108 | |
| 109 | def setup_virtualenvs(recreate_virtualenvs=False): |
| 110 | """ |
| 111 | Setup Python virtual environments for all the registered or the provided pack. |
| 112 | """ |
| 113 | |
| 114 | LOG.info("=========================================================") |
| 115 | LOG.info("########### Setting up virtual environments #############") |
| 116 | LOG.info("=========================================================") |
| 117 | pack_dir = cfg.CONF.register.pack |
| 118 | fail_on_failure = not cfg.CONF.register.no_fail_on_failure |
| 119 | |
| 120 | registrar = ResourceRegistrar() |
| 121 | |
| 122 | if pack_dir: |
| 123 | pack_name = os.path.basename(pack_dir) |
| 124 | pack_names = [pack_name] |
| 125 | |
| 126 | # 1. Register pack |
| 127 | registrar.register_pack(pack_name=pack_name, pack_dir=pack_dir) |
| 128 | else: |
| 129 | # 1. Register pack |
| 130 | base_dirs = content_utils.get_packs_base_paths() |
| 131 | registrar.register_packs(base_dirs=base_dirs) |
| 132 | |
| 133 | # 2. Retrieve available packs (aka packs which have been registered) |
| 134 | pack_names = registrar.get_registered_packs() |
| 135 | |
| 136 | if recreate_virtualenvs: |
| 137 | """ |
| 138 | update = False: |
| 139 | this is more than an update of an existing virtualenv |
| 140 | the virtualenv itself will be removed & recreated |
| 141 | this is i.e. useful for updates to a newer Python release |
| 142 | """ |
| 143 | update = False |
| 144 | else: |
| 145 | """ |
| 146 | update = True: |
| 147 | only dependencies inside the virtualenv will be updated |
| 148 | """ |
| 149 | update = True |
| 150 | |
| 151 | setup_count = 0 |
| 152 | for pack_name in pack_names: |
| 153 | try: |
| 154 | setup_pack_virtualenv(pack_name=pack_name, update=update, logger=LOG) |
| 155 | except Exception as e: |
| 156 | exc_info = not fail_on_failure |
| 157 | LOG.warning( |
| 158 | 'Failed to setup virtualenv for pack "%s": %s', |
| 159 | pack_name, |
| 160 | e, |
| 161 | exc_info=exc_info, |
| 162 | ) |
| 163 | |
| 164 | if fail_on_failure: |
| 165 | raise e |
| 166 | else: |
no test coverage detected