Skip to content

refactor(parsers): replace configobj with stdlib implementations - #7026

Open
sshedi wants to merge 11 commits into
canonical:mainfrom
sshedi:drop-configobj
Open

refactor(parsers): replace configobj with stdlib implementations#7026
sshedi wants to merge 11 commits into
canonical:mainfrom
sshedi:drop-configobj

Conversation

@sshedi

@sshedi sshedi commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Proposed Commit Message

refactor(parsers): replace configobj with stdlib implementations

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

@sshedi

sshedi commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Discussion link: #7023

@sshedi
sshedi force-pushed the drop-configobj branch 3 times, most recently from e08c7e8 to 04f9007 Compare August 21, 2026 19:29
@sshedi sshedi changed the title Drop configobj refactor(parsers): replace configobj with stdlib implementations Aug 22, 2026
sshedi and others added 11 commits August 22, 2026 12:20
SysConf is rewritten as a plain dict subclass that preserves comment
lines, key ordering, and inline comments through a parse-then-emit
cycle. Shell-variable quoting logic is retained verbatim. The quote
format constants (_SQUOT, _DQUOT, etc.) are inlined from configobj so
the output is byte-for-byte identical.

NetworkManagerConf is rewritten on top of configparser.RawConfigParser
with the same public API: sections, set_section_keypair(), write().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
Both networkd_parse_lease() and network_manager_load_leases() used
ConfigObj solely to parse flat key=value content with no sections.
The new _parse_key_value() helper does the same with a simple loop,
accepting a file-like object, a list of lines, or a plain string.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
Introduces _McollectiveConfig, a lightweight class that reads and
writes mcollective server.cfg files. The format is sectionless key=value
at the top level with optional [section] blocks. Original key and section
ordering is preserved on write. The class exposes the same interface that
the handler code used on ConfigObj: dict-style item access, .sections,
and .write(file).

The test helper that read the written file back via ConfigObj is replaced
with a simple key=value parser so there is no longer any configobj
dependency in this module or its tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
…merge

merge_together() now accepts plain dicts and INI filenames. Dicts are
deep-copied before merging so that the module-level LSC_BUILTIN_CFG
constant is never mutated across calls. INI files are parsed with
configparser.RawConfigParser, which handles the [client] section
natively. No behaviour change for callers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
…tting

_format_repository_config() used ConfigObj only to produce a [section]
block with key=value lines. The replacement builds that string directly,
removing the dependency with no behaviour change for zypper repo files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
These tests imported ConfigObj only to parse written sysconfig files and
verify their contents. The verification is now done with an inline
key=value loop, which reads KEY=VALUE lines and strips surrounding
whitespace. No test logic changes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
All usages have been replaced with stdlib alternatives (configparser,
copy, and plain dict/string operations). Remove the dependency from
both requirements.txt and pyproject.toml.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
parse_key_value() parses flat key=value content (comments and blank lines
ignored) from any of: string, bytes/bytearray, list/tuple, or file-like
object. It replaces four private/inline copies that existed in dhcp.py and
various test helpers.

deep_merge() returns a new dict with override merged into base recursively
(last-writer wins for scalars, recursive merge for nested dicts). It replaces
the private _deep_merge() in cc_landscape.py. Unlike mergemanydict(), it uses
no merger plugins and never mutates its inputs.

Both functions are tested with comprehensive unit tests in TestParseKeyValue
and TestDeepMerge.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
…value

dhcp.py had a private _parse_key_value(). Four test files each had their own
inline key=value parser or a private helper doing the same thing. All are now
replaced with calls to util.parse_key_value(), removing ~60 lines of
duplicated logic across the codebase.

test_cc_mcollective: thin _parse_mcollective_config wrapper now delegates to
util.parse_key_value and util.load_text_file instead of re-implementing
parsing.

test_cc_set_hostname: conf_parser is now a direct alias for util.parse_key_value.

test_cc_timezone, test_cc_locale: inline loops replaced with single-line
util.parse_key_value() calls.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
Replace the module-private _deep_merge() with util.deep_merge(). The new
util function returns a fresh dict rather than mutating in place, so
merge_together() is updated to use the return value instead of passing base
by reference. This also removes the need to import copy, since deep_merge
never mutates its inputs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant