mirror of
https://github.com/fedora-python/tox-current-env.git
synced 2024-12-23 16:46:14 +01:00
Use our own subprocess executor to alter env variables
This commit is contained in:
parent
70a344a8f9
commit
dadd0a954b
@ -10,7 +10,10 @@ from typing import Set
|
|||||||
|
|
||||||
from tox.config.loader.memory import MemoryLoader
|
from tox.config.loader.memory import MemoryLoader
|
||||||
from tox.execute.api import Execute
|
from tox.execute.api import Execute
|
||||||
from tox.execute.local_sub_process import LocalSubProcessExecutor
|
from tox.execute.local_sub_process import (
|
||||||
|
Execute,
|
||||||
|
LocalSubProcessExecuteInstance,
|
||||||
|
)
|
||||||
from tox.plugin import impl
|
from tox.plugin import impl
|
||||||
from tox.report import HandledError
|
from tox.report import HandledError
|
||||||
from tox.tox_env.python.api import PythonInfo
|
from tox.tox_env.python.api import PythonInfo
|
||||||
@ -108,11 +111,28 @@ class Installer:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class CurrentEnvLocalSubProcessExecutor(Execute):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.tempdir = kwargs.pop("tempdir")
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def build_instance(
|
||||||
|
self,
|
||||||
|
request,
|
||||||
|
options,
|
||||||
|
out,
|
||||||
|
err,
|
||||||
|
):
|
||||||
|
request.env["PATH"] = ":".join((str(self.tempdir.name), request.env.get("PATH", "")))
|
||||||
|
return LocalSubProcessExecuteInstance(request, options, out, err)
|
||||||
|
|
||||||
|
|
||||||
class CurrentEnv(PythonRun):
|
class CurrentEnv(PythonRun):
|
||||||
def __init__(self, create_args):
|
def __init__(self, create_args):
|
||||||
self._executor = None
|
self._executor = None
|
||||||
self._installer = None
|
self._installer = None
|
||||||
self._path = []
|
self._path = []
|
||||||
|
self.tempdir = tempfile.TemporaryDirectory()
|
||||||
super().__init__(create_args)
|
super().__init__(create_args)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -134,7 +154,7 @@ class CurrentEnv(PythonRun):
|
|||||||
@property
|
@property
|
||||||
def executor(self):
|
def executor(self):
|
||||||
if self._executor is None:
|
if self._executor is None:
|
||||||
self._executor = LocalSubProcessExecutor(self.options.is_colored)
|
self._executor = CurrentEnvLocalSubProcessExecutor(self.options.is_colored, tempdir=self.tempdir)
|
||||||
return self._executor
|
return self._executor
|
||||||
|
|
||||||
def _get_python(self, base_python):
|
def _get_python(self, base_python):
|
||||||
@ -150,14 +170,12 @@ class CurrentEnv(PythonRun):
|
|||||||
def create_python_env(self):
|
def create_python_env(self):
|
||||||
# Fake Python environment just to make sure all possible
|
# Fake Python environment just to make sure all possible
|
||||||
# commands like python or python3 works.
|
# commands like python or python3 works.
|
||||||
self.tempdir = tempfile.TemporaryDirectory()
|
|
||||||
for suffix in (
|
for suffix in (
|
||||||
"",
|
"",
|
||||||
f"{sys.version_info.major}",
|
f"{sys.version_info.major}",
|
||||||
f"{sys.version_info.major}.{sys.version_info.minor}",
|
f"{sys.version_info.major}.{sys.version_info.minor}",
|
||||||
):
|
):
|
||||||
os.symlink(sys.executable, Path(self.tempdir.name) / f"python{suffix}")
|
os.symlink(sys.executable, Path(self.tempdir.name) / f"python{suffix}")
|
||||||
os.environ["PATH"] = ":".join((os.environ["PATH"], str(self.tempdir.name)))
|
|
||||||
|
|
||||||
def _teardown(self):
|
def _teardown(self):
|
||||||
del self.tempdir
|
del self.tempdir
|
||||||
|
Loading…
Reference in New Issue
Block a user