Use Python instead of sed to edit the Qleverfile in setup-config - #323
Merged
Conversation
…ing an sed command
There was a problem hiding this comment.
Pull request overview
This PR replaces the sed-based Qleverfile patching in qlever setup-config with a Python-native INI updater (util.update_ini_values), improving cross-platform behavior and enabling adding missing sections/options.
Changes:
- Add
edit_option_line/update_ini_valuesutilities to update INI-style files in-memory (including adding missing options/sections). - Refactor
setup-configto build anupdatesstructure and apply it via Python (and change--showto print a summary rather than a shell pipeline). - Add focused unit tests for the new INI editing behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
test/qlever/test_util.py |
Adds unit tests covering option editing and INI update behavior (replace/append/add/ignore commented lines). |
src/qlever/util.py |
Introduces Python helpers for editing INI content (replacing prior sed command generation). |
src/qlever/commands/setup_config.py |
Switches setup-config from shell pipeline to Python edits; adjusts override handling and --show output. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+91
to
+96
| for section, arg_name in self.override_args: | ||
| if arg_value := getattr(args, arg_name, None): | ||
| updates.setdefault(section, {})[arg_name.upper()] = ( | ||
| str(arg_value), | ||
| False, | ||
| ) |
Comment on lines
+111
to
+117
| for section, option_dict in updates.items(): | ||
| show_lines.append(f"\n[{section}]") | ||
| for option, (value, is_suffix) in option_dict.items(): | ||
| shown_value = ( | ||
| "*" * len(value) if option == "ACCESS_TOKEN" else value | ||
| ) | ||
| show_lines.append(f"{option} = {shown_value}") |
Comment on lines
+647
to
+650
| for section in updates: | ||
| if section not in sections_seen: | ||
| result_lines.append(f"\n[{section}]") | ||
| result_lines.extend(missing_option_lines(section)) |
…n added options with their section
sed to generate the Qleverfile in setup-config
sed to generate the Qleverfile in setup-configsed to edit the Qleverfile in setup-config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
qlever setup-configno longer pipes the template throughsedto patch in theACCESS_TOKENand the--port,--timeout, and--systemoverrides, but edits it in Python with the newutil.update_ini_values. That does not depend on the platform'ssed, and unlike asedsubstitution it can also add an option or a section that the template does not have.--shownow prints the options that will differ from the template, with theACCESS_TOKENmasked, instead of a shell pipeline. WithQLEVER_IS_RUNNING_IN_CONTAINERset,--portand--timeoutare now still applied and onlySYSTEMis forced tonative; before, all overrides were skipped in that case. And an override that was not given on the command line is no longer written at all, so a generated Qleverfile keeps theTIMEOUTandSYSTEMof its template.