Skip to content

Commit

Permalink
Fixing overlaping sections bug (#4915)
Browse files Browse the repository at this point in the history
* Fixing overlaping sections bug

* Reading before environment section is set to avoid errors

* skipping environment section

* read the file before environment

* removing reading with parser

* making parser case sensitive

---------

Co-authored-by: Aleyna Akyuz <[email protected]>
Co-authored-by: Aleyna Akyuz <[email protected]>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent 3caa512 commit 287b462
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pycbc/types/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ def read_ini_file(self, fpath):
"""
Read a .ini file and return it as a ConfigParser class.
This function does none of the parsing/combining of sections. It simply
reads the file and returns it unedited
reads the file, checks if there are overlaping options
and returns it unedited
Stub awaiting more functionality - see configparser_test.py
Expand All @@ -245,6 +246,27 @@ def read_ini_file(self, fpath):
The ConfigParser class containing the read in .ini file
"""
# Read the file

options_seen = {}

for filename in fpath:
parser = ConfigParser.ConfigParser()
parser.optionxform=str
parser.read(filename)

for section in parser.sections():
if section not in options_seen:
options_seen[section] = set()

section_options = parser.options(section)

option_intersection = options_seen[section].intersection(section_options)

if option_intersection:
raise ValueError(f"Duplicate option(s) {', '.join(option_intersection)} found in section '{section}' in file '{filename}'")

options_seen[section].update(section_options)

self.read(fpath)

def get_subsections(self, section_name):
Expand Down

0 comments on commit 287b462

Please sign in to comment.