1
1
from __future__ import annotations
2
2
3
3
from pathlib import Path
4
+ from typing import cast
4
5
5
- from tox .config .cli .parser import DEFAULT_VERBOSITY , ToxParser
6
+ from packaging .requirements import InvalidRequirement , Requirement
7
+
8
+ from tox .config .cli .parser import DEFAULT_VERBOSITY , Parsed , ToxParser
9
+ from tox .config .loader .memory import MemoryLoader
10
+ from tox .config .set_env import SetEnv
6
11
from tox .plugin import impl
7
12
from tox .session .cmd .run .common import env_run_create_flags
8
13
from tox .session .cmd .run .parallel import OFF_VALUE , parallel_flags , run_parallel
9
14
from tox .session .cmd .run .sequential import run_sequential
10
15
from tox .session .state import State
16
+ from tox .tox_env .python .pip .req_file import PythonDeps
11
17
12
- from ..env_select import CliEnv , register_env_select_flags
18
+ from ..env_select import CliEnv , EnvSelector , register_env_select_flags
13
19
from .devenv import devenv
14
20
from .list_env import list_env
15
21
from .show_config import show_config
@@ -54,16 +60,8 @@ def tox_add_option(parser: ToxParser) -> None:
54
60
our .add_argument (
55
61
"--pre" ,
56
62
action = "store_true" ,
57
- help = "install pre-releases and development versions of dependencies. This will pass the --pre option to"
58
- "install_command (pip by default)." ,
59
- )
60
- our .add_argument (
61
- "-i" ,
62
- "--index-url" ,
63
- action = "append" ,
64
- default = [],
65
- metavar = "url" ,
66
- help = "set indexserver url (if URL is of form name=url set the url for the 'name' indexserver, specifically)" ,
63
+ help = "deprecated use PIP_PRE in set_env instead - install pre-releases and development versions of"
64
+ "dependencies; this will set PIP_PRE=1 environment variable" ,
67
65
)
68
66
our .add_argument (
69
67
"--force-dep" ,
@@ -72,17 +70,18 @@ def tox_add_option(parser: ToxParser) -> None:
72
70
default = [],
73
71
help = "Forces a certain version of one of the dependencies when configuring the virtual environment. REQ "
74
72
"Examples 'pytest<6.1' or 'django>=2.2'." ,
73
+ type = Requirement ,
75
74
)
76
75
our .add_argument (
77
76
"--sitepackages" ,
78
77
action = "store_true" ,
79
- help = "override sitepackages setting to True in all envs" ,
78
+ help = "deprecated use VIRTUALENV_SYSTEM_SITE_PACKAGES=1, override sitepackages setting to True in all envs" ,
80
79
dest = "site_packages" ,
81
80
)
82
81
our .add_argument (
83
82
"--alwayscopy" ,
84
83
action = "store_true" ,
85
- help = "override always copy setting to True in all envs" ,
84
+ help = "deprecated use VIRTUALENV_ALWAYS_COPY=1, override always copy setting to True in all envs" ,
86
85
dest = "always_copy" ,
87
86
)
88
87
@@ -92,16 +91,53 @@ def legacy(state: State) -> int:
92
91
if option .show_config :
93
92
option .list_keys_only = []
94
93
option .show_core = not bool (option .env )
95
- return show_config (state )
96
94
if option .list_envs or option .list_envs_all :
97
95
state .envs .on_empty_fallback_py = False
98
96
option .list_no_description = option .verbosity <= DEFAULT_VERBOSITY
99
97
option .list_default_only = not option .list_envs_all
100
98
option .show_core = False
99
+
100
+ _handle_legacy_only_flags (option , state .envs )
101
+
102
+ if option .show_config :
103
+ return show_config (state )
104
+ if option .list_envs or option .list_envs_all :
101
105
return list_env (state )
102
106
if option .devenv_path :
103
107
option .devenv_path = Path (option .devenv_path )
104
108
return devenv (state )
105
109
if option .parallel != 0 : # only 0 means sequential
106
110
return run_parallel (state )
107
111
return run_sequential (state )
112
+
113
+
114
+ def _handle_legacy_only_flags (option : Parsed , envs : EnvSelector ) -> None :
115
+ override = {}
116
+ if getattr (option , "site_packages" , False ):
117
+ override ["system_site_packages" ] = True
118
+ if getattr (option , "always_copy" , False ):
119
+ override ["always_copy" ] = True
120
+ set_env = {}
121
+ if getattr (option , "pre" , False ):
122
+ set_env ["PIP_PRE" ] = "1"
123
+ forced = {j .name : j for j in getattr (option , "force_dep" , [])}
124
+ if override or set_env or forced :
125
+ for env in envs .iter (only_active = True , package = False ):
126
+ env_conf = envs [env ].conf
127
+ if override :
128
+ env_conf .loaders .insert (0 , MemoryLoader (** override ))
129
+ if set_env :
130
+ cast (SetEnv , env_conf ["set_env" ]).update (set_env , override = True )
131
+ if forced :
132
+ to_force = forced .copy ()
133
+ deps = cast (PythonDeps , env_conf ["deps" ])
134
+ as_root_args = deps .as_root_args
135
+ for at , entry in enumerate (as_root_args ):
136
+ try :
137
+ req = Requirement (entry )
138
+ except InvalidRequirement :
139
+ continue
140
+ if req .name in to_force :
141
+ as_root_args [at ] = str (to_force [req .name ])
142
+ del to_force [req .name ]
143
+ as_root_args .extend (str (v ) for v in to_force .values ())
0 commit comments