Skip to content

Commit 02c0232

Browse files
committed
squash: avoid .environ
1 parent 2ed33bc commit 02c0232

13 files changed

Lines changed: 52 additions & 33 deletions

File tree

tmt/config/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ def effective_config_dir() -> Path:
2828
:py:const:`DEFAULT_CONFIG_DIR` is picked.
2929
"""
3030

31-
if 'TMT_CONFIG_DIR' in tmt.utils.Environment.environ:
32-
return Path(tmt.utils.Environment.environ['TMT_CONFIG_DIR']).expanduser()
31+
environment = tmt.utils.Environment.from_environ()
32+
33+
if 'TMT_CONFIG_DIR' in environment:
34+
return Path(environment['TMT_CONFIG_DIR']).expanduser()
3335

3436
return DEFAULT_CONFIG_DIR.expanduser()
3537

tmt/guest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def configure_ssh_options() -> tmt.utils.RawCommand:
201201

202202
options: tmt.utils.RawCommand = []
203203

204-
for name, value in Environment.environ.items():
204+
for name, value in Environment.from_environ().items():
205205
match = SSH_OPTIONS_ENVVAR_PATTERN.match(name)
206206

207207
if not match:

tmt/libraries/beakerlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def _do_fetch(self, directory: Path) -> None:
364364
else:
365365
self.parent.debug(f"Cloning '{self.identifier}' for '{self}'.", level=3)
366366

367-
environment = Environment.environ
367+
environment = Environment.from_environ()
368368
environment["GIT_ASKPASS"] = EnvVarValue("echo")
369369

370370
tmt.utils.git.git_clone(

tmt/log.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def create_decolorizer(apply_colors: bool) -> Callable[[str], str]:
144144
def _debug_level_from_global_envvar() -> Optional[DebugLevel]:
145145
import tmt.utils
146146

147-
raw_value = tmt.utils.Environment.environ.get('TMT_DEBUG', None)
147+
raw_value = tmt.utils.Environment.from_environ().get('TMT_DEBUG', None)
148148

149149
if raw_value is None:
150150
return 0
@@ -194,15 +194,17 @@ def decide_colorization(no_color: bool, force_color: bool) -> tuple[bool, bool]:
194194

195195
from tmt.utils import Environment
196196

197+
environment = Environment.from_environ()
198+
197199
# Default values: assume colors & unicorns everywhere.
198200
apply_colors_output = apply_colors_logging = True
199201

200202
# Enforce colors if `--force-color` was used, or `TMT_FORCE_COLOR` envvar is set.
201-
if force_color or 'TMT_FORCE_COLOR' in Environment.environ:
203+
if force_color or 'TMT_FORCE_COLOR' in environment:
202204
apply_colors_output = apply_colors_logging = True
203205

204206
# Disable coloring if `--no-color` was used, or `NO_COLOR` or `TMT_NO_COLOR` envvar is set.
205-
elif no_color or 'NO_COLOR' in Environment.environ or 'TMT_NO_COLOR' in Environment.environ:
207+
elif no_color or 'NO_COLOR' in environment or 'TMT_NO_COLOR' in environment:
206208
apply_colors_output = apply_colors_logging = False
207209

208210
# Autodetection, disable colors when not talking to a terminal.

tmt/plugins/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ def _explore_custom_directories(logger: Logger) -> None:
122122
logger.debug('Import plugins from custom directories.')
123123
logger = logger.descend()
124124

125-
if not tmt.utils.Environment.environ.get(ENVIRONMENT_NAME):
125+
environment = tmt.utils.Environment.from_environ()
126+
127+
if not environment.get(ENVIRONMENT_NAME):
126128
logger.debug(
127129
f"No custom directories found in the '{ENVIRONMENT_NAME}' environment variable."
128130
)
129131
return
130132

131-
for _path in tmt.utils.Environment.environ[ENVIRONMENT_NAME].split(os.pathsep):
133+
for _path in environment[ENVIRONMENT_NAME].split(os.pathsep):
132134
# TID251: `pathlib` does not provide `os.patch.expandvars`, its
133135
# use is allowed. For the simplicity, keeping `expanduser` as well,
134136
# to avoid str -> Path -> str -> Path conversion.

tmt/steps/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ def _log_raw_data(stage: str, raw_data: list[_RawStepData]) -> None:
12631263

12641264
# First pass, apply environment variables
12651265
for i, plugin_envvar in enumerate(
1266-
PluginEnvVar.from_environment(Environment.environ, self)
1266+
PluginEnvVar.from_environment(Environment.from_environ(), self)
12671267
):
12681268
debug2(f'environment invocation #{i}', str(plugin_envvar))
12691269

tmt/steps/context/pidfile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ def effective_pidfile_root() -> Path:
186186
:py:const:`TEST_PIDFILE_ROOT` is picked.
187187
"""
188188

189-
if 'TMT_TEST_PIDFILE_ROOT' in Environment.environ:
190-
return Path(Environment.environ['TMT_TEST_PIDFILE_ROOT'])
189+
environment = Environment.from_environ()
190+
191+
if 'TMT_TEST_PIDFILE_ROOT' in environment:
192+
return Path(environment['TMT_TEST_PIDFILE_ROOT'])
191193

192194
return TEST_PIDFILE_ROOT
193195

tmt/steps/discover/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def _fetch_remote_source(self, url: str) -> Optional[Path]:
286286
if self.data.url_content_type == "git":
287287
self.debug(f"Clone '{url}' to '{self.test_dir}'.")
288288

289-
environment = Environment.environ
289+
environment = Environment.from_environ()
290290
environment["GIT_ASKPASS"] = EnvVarValue("echo")
291291

292292
tmt.utils.git.git_clone(

tmt/steps/provision/local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
336336
self._guest.start()
337337
self._guest.setup()
338338

339-
if tmt.utils.Environment.environ.get(tmt.steps.scripts.SCRIPTS_DEST_DIR_VARIABLE):
339+
if tmt.utils.Environment.from_environ().get(tmt.steps.scripts.SCRIPTS_DEST_DIR_VARIABLE):
340340
self.warn(
341341
f"The '{tmt.steps.scripts.SCRIPTS_DEST_DIR_VARIABLE}' variable "
342342
"is not supported in 'local' provision, the default scripts path "

tmt/steps/scripts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def effective_scripts_dest_dir(default: Path = DEFAULT_SCRIPTS_DEST_DIR) -> Path
131131
parameter path is returned.
132132
"""
133133

134-
return Path(tmt.utils.Environment.environ.get(SCRIPTS_DEST_DIR_VARIABLE, default))
134+
return Path(tmt.utils.Environment.from_environ().get(SCRIPTS_DEST_DIR_VARIABLE, default))
135135

136136

137137
# Script handling reboots, in restraint compatible fashion

0 commit comments

Comments
 (0)