mirror of
https://github.com/fedora-python/tox-current-env.git
synced 2025-01-11 08:56:14 +01:00
Make __init__ methods noop and use env_dir instead of a temp dir
This commit is contained in:
parent
14fd3c24c2
commit
0e90086c0f
@ -113,10 +113,6 @@ class Installer:
|
|||||||
|
|
||||||
|
|
||||||
class CurrentEnvLocalSubProcessExecutor(Execute):
|
class CurrentEnvLocalSubProcessExecutor(Execute):
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self.tempdir = kwargs.pop("tempdir")
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
def build_instance(
|
def build_instance(
|
||||||
self,
|
self,
|
||||||
request,
|
request,
|
||||||
@ -124,7 +120,9 @@ class CurrentEnvLocalSubProcessExecutor(Execute):
|
|||||||
out,
|
out,
|
||||||
err,
|
err,
|
||||||
):
|
):
|
||||||
request.env["PATH"] = ":".join((str(self.tempdir.name), request.env.get("PATH", "")))
|
request.env["PATH"] = ":".join(
|
||||||
|
(str(options._env.env_dir / "bin"), request.env.get("PATH", ""))
|
||||||
|
)
|
||||||
return LocalSubProcessExecuteInstance(request, options, out, err)
|
return LocalSubProcessExecuteInstance(request, options, out, err)
|
||||||
|
|
||||||
|
|
||||||
@ -133,7 +131,6 @@ class CurrentEnv(PythonRun):
|
|||||||
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
|
||||||
@ -155,7 +152,7 @@ class CurrentEnv(PythonRun):
|
|||||||
@property
|
@property
|
||||||
def executor(self):
|
def executor(self):
|
||||||
if self._executor is None:
|
if self._executor is None:
|
||||||
self._executor = CurrentEnvLocalSubProcessExecutor(self.options.is_colored, tempdir=self.tempdir)
|
self._executor = CurrentEnvLocalSubProcessExecutor(self.options.is_colored)
|
||||||
return self._executor
|
return self._executor
|
||||||
|
|
||||||
def _get_python(self, base_python):
|
def _get_python(self, base_python):
|
||||||
@ -169,17 +166,19 @@ 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."""
|
||||||
|
bindir = self.env_dir / "bin"
|
||||||
|
if not bindir.exists():
|
||||||
|
os.mkdir(bindir)
|
||||||
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}")
|
symlink = bindir / f"python{suffix}"
|
||||||
|
if not symlink.exists():
|
||||||
def _teardown(self):
|
os.symlink(sys.executable, symlink)
|
||||||
del self.tempdir
|
|
||||||
|
|
||||||
def env_bin_dir(self):
|
def env_bin_dir(self):
|
||||||
return Path(sysconfig.get_path("scripts"))
|
return Path(sysconfig.get_path("scripts"))
|
||||||
@ -206,18 +205,6 @@ class PrintEnv(CurrentEnv):
|
|||||||
def __init__(self, create_args):
|
def __init__(self, create_args):
|
||||||
super().__init__(create_args)
|
super().__init__(create_args)
|
||||||
|
|
||||||
# As soon as this environment has enough info to do its job,
|
|
||||||
# do it and nothing more.
|
|
||||||
|
|
||||||
if self.options.print_deps_to:
|
|
||||||
print(
|
|
||||||
*self.core["requires"],
|
|
||||||
*self.conf["deps"].lines(),
|
|
||||||
sep="\n",
|
|
||||||
file=self.options.print_deps_to,
|
|
||||||
)
|
|
||||||
self.options.print_deps_to.flush()
|
|
||||||
|
|
||||||
if self.options.print_extras_to:
|
if self.options.print_extras_to:
|
||||||
if "extras" not in self.conf:
|
if "extras" not in self.conf:
|
||||||
# Unfortunately, if there is skipsdist/no_package or skip_install
|
# Unfortunately, if there is skipsdist/no_package or skip_install
|
||||||
@ -229,6 +216,24 @@ class PrintEnv(CurrentEnv):
|
|||||||
default=set(),
|
default=set(),
|
||||||
desc="extras to install of the target package",
|
desc="extras to install of the target package",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def create_python_env(self):
|
||||||
|
"""We don't need any environment for this plugin"""
|
||||||
|
return None
|
||||||
|
|
||||||
|
def prepend_env_var_path(self):
|
||||||
|
"""Usage of this method for the core of this plugin is far from perfect
|
||||||
|
but this method is called every time even without recreated environment"""
|
||||||
|
if self.options.print_deps_to:
|
||||||
|
print(
|
||||||
|
*self.core["requires"],
|
||||||
|
*self.conf["deps"].lines(),
|
||||||
|
sep="\n",
|
||||||
|
file=self.options.print_deps_to,
|
||||||
|
)
|
||||||
|
self.options.print_deps_to.flush()
|
||||||
|
|
||||||
|
if self.options.print_extras_to:
|
||||||
print(
|
print(
|
||||||
*self.conf["extras"],
|
*self.conf["extras"],
|
||||||
sep="\n",
|
sep="\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user