log.py: remove setenv calls (#48933)
This commit is contained in:
parent
04313afc63
commit
6d608a9664
@ -344,26 +344,6 @@ def close(self):
|
|||||||
self.file.close()
|
self.file.close()
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def replace_environment(env):
|
|
||||||
"""Replace the current environment (`os.environ`) with `env`.
|
|
||||||
|
|
||||||
If `env` is empty (or None), this unsets all current environment
|
|
||||||
variables.
|
|
||||||
"""
|
|
||||||
env = env or {}
|
|
||||||
old_env = os.environ.copy()
|
|
||||||
try:
|
|
||||||
os.environ.clear()
|
|
||||||
for name, val in env.items():
|
|
||||||
os.environ[name] = val
|
|
||||||
yield
|
|
||||||
finally:
|
|
||||||
os.environ.clear()
|
|
||||||
for name, val in old_env.items():
|
|
||||||
os.environ[name] = val
|
|
||||||
|
|
||||||
|
|
||||||
def log_output(*args, **kwargs):
|
def log_output(*args, **kwargs):
|
||||||
"""Context manager that logs its output to a file.
|
"""Context manager that logs its output to a file.
|
||||||
|
|
||||||
@ -447,7 +427,6 @@ def __init__(
|
|||||||
self.echo = echo
|
self.echo = echo
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.buffer = buffer
|
self.buffer = buffer
|
||||||
self.env = env # the environment to use for _writer_daemon
|
|
||||||
self.filter_fn = filter_fn
|
self.filter_fn = filter_fn
|
||||||
|
|
||||||
self._active = False # used to prevent re-entry
|
self._active = False # used to prevent re-entry
|
||||||
@ -519,7 +498,6 @@ def __enter__(self):
|
|||||||
# just don't forward input if this fails
|
# just don't forward input if this fails
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with replace_environment(self.env):
|
|
||||||
self.process = multiprocessing.Process(
|
self.process = multiprocessing.Process(
|
||||||
target=_writer_daemon,
|
target=_writer_daemon,
|
||||||
args=(
|
args=(
|
||||||
@ -729,10 +707,7 @@ class winlog:
|
|||||||
Does not support the use of 'v' toggling as nixlog does.
|
Does not support the use of 'v' toggling as nixlog does.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, file_like=None, echo=False, debug=0, buffer=False, filter_fn=None):
|
||||||
self, file_like=None, echo=False, debug=0, buffer=False, env=None, filter_fn=None
|
|
||||||
):
|
|
||||||
self.env = env
|
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.echo = echo
|
self.echo = echo
|
||||||
self.logfile = file_like
|
self.logfile = file_like
|
||||||
@ -789,7 +764,6 @@ def background_reader(reader, echo_writer, _kill):
|
|||||||
reader.close()
|
reader.close()
|
||||||
|
|
||||||
self._active = True
|
self._active = True
|
||||||
with replace_environment(self.env):
|
|
||||||
self._thread = Thread(
|
self._thread = Thread(
|
||||||
target=background_reader, args=(self.reader, self.echo_writer, self._kill)
|
target=background_reader, args=(self.reader, self.echo_writer, self._kill)
|
||||||
)
|
)
|
||||||
|
@ -2436,11 +2436,7 @@ def _real_install(self) -> None:
|
|||||||
# DEBUGGING TIP - to debug this section, insert an IPython
|
# DEBUGGING TIP - to debug this section, insert an IPython
|
||||||
# embed here, and run the sections below without log capture
|
# embed here, and run the sections below without log capture
|
||||||
log_contextmanager = log_output(
|
log_contextmanager = log_output(
|
||||||
log_file,
|
log_file, self.echo, True, filter_fn=self.filter_fn
|
||||||
self.echo,
|
|
||||||
True,
|
|
||||||
env=self.unmodified_env,
|
|
||||||
filter_fn=self.filter_fn,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
with log_contextmanager as logger:
|
with log_contextmanager as logger:
|
||||||
|
Loading…
Reference in New Issue
Block a user