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 f9945d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/changelog/2926.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Plugins are now able to access tox.ini config sections using a custom prefix with the same suffix / name as a tox
``testenv`` - by :user:`masenf`
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 f9945d2

Please sign in to comment.