14
14
from .plugin .seeders import SeederSelector
15
15
16
16
17
- def cli_run (args , options = None ):
18
- """Create a virtual environment given some command line interface arguments
17
+ def cli_run (args , options = None , setup_logging = True ):
18
+ """
19
+ Create a virtual environment given some command line interface arguments.
19
20
20
21
:param args: the command line arguments
21
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
22
24
:return: the session object of the creation (its structure for now is experimental and might change on short notice)
23
25
"""
24
- session = session_via_cli (args , options )
25
- with session :
26
- session .run ()
27
- return session
26
+ of_session = session_via_cli (args , options , setup_logging )
27
+ with of_session :
28
+ of_session .run ()
29
+ return of_session
30
+
28
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.
29
36
30
- # noinspection PyProtectedMember
31
- def session_via_cli (args , options = None ):
32
- parser , elements = build_parser (args , options )
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 )
33
43
options = parser .parse_args (args )
34
44
creator , seeder , activators = tuple (e .create (options ) for e in elements ) # create types
35
- session = Session (options .verbosity , options .app_data , parser ._interpreter , creator , seeder , activators )
36
- return session
45
+ of_session = Session (options .verbosity , options .app_data , parser ._interpreter , creator , seeder , activators ) # noqa
46
+ return of_session
37
47
38
48
39
- # noinspection PyProtectedMember
40
- def build_parser (args = None , options = None ):
49
+ def build_parser (args = None , options = None , setup_logging = True ):
41
50
parser = VirtualEnvConfigParser (options )
42
51
add_version_flag (parser )
43
52
parser .add_argument (
@@ -47,7 +56,7 @@ def build_parser(args=None, options=None):
47
56
default = False ,
48
57
help = "on failure also display the stacktrace internals of virtualenv" ,
49
58
)
50
- _do_report_setup (parser , args )
59
+ _do_report_setup (parser , args , setup_logging )
51
60
options = load_app_data (args , parser , options )
52
61
handle_extra_commands (options )
53
62
@@ -121,7 +130,7 @@ def add_version_flag(parser):
121
130
)
122
131
123
132
124
- def _do_report_setup (parser , args ):
133
+ def _do_report_setup (parser , args , setup_logging ):
125
134
level_map = ", " .join ("{}={}" .format (logging .getLevelName (l ), c ) for c , l in sorted (list (LEVELS .items ())))
126
135
msg = "verbosity = verbose - quiet, default {}, mapping => {}"
127
136
verbosity_group = parser .add_argument_group (
@@ -131,4 +140,11 @@ def _do_report_setup(parser, args):
131
140
verbosity .add_argument ("-v" , "--verbose" , action = "count" , dest = "verbose" , help = "increase verbosity" , default = 2 )
132
141
verbosity .add_argument ("-q" , "--quiet" , action = "count" , dest = "quiet" , help = "decrease verbosity" , default = 0 )
133
142
option , _ = parser .parse_known_args (args )
134
- setup_report (option .verbosity )
143
+ if setup_logging :
144
+ setup_report (option .verbosity )
145
+
146
+
147
+ __all__ = (
148
+ "cli_run" ,
149
+ "session_via_cli" ,
150
+ )
0 commit comments