Warn when venv/install doesn't match previously used one (#6715)

This commit is contained in:
Jakub Kuczys
2026-04-05 21:44:17 +02:00
committed by GitHub
parent fcb8bc0265
commit f70c48ec30

View File

@@ -152,6 +152,7 @@ class Red(
invoke_error_msg=None, invoke_error_msg=None,
extra_owner_destinations=[], extra_owner_destinations=[],
owner_opt_out_list=[], owner_opt_out_list=[],
last_system_info__python_prefix=None,
last_system_info__python_version=[3, 7], last_system_info__python_version=[3, 7],
last_system_info__machine=None, last_system_info__machine=None,
last_system_info__system=None, last_system_info__system=None,
@@ -1209,6 +1210,28 @@ class Red(
last_system_info = await self._config.last_system_info() last_system_info = await self._config.last_system_info()
last_python_prefix = last_system_info["python_prefix"]
if last_python_prefix is None:
await self._config.last_system_info.python_prefix.set(sys.prefix)
elif last_python_prefix != sys.prefix:
await self._config.last_system_info.python_prefix.set(sys.prefix)
try:
same_install = os.path.samefile(last_python_prefix, sys.prefix)
except OSError:
same_install = False
if not same_install:
if sys.prefix != sys.base_prefix:
install_info = "in the currently used virtual environment"
else:
install_info = "with the currently used Python installation"
log.warning(
"Red seems to have been started with a different Python installation"
" and/or virtual environment. This is not, in itself, an issue but is often"
" done unintentionally and may explain some, otherwise unexpected, behavior."
" This message will not be shown again, if you start Red %s again.",
install_info,
)
ver_info = list(sys.version_info[:2]) ver_info = list(sys.version_info[:2])
python_version_changed = False python_version_changed = False
if ver_info != last_system_info["python_version"]: if ver_info != last_system_info["python_version"]: