Repository navigation
Add INI filetype support - #120
Merged
ESultanik merged 1 commit intoSep 8, 2026
Merged
Conversation
Signed-off-by: Haitao Zheng <[email protected]>
ESultanik
approved these changes
Sep 8, 2026
ESultanik
left a comment
Collaborator
There was a problem hiding this comment.
I started with a review, but part way through I realized that recent changes to master have caused conflicts that we'll need to work around. I am going to merge your changes into an upstream branch and make the necessary updates there.
|
|
||
| import configparser | ||
| import os | ||
| from typing import ClassVar, Optional, Type, Union |
Collaborator
There was a problem hiding this comment.
Suggested change
| from typing import ClassVar, Optional, Type, Union | |
| from typing import ClassVar, List, Optional, Type, Union |
|
|
||
| class INIFormatter(GraphtageFormatter): | ||
| """A formatter for INI files.""" | ||
| sub_format_types: ClassVar[list[Type[GraphtageFormatter]]] = [INIStringFormatter] |
Collaborator
There was a problem hiding this comment.
list[] requires Python 3.9, and we are still supporting Python 3.8 (although we'll likely be dropping support in the next release or two).
Suggested change
| sub_format_types: ClassVar[list[Type[GraphtageFormatter]]] = [INIStringFormatter] | |
| sub_format_types: ClassVar[List[Type[GraphtageFormatter]]] = [INIStringFormatter] |
| printer.write("]") | ||
| printer.newline() | ||
| for item in section.value: | ||
| self.print(printer, item) |
Collaborator
There was a problem hiding this comment.
This should really use SequenceFormatter.print_SequenceNode to properly print edited nodes. See graphtage/json.py:142, graphtage/yaml.py:96, and TOMLMapping in graphtage/toml.py for examples.
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.
Fixes #49.
This adds first-class INI support using Python's standard
configparsermodule. INI files are represented as section dictionaries with string option values, which lets Graphtage parse, diff, and format.inifiles without adding a new dependency.Changes:
inifiletype with parser and formatter support.iniMIME detection for CLI useLocal validation:
.venv/bin/python -m pytest test/test_formatting.py -q.venv/bin/python -m ruff check graphtage/ini.py.venv/bin/python -m py_compile graphtage/ini.py graphtage/__init__.py graphtage/__main__.py test/test_formatting.pygit diff --check.inifilesNote: full changed-file Ruff checking reports existing lint issues in files that already predate this change, so I scoped Ruff to the new module and used targeted tests for the touched behavior.