create iniparser in python #1

Open
opened 2026-05-05 19:51:47 +00:00 by thabeta · 4 comments
Owner
No description provided.
Author
Owner

Implementation Spec for Issue #1

Objective

Create a Python package named inipy that parses .ini configuration files, supporting sections, key-value pairs, and comments.


Requirements

  • Parse .ini files and return a structured dictionary-like object
  • Support sections (e.g., [SectionName])
  • Support key=value pairs (including strings, integers, booleans)
  • Support comments with # and ; prefixes
  • Handle empty lines gracefully (ignore them)
  • Provide a write/export function to serialize data back to .ini format
  • Include error handling for malformed lines
  • Package as a standard Python library with pyproject.toml
  • Include unit tests using pytest

Files to Create

File Description
pyproject.toml Package metadata, build config, dependencies (pytest)
src/inipy/__init__.py Package entry point, expose public API
src/inipy/parser.py Core INI parsing logic (class-based)
src/inipy/exceptions.py Custom exception classes
tests/test_parser.py Unit tests for parser
README.md Basic documentation

Step-by-Step Implementation Plan

Step 1 — Initialize package structure: pyproject.toml with src layout

Step 2 — Define exceptions: src/inipy/exceptions.py with IniParseError

Step 3 — Implement core parser: IniParser class in src/inipy/parser.py with parse(), loads(), dumps()

Step 4 — Expose public API: src/inipy/__init__.py exports

Step 5 — Write tests: tests/test_parser.py with pytest

Step 6 — Create README: usage documentation


Acceptance Criteria

  • pyproject.toml exists with valid metadata and pytest dependency
  • IniParser class parses a valid .ini file into a Python dict
  • Sections, key-value pairs, and comments are handled correctly
  • loads() parses INI from a string
  • dumps() serializes dict back to valid INI string
  • IniParseError is raised for malformed lines
  • Tests in tests/test_parser.py pass with pytest
  • Package is installable via pip install -e .

Notes

  • Python 3.9+ target
  • v1 is minimal — no nested sections, no interpolation
  • All work happens on the current branch (no new branch, no PR)
## Implementation Spec for Issue #1 ### Objective Create a Python package named `inipy` that parses `.ini` configuration files, supporting sections, key-value pairs, and comments. --- ### Requirements - Parse `.ini` files and return a structured dictionary-like object - Support **sections** (e.g., `[SectionName]`) - Support **key=value pairs** (including strings, integers, booleans) - Support **comments** with `#` and `;` prefixes - Handle **empty lines** gracefully (ignore them) - Provide a **write/export** function to serialize data back to `.ini` format - Include **error handling** for malformed lines - Package as a standard Python library with `pyproject.toml` - Include **unit tests** using `pytest` --- ### Files to Create | File | Description | |------|-------------| | `pyproject.toml` | Package metadata, build config, dependencies (pytest) | | `src/inipy/__init__.py` | Package entry point, expose public API | | `src/inipy/parser.py` | Core INI parsing logic (class-based) | | `src/inipy/exceptions.py` | Custom exception classes | | `tests/test_parser.py` | Unit tests for parser | | `README.md` | Basic documentation | --- ### Step-by-Step Implementation Plan **Step 1** — Initialize package structure: `pyproject.toml` with src layout **Step 2** — Define exceptions: `src/inipy/exceptions.py` with `IniParseError` **Step 3** — Implement core parser: `IniParser` class in `src/inipy/parser.py` with `parse()`, `loads()`, `dumps()` **Step 4** — Expose public API: `src/inipy/__init__.py` exports **Step 5** — Write tests: `tests/test_parser.py` with pytest **Step 6** — Create README: usage documentation --- ### Acceptance Criteria - [ ] `pyproject.toml` exists with valid metadata and pytest dependency - [ ] `IniParser` class parses a valid `.ini` file into a Python dict - [ ] Sections, key-value pairs, and comments are handled correctly - [ ] `loads()` parses INI from a string - [ ] `dumps()` serializes dict back to valid INI string - [ ] `IniParseError` is raised for malformed lines - [ ] Tests in `tests/test_parser.py` pass with `pytest` - [ ] Package is installable via `pip install -e .` --- ### Notes - Python 3.9+ target - v1 is minimal — no nested sections, no interpolation - All work happens on the current branch (no new branch, no PR)
Author
Owner

Spec confirmed from existing comment. Implementation:

  • src/inipy/__init__.py — package init with IniParser and IniParseError exports
  • src/inipy/parser.pyIniParser class: parse(), loads(), dumps(), _cast(), with regex-based line parsing (section headers [section], key-value key = value, comments #/;, blank lines)
  • src/inipy/exceptions.pyIniParseError with lineno and line attributes
  • pyproject.toml — setuptools build, Python >=3.9, pytest dev dep
  • tests/test_parser.py — 13 unit tests covering parsing, sections, comments, casting, round-trip, error handling

Tests: 13 passed. Package installable.

Work is on the current branch (cloned from the empty repo). No additional spec comment needed — the existing comment #29705 already documents the plan.

Spec confirmed from existing comment. Implementation: - `src/inipy/__init__.py` — package init with `IniParser` and `IniParseError` exports - `src/inipy/parser.py` — `IniParser` class: `parse()`, `loads()`, `dumps()`, `_cast()`, with regex-based line parsing (section headers `[section]`, key-value `key = value`, comments `#`/`;`, blank lines) - `src/inipy/exceptions.py` — `IniParseError` with `lineno` and `line` attributes - `pyproject.toml` — setuptools build, Python >=3.9, pytest dev dep - `tests/test_parser.py` — 13 unit tests covering parsing, sections, comments, casting, round-trip, error handling Tests: 13 passed. Package installable. Work is on the current branch (cloned from the empty repo). No additional spec comment needed — the existing comment #29705 already documents the plan.
Author
Owner

Test results: 13 passed, 0 failed.

tests/test_parser.py::test_parse_key_value PASSED
tests/test_parser.py::test_parse_with_section PASSED
tests/test_parser.py::test_multiple_sections PASSED
tests/test_parser.py::test_comments_hash PASSED
tests/test_parser.py::test_comments_semicolon PASSED
tests/test_parser.py::test_blank_lines_ignored PASSED
tests/test_parser.py::test_bool_casting PASSED
tests/test_parser.py::test_int_casting PASSED
tests/test_parser.py::test_string_preserved PASSED
tests/test_parser.py::test_dumps_basic PASSED
tests/test_parser.py::test_dumps_roundtrip PASSED
tests/test_parser.py::test_parse_file PASSED
tests/test_parser.py::test_malformed_line_raises PASSED
============================== 13 passed in 0.03s

All acceptance criteria met. Implementation complete.

Test results: 13 passed, 0 failed. ``` tests/test_parser.py::test_parse_key_value PASSED tests/test_parser.py::test_parse_with_section PASSED tests/test_parser.py::test_multiple_sections PASSED tests/test_parser.py::test_comments_hash PASSED tests/test_parser.py::test_comments_semicolon PASSED tests/test_parser.py::test_blank_lines_ignored PASSED tests/test_parser.py::test_bool_casting PASSED tests/test_parser.py::test_int_casting PASSED tests/test_parser.py::test_string_preserved PASSED tests/test_parser.py::test_dumps_basic PASSED tests/test_parser.py::test_dumps_roundtrip PASSED tests/test_parser.py::test_parse_file PASSED tests/test_parser.py::test_malformed_line_raises PASSED ============================== 13 passed in 0.03s ``` All acceptance criteria met. Implementation complete.
Author
Owner

Implementation complete for issue #1 — create iniparser in python.

Summary:

  • Package inipy created with IniParser class supporting parse(), loads(), dumps()
  • Handles sections, key-value pairs, comments (#/;), blank lines
  • Automatic type casting: bools (true/false), integers, strings
  • Custom IniParseError exception with line/lineno
  • 13 unit tests, all passing

Files:

  • pyproject.toml — setuptools build, Python >=3.9
  • src/inipy/__init__.py, parser.py, exceptions.py
  • tests/test_parser.py
  • README.md

Install: uv pip install -e .
Test: pytest tests/

Implementation complete for issue #1 — create iniparser in python. **Summary:** - Package `inipy` created with `IniParser` class supporting `parse()`, `loads()`, `dumps()` - Handles sections, key-value pairs, comments (`#`/`;`), blank lines - Automatic type casting: bools (`true`/`false`), integers, strings - Custom `IniParseError` exception with line/lineno - 13 unit tests, all passing **Files:** - `pyproject.toml` — setuptools build, Python >=3.9 - `src/inipy/__init__.py`, `parser.py`, `exceptions.py` - `tests/test_parser.py` - `README.md` **Install:** `uv pip install -e .` **Test:** `pytest tests/`
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
thabeta/inipy#1
No description provided.