Skip to content

Commit

Permalink
IniSource.get_loader: check section.prefix
Browse files Browse the repository at this point in the history
ensure that loaders returned from .ini source are bound
to the correct section prefix, if specified.

add comment explaining why the code must look up the name
in the _section_mapping

fix tox-dev#2926
  • Loading branch information
masenf committed Feb 21, 2023
1 parent a32eede commit b819b98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Empty file added docs/changelog/2926.bugfix.rst
Empty file.
9 changes: 7 additions & 2 deletions src/tox/config/source/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ def sections(self) -> Iterator[IniSection]:
yield IniSection.from_key(section)

def get_loader(self, section: Section, override_map: OverrideMap) -> IniLoader | None:
sections = self._section_mapping.get(section.name)
key = sections[0] if sections else section.key
# look up requested section name in the generative testenv mapping to find the real config source
for key in self._section_mapping.get(section.name) or []:
if section.prefix is None or Section.from_key(key).prefix == section.prefix:
break
else:
# if no matching section/prefix is found, use the requested section key as-is (for custom prefixes)
key = section.key
if self._parser.has_section(key):
return IniLoader(
section=section,
Expand Down

0 comments on commit b819b98

Please sign in to comment.