summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernát Gábor <gaborjbernat@gmail.com>2022-12-15 15:59:36 -0800
committerGitHub <noreply@github.com>2022-12-15 15:59:36 -0800
commit4558fee5ac372c6842e5cb2ccd64c441d5a1aac5 (patch)
tree52e9c8ed3fc10014a5e7ab4c1883d026b4ef15a4 /src
parent3641a477e40e606320fea11949b5bb571aace7d5 (diff)
downloadtox-git-4558fee5ac372c6842e5cb2ccd64c441d5a1aac5.tar.gz
Fix legacy flags, deprecate them and remove --index-url (#2731)
Resolves https://github.com/tox-dev/tox/issues/2690
Diffstat (limited to 'src')
-rw-r--r--src/tox/session/cmd/legacy.py66
-rw-r--r--src/tox/tox_env/python/virtual_env/api.py5
2 files changed, 53 insertions, 18 deletions
diff --git a/src/tox/session/cmd/legacy.py b/src/tox/session/cmd/legacy.py
index bb5e993f..e92c3d27 100644
--- a/src/tox/session/cmd/legacy.py
+++ b/src/tox/session/cmd/legacy.py
@@ -1,15 +1,21 @@
from __future__ import annotations
from pathlib import Path
+from typing import cast
-from tox.config.cli.parser import DEFAULT_VERBOSITY, ToxParser
+from packaging.requirements import InvalidRequirement, Requirement
+
+from tox.config.cli.parser import DEFAULT_VERBOSITY, Parsed, ToxParser
+from tox.config.loader.memory import MemoryLoader
+from tox.config.set_env import SetEnv
from tox.plugin import impl
from tox.session.cmd.run.common import env_run_create_flags
from tox.session.cmd.run.parallel import OFF_VALUE, parallel_flags, run_parallel
from tox.session.cmd.run.sequential import run_sequential
from tox.session.state import State
+from tox.tox_env.python.pip.req_file import PythonDeps
-from ..env_select import CliEnv, register_env_select_flags
+from ..env_select import CliEnv, EnvSelector, register_env_select_flags
from .devenv import devenv
from .list_env import list_env
from .show_config import show_config
@@ -54,16 +60,8 @@ def tox_add_option(parser: ToxParser) -> None:
our.add_argument(
"--pre",
action="store_true",
- help="install pre-releases and development versions of dependencies. This will pass the --pre option to"
- "install_command (pip by default).",
- )
- our.add_argument(
- "-i",
- "--index-url",
- action="append",
- default=[],
- metavar="url",
- help="set indexserver url (if URL is of form name=url set the url for the 'name' indexserver, specifically)",
+ help="deprecated use PIP_PRE in set_env instead - install pre-releases and development versions of"
+ "dependencies; this will set PIP_PRE=1 environment variable",
)
our.add_argument(
"--force-dep",
@@ -72,17 +70,18 @@ def tox_add_option(parser: ToxParser) -> None:
default=[],
help="Forces a certain version of one of the dependencies when configuring the virtual environment. REQ "
"Examples 'pytest<6.1' or 'django>=2.2'.",
+ type=Requirement,
)
our.add_argument(
"--sitepackages",
action="store_true",
- help="override sitepackages setting to True in all envs",
+ help="deprecated use VIRTUALENV_SYSTEM_SITE_PACKAGES=1, override sitepackages setting to True in all envs",
dest="site_packages",
)
our.add_argument(
"--alwayscopy",
action="store_true",
- help="override always copy setting to True in all envs",
+ help="deprecated use VIRTUALENV_ALWAYS_COPY=1, override always copy setting to True in all envs",
dest="always_copy",
)
@@ -92,12 +91,17 @@ def legacy(state: State) -> int:
if option.show_config:
option.list_keys_only = []
option.show_core = not bool(option.env)
- return show_config(state)
if option.list_envs or option.list_envs_all:
state.envs.on_empty_fallback_py = False
option.list_no_description = option.verbosity <= DEFAULT_VERBOSITY
option.list_default_only = not option.list_envs_all
option.show_core = False
+
+ _handle_legacy_only_flags(option, state.envs)
+
+ if option.show_config:
+ return show_config(state)
+ if option.list_envs or option.list_envs_all:
return list_env(state)
if option.devenv_path:
option.devenv_path = Path(option.devenv_path)
@@ -105,3 +109,35 @@ def legacy(state: State) -> int:
if option.parallel != 0: # only 0 means sequential
return run_parallel(state)
return run_sequential(state)
+
+
+def _handle_legacy_only_flags(option: Parsed, envs: EnvSelector) -> None:
+ override = {}
+ if getattr(option, "site_packages", False):
+ override["system_site_packages"] = True
+ if getattr(option, "always_copy", False):
+ override["always_copy"] = True
+ set_env = {}
+ if getattr(option, "pre", False):
+ set_env["PIP_PRE"] = "1"
+ forced = {j.name: j for j in getattr(option, "force_dep", [])}
+ if override or set_env or forced:
+ for env in envs.iter(only_active=True, package=False):
+ env_conf = envs[env].conf
+ if override:
+ env_conf.loaders.insert(0, MemoryLoader(**override))
+ if set_env:
+ cast(SetEnv, env_conf["set_env"]).update(set_env, override=True)
+ if forced:
+ to_force = forced.copy()
+ deps = cast(PythonDeps, env_conf["deps"])
+ as_root_args = deps.as_root_args
+ for at, entry in enumerate(as_root_args):
+ try:
+ req = Requirement(entry)
+ except InvalidRequirement:
+ continue
+ if req.name in to_force:
+ as_root_args[at] = str(to_force[req.name])
+ del to_force[req.name]
+ as_root_args.extend(str(v) for v in to_force.values())
diff --git a/src/tox/tox_env/python/virtual_env/api.py b/src/tox/tox_env/python/virtual_env/api.py
index 01bdc627..f2b87a43 100644
--- a/src/tox/tox_env/python/virtual_env/api.py
+++ b/src/tox/tox_env/python/virtual_env/api.py
@@ -112,10 +112,9 @@ class VirtualEnv(Python):
base_python: list[str] = self.conf["base_python"]
if "VIRTUALENV_NO_PERIODIC_UPDATE" not in env:
env["VIRTUALENV_NO_PERIODIC_UPDATE"] = "True"
- site = getattr(self.options, "site_packages", False) or self.conf["system_site_packages"]
env["VIRTUALENV_CLEAR"] = "False"
- env["VIRTUALENV_SYSTEM_SITE_PACKAGES"] = str(site)
- env["VIRTUALENV_COPIES"] = str(getattr(self.options, "always_copy", False) or self.conf["always_copy"])
+ env["VIRTUALENV_SYSTEM_SITE_PACKAGES"] = str(self.conf["system_site_packages"])
+ env["VIRTUALENV_COPIES"] = str(self.conf["always_copy"])
env["VIRTUALENV_DOWNLOAD"] = str(self.conf["download"])
env["VIRTUALENV_PYTHON"] = "\n".join(base_python)
if hasattr(self.options, "discover"):