Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read file in read mode #1338

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add a test, move parsing of avoid_duplicate_runs
  • Loading branch information
PGijsbers committed May 14, 2024
commit 4a9b5684749f7eff1ebd072d007ed73afbde6807
6 changes: 5 additions & 1 deletion openml/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _setup(config: _Config | None = None) -> None:
if config is None:
config = _parse_config(config_file)

avoid_duplicate_runs = config.get("avoid_duplicate_runs", "").lower() == "true"
avoid_duplicate_runs = config["avoid_duplicate_runs"]
apikey = config["apikey"]
server = config["server"]
short_cache_dir = Path(config["cachedir"])
Expand Down Expand Up @@ -328,6 +328,10 @@ def _parse_config(config_file: str | Path) -> _Config:
logger.info("Error opening file %s: %s", config_file, e.args[0])
config_file_.seek(0)
config.read_file(config_file_)
if isinstance(config["FAKE_SECTION"]["avoid_duplicate_runs"], str):
config["FAKE_SECTION"]["avoid_duplicate_runs"] = config["FAKE_SECTION"].getboolean(
"avoid_duplicate_runs"
) # type: ignore
return dict(config.items("FAKE_SECTION")) # type: ignore


Expand Down
17 changes: 17 additions & 0 deletions tests/test_openml/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,20 @@ def test_example_configuration_start_twice(self):

assert openml.config.apikey == "610344db6388d9ba34f6db45a3cf71de"
assert openml.config.server == self.production_server


def test_configuration_file_not_overwritten_on_load():
""" Regression test for #1337 """
config_file_content = "apikey = abcd"
with tempfile.TemporaryDirectory() as tmpdir:
config_file_path = Path(tmpdir) / "config"
with config_file_path.open("w") as config_file:
config_file.write(config_file_content)

read_config = openml.config._parse_config(config_file_path)

with config_file_path.open("r") as config_file:
new_file_content = config_file.read()

assert config_file_content == new_file_content
assert "abcd" == read_config["apikey"]
Loading