Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/virtualenv/run/__init__.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 import logging | |
4 | |
5 from ..app_data import AppDataAction, AppDataDisabled, TempAppData | |
6 from ..config.cli.parser import VirtualEnvConfigParser | |
7 from ..report import LEVELS, setup_report | |
8 from ..run.session import Session | |
9 from ..seed.wheels.periodic_update import manual_upgrade | |
10 from ..version import __version__ | |
11 from .plugin.activators import ActivationSelector | |
12 from .plugin.creators import CreatorSelector | |
13 from .plugin.discovery import get_discover | |
14 from .plugin.seeders import SeederSelector | |
15 | |
16 | |
17 def cli_run(args, options=None, setup_logging=True): | |
18 """ | |
19 Create a virtual environment given some command line interface arguments. | |
20 | |
21 :param args: the command line arguments | |
22 :param options: passing in a ``VirtualEnvOptions`` object allows return of the parsed options | |
23 :param setup_logging: ``True`` if setup logging handlers, ``False`` to use handlers already registered | |
24 :return: the session object of the creation (its structure for now is experimental and might change on short notice) | |
25 """ | |
26 of_session = session_via_cli(args, options, setup_logging) | |
27 with of_session: | |
28 of_session.run() | |
29 return of_session | |
30 | |
31 | |
32 def session_via_cli(args, options=None, setup_logging=True): | |
33 """ | |
34 Create a virtualenv session (same as cli_run, but this does not perform the creation). Use this if you just want to | |
35 query what the virtual environment would look like, but not actually create it. | |
36 | |
37 :param args: the command line arguments | |
38 :param options: passing in a ``VirtualEnvOptions`` object allows return of the parsed options | |
39 :param setup_logging: ``True`` if setup logging handlers, ``False`` to use handlers already registered | |
40 :return: the session object of the creation (its structure for now is experimental and might change on short notice) | |
41 """ | |
42 parser, elements = build_parser(args, options, setup_logging) | |
43 options = parser.parse_args(args) | |
44 creator, seeder, activators = tuple(e.create(options) for e in elements) # create types | |
45 of_session = Session(options.verbosity, options.app_data, parser._interpreter, creator, seeder, activators) # noqa | |
46 return of_session | |
47 | |
48 | |
49 def build_parser(args=None, options=None, setup_logging=True): | |
50 parser = VirtualEnvConfigParser(options) | |
51 add_version_flag(parser) | |
52 parser.add_argument( | |
53 "--with-traceback", | |
54 dest="with_traceback", | |
55 action="store_true", | |
56 default=False, | |
57 help="on failure also display the stacktrace internals of virtualenv", | |
58 ) | |
59 _do_report_setup(parser, args, setup_logging) | |
60 options = load_app_data(args, parser, options) | |
61 handle_extra_commands(options) | |
62 | |
63 discover = get_discover(parser, args) | |
64 parser._interpreter = interpreter = discover.interpreter | |
65 if interpreter is None: | |
66 raise RuntimeError("failed to find interpreter for {}".format(discover)) | |
67 elements = [ | |
68 CreatorSelector(interpreter, parser), | |
69 SeederSelector(interpreter, parser), | |
70 ActivationSelector(interpreter, parser), | |
71 ] | |
72 options, _ = parser.parse_known_args(args) | |
73 for element in elements: | |
74 element.handle_selected_arg_parse(options) | |
75 parser.enable_help() | |
76 return parser, elements | |
77 | |
78 | |
79 def build_parser_only(args=None): | |
80 """Used to provide a parser for the doc generation""" | |
81 return build_parser(args)[0] | |
82 | |
83 | |
84 def handle_extra_commands(options): | |
85 if options.upgrade_embed_wheels: | |
86 result = manual_upgrade(options.app_data) | |
87 raise SystemExit(result) | |
88 | |
89 | |
90 def load_app_data(args, parser, options): | |
91 # here we need a write-able application data (e.g. the zipapp might need this for discovery cache) | |
92 default_app_data = AppDataAction.default() | |
93 parser.add_argument( | |
94 "--app-data", | |
95 dest="app_data", | |
96 action=AppDataAction, | |
97 default="<temp folder>" if isinstance(default_app_data, AppDataDisabled) else default_app_data, | |
98 help="a data folder used as cache by the virtualenv", | |
99 ) | |
100 parser.add_argument( | |
101 "--reset-app-data", | |
102 dest="reset_app_data", | |
103 action="store_true", | |
104 help="start with empty app data folder", | |
105 default=False, | |
106 ) | |
107 parser.add_argument( | |
108 "--upgrade-embed-wheels", | |
109 dest="upgrade_embed_wheels", | |
110 action="store_true", | |
111 help="trigger a manual update of the embedded wheels", | |
112 default=False, | |
113 ) | |
114 options, _ = parser.parse_known_args(args, namespace=options) | |
115 if options.app_data == "<temp folder>": | |
116 options.app_data = TempAppData() | |
117 if options.reset_app_data: | |
118 options.app_data.reset() | |
119 return options | |
120 | |
121 | |
122 def add_version_flag(parser): | |
123 import virtualenv | |
124 | |
125 parser.add_argument( | |
126 "--version", | |
127 action="version", | |
128 version="%(prog)s {} from {}".format(__version__, virtualenv.__file__), | |
129 help="display the version of the virtualenv package and its location, then exit", | |
130 ) | |
131 | |
132 | |
133 def _do_report_setup(parser, args, setup_logging): | |
134 level_map = ", ".join("{}={}".format(logging.getLevelName(l), c) for c, l in sorted(list(LEVELS.items()))) | |
135 msg = "verbosity = verbose - quiet, default {}, mapping => {}" | |
136 verbosity_group = parser.add_argument_group( | |
137 title="verbosity", description=msg.format(logging.getLevelName(LEVELS[3]), level_map), | |
138 ) | |
139 verbosity = verbosity_group.add_mutually_exclusive_group() | |
140 verbosity.add_argument("-v", "--verbose", action="count", dest="verbose", help="increase verbosity", default=2) | |
141 verbosity.add_argument("-q", "--quiet", action="count", dest="quiet", help="decrease verbosity", default=0) | |
142 option, _ = parser.parse_known_args(args) | |
143 if setup_logging: | |
144 setup_report(option.verbosity) | |
145 | |
146 | |
147 __all__ = ( | |
148 "cli_run", | |
149 "session_via_cli", | |
150 ) |