Skip to content

Commit

Permalink
vdk-core: support vdk subsections in JobConfig (#3314)
Browse files Browse the repository at this point in the history
Solving: #3305

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
duyguHsnHsn and pre-commit-ci[bot] authored Apr 17, 2024
1 parent 97fb778 commit 9527052
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,35 @@ def get_vdk_options(self) -> Dict[str, str]:
else:
return {}

def get_all_sections(self):
"""Return a list of section names, excluding [DEFAULT]"""
return self._config_ini.sections()

def get_vdk_subsection_names(self):
"""
Retrieves the names of all subsections under the 'vdk' main section from the config.ini file.
Subsections are identified by the pattern 'vdk_<string>'.
Returns a list of subsection names.
"""
subsection_names = [
section
for section in self._config_ini.sections()
if section.startswith("vdk_")
]
return subsection_names

def get_vdk_subsection_values(self, subsection_name):
"""
Given a subsection name under 'vdk', returns all key-value pairs from that subsection.
Subsections are identified by the pattern 'vdk_<string>'.
If the subsection does not exist, it returns an empty dictionary.
:param subsection_name: The name of the subsection (e.g., 'vdk_my_oracle')
"""
if subsection_name in self._config_ini.sections():
return dict(self._config_ini[subsection_name])
return {}

def _get_value(self, section, key):
if self._config_ini.has_option(section, key):
return self._config_ini.get(section, key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,12 @@ def vdk_configure(self, config_builder: ConfigurationBuilder) -> None:

for key, value in job_config.get_vdk_options().items():
config_builder.set_value(key, value)

for subsection in job_config.get_vdk_subsection_names():
for key, value in job_config.get_vdk_subsection_values(
subsection
).items():
# TODO: after the configuration builder is changed, we need to pass the subsection as
# section not as key
config_builder.add(key=subsection + "_" + key, default_value="")
config_builder.set_value(key=subsection + "_" + key, value=value)
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,37 @@ def test_vdk_options(self):
cfg = JobConfig(self._test_dir)
self.assertEqual({"a": "b"}, cfg.get_vdk_options())

def test_get_vdk_subsection_names(self):
self._write_to_config_ini(
self._test_dir,
"""
[vdk_subsection_one]
[vdk_subsection_two]
""",
)
cfg = JobConfig(self._test_dir)
options = ["vdk_subsection_one", "vdk_subsection_two"]
for subclass in cfg.get_vdk_subsection_names():
assert options.count(subclass) == 1

def test_vdk_subsection_values(self):
self._write_to_config_ini(
self._test_dir,
"""
[vdk]
not_to_be_fetched=a
[vdk_subsection]
a=b
c=d
""",
)
cfg = JobConfig(self._test_dir)
values = cfg.get_vdk_subsection_values("vdk_subsection")
self.assertEqual({"a": "b", "c": "d"}, values)

def test_set_team(self):
self._perform_set_team_test("my_unique_team_name")

Expand Down

0 comments on commit 9527052

Please sign in to comment.