Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/virtualenv/run/plugin/activators.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
| author | guerler |
|---|---|
| date | Fri, 31 Jul 2020 00:32:28 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:d30785e31577 | 1:56ad4e20f292 |
|---|---|
| 1 from __future__ import absolute_import, unicode_literals | |
| 2 | |
| 3 from argparse import ArgumentTypeError | |
| 4 from collections import OrderedDict | |
| 5 | |
| 6 from .base import ComponentBuilder | |
| 7 | |
| 8 | |
| 9 class ActivationSelector(ComponentBuilder): | |
| 10 def __init__(self, interpreter, parser): | |
| 11 self.default = None | |
| 12 possible = OrderedDict( | |
| 13 (k, v) for k, v in self.options("virtualenv.activate").items() if v.supports(interpreter) | |
| 14 ) | |
| 15 super(ActivationSelector, self).__init__(interpreter, parser, "activators", possible) | |
| 16 self.parser.description = "options for activation scripts" | |
| 17 self.active = None | |
| 18 | |
| 19 def add_selector_arg_parse(self, name, choices): | |
| 20 self.default = ",".join(choices) | |
| 21 self.parser.add_argument( | |
| 22 "--{}".format(name), | |
| 23 default=self.default, | |
| 24 metavar="comma_sep_list", | |
| 25 required=False, | |
| 26 help="activators to generate - default is all supported", | |
| 27 type=self._extract_activators, | |
| 28 ) | |
| 29 | |
| 30 def _extract_activators(self, entered_str): | |
| 31 elements = [e.strip() for e in entered_str.split(",") if e.strip()] | |
| 32 missing = [e for e in elements if e not in self.possible] | |
| 33 if missing: | |
| 34 raise ArgumentTypeError("the following activators are not available {}".format(",".join(missing))) | |
| 35 return elements | |
| 36 | |
| 37 def handle_selected_arg_parse(self, options): | |
| 38 selected_activators = ( | |
| 39 self._extract_activators(self.default) if options.activators is self.default else options.activators | |
| 40 ) | |
| 41 self.active = {k: v for k, v in self.possible.items() if k in selected_activators} | |
| 42 self.parser.add_argument( | |
| 43 "--prompt", | |
| 44 dest="prompt", | |
| 45 metavar="prompt", | |
| 46 help="provides an alternative prompt prefix for this environment", | |
| 47 default=None, | |
| 48 ) | |
| 49 for activator in self.active.values(): | |
| 50 activator.add_parser_arguments(self.parser, self.interpreter) | |
| 51 | |
| 52 def create(self, options): | |
| 53 return [activator_class(options) for activator_class in self.active.values()] |
