Skip to content

Add INI filetype support - #120

Merged
ESultanik merged 1 commit into
trailofbits:add-ini-filetypefrom
0xTaoZ:0xTaoZ/add-ini-filetype
Sep 8, 2026
Merged

ESultanik merged 1 commit into
trailofbits:add-ini-filetypefrom
0xTaoZ:0xTaoZ/add-ini-filetype

Conversation

@0xTaoZ

@0xTaoZ 0xTaoZ commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #49.

This adds first-class INI support using Python's standard configparser module. INI files are represented as section dictionaries with string option values, which lets Graphtage parse, diff, and format .ini files without adding a new dependency.

Changes:

  • add an ini filetype with parser and formatter support
  • register .ini MIME detection for CLI use
  • include INI in the package filetype registry
  • add randomized INI round-trip formatting coverage

Local 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.py
  • git diff --check
  • manual CLI smoke test diffing two .ini files

Note: 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.

Signed-off-by: Haitao Zheng <[email protected]>
@0xTaoZ
0xTaoZ requested a review from ESultanik as a code owner July 2, 2026 12:56
@CLAassistant

CLAassistant commented Jul 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@ESultanik
ESultanik changed the base branch from master to add-ini-filetype September 8, 2026 16:49

@ESultanik ESultanik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread graphtage/ini.py

import configparser
import os
from typing import ClassVar, Optional, Type, Union

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from typing import ClassVar, Optional, Type, Union
from typing import ClassVar, List, Optional, Type, Union

Comment thread graphtage/ini.py

class INIFormatter(GraphtageFormatter):
"""A formatter for INI files."""
sub_format_types: ClassVar[list[Type[GraphtageFormatter]]] = [INIStringFormatter]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Comment thread graphtage/ini.py
printer.write("]")
printer.newline()
for item in section.value:
self.print(printer, item)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ESultanik
ESultanik merged commit 0ced9c9 into trailofbits:add-ini-filetype Sep 8, 2026
1 check passed
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.

Add support for INI files

3 participants