Skip to content

Commit

Permalink
Cache env config
Browse files Browse the repository at this point in the history
This commit adds a new cache to the main config object, specifically for
env config. When env config is retrieved via Config.get_env(), it is
not in general possible to determine whether the env is a packaging
environment or not. Because retrieving standard section config needs to
know which "base" section to inherit from, and this is different for
test envs and packaging envs, we require a separate way to retrieve
previously created env config. At creation time we do reliably know
whether this is a packaging or run env, and we want that to persist (if
it changes, we call clear_env() and recreate it with the new type).
  • Loading branch information
Ben Rowland committed Apr 18, 2024
1 parent 0e5a3db commit 6064f55
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/tox/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__( # noqa: PLR0913

self._src = config_source
self._key_to_conf_set: dict[tuple[str, str, str], ConfigSet] = OrderedDict()
self._key_to_env_conf: dict[str, EnvConfigSet] = {}
self._core_set: CoreConfigSet | None = None
self.memory_seed_loaders: defaultdict[str, list[MemoryLoader]] = defaultdict(list)

Expand Down Expand Up @@ -159,18 +160,21 @@ def get_env(
:param loaders: loaders to use for this configuration (only used for creation)
:return: the tox environments config
"""
section, base_test, base_pkg = self._src.get_tox_env_section(item)
return self.get_section_config(
section,
base=base_pkg if package else base_test,
of_type=EnvConfigSet,
for_env=item,
loaders=loaders,
)
if item not in self._key_to_env_conf:
section, base_test, base_pkg = self._src.get_tox_env_section(item)
self._key_to_env_conf[item] = self.get_section_config(
section,
base=base_pkg if package else base_test,
of_type=EnvConfigSet,
for_env=item,
loaders=loaders,
)
return self._key_to_env_conf[item]

def clear_env(self, name: str) -> None:
section, _, __ = self._src.get_tox_env_section(name)
self._key_to_conf_set = {k: v for k, v in self._key_to_conf_set.items() if k[0] == section.key and k[1] == name}
self._key_to_env_conf.pop(name)


___all__ = [
Expand Down

0 comments on commit 6064f55

Please sign in to comment.