Skip to content

Configurable Columns Enhancements Design Spec (Refactored & Unified) #2

Closed

Description

@falbany

Configurable Columns Enhancements Design Spec (Refactored & Unified)

Date: 2026-08-07
Topic: Configurable Columns Enhancements (Unified match + transform with Group Reference Support, Stretch Control, and Friendly Header Names)


1. Overview & Goals

This specification details the final refactored design for ProFiles dynamic column extraction and rendering. The goals are:

  1. Intuitive Matching (match): Unify built-in macros and custom regexes under a single, clear property (match: version or match: "custom_regex").
  2. Unified Group & Transform (transform): Replace separate group properties with standard regex backreferences (\1, \2, etc.) inside transform. If transform is omitted, it defaults to returning group 1 (or group 0).
  3. Stretch Control (stretch): Support per-column resizing behavior in the Tkinter Treeview (stretch: true or stretch: false).
  4. Friendly Column Names (name): Separate internal identifiers from user-facing UI column header labels.

2. Configuration Schema & Data Models

2.1. Refactored Pydantic Model (ColumnMapping / ColumnConfiguration)

class ColumnMapping(BaseModel):
    name: str | None = None          # User-friendly header display name
    width: int = 150
    stretch: bool = False            # Tkinter treeview stretch behavior
    match: str = ".*"                # Built-in keyword (e.g. "version", "date") or raw regex
    transform: str | None = None     # Optional replacement pattern with group backreferences (e.g. "\\1 (Build \\2)")
    priority: int = 0                # Processing priority
    default: str = ""                # Default value on non-match

2.2. Example .profiles YAML Configuration

columns:
  File:
    width: 600
    stretch: true
    match: ".*"
    priority: 100

  Version:
    name: "Version Number"
    width: 120
    stretch: false
    match: version               # Uses built-in version regex macro
    transform: "Ver. \\1"        # Prepends "Ver. " to captured group 1
    priority: 20

  ProjectBuild:
    name: "Project & Build"
    width: 160
    stretch: false
    match: "Project_([A-Z0-9]+)_Build_(\\d+)"
    transform: "\\1 (Build \\2)" # Combines multiple groups into a single formatted string
    priority: 15

3. Core Processing Architecture

3.1. Unified Match & Transform Engine (ColumnRule / ColumnExtractor)

When a match occurs:

  • If transform is specified, we use Python's match.expand(transform) which natively supports group backreferences (\1, \g<1>, etc.).
  • If transform is NOT specified, we default to returning match.group(1) if group 1 exists, else match.group(0).
BUILTIN_PATTERNS = {
    "version": r"[-_]V(\d+(?:\.\d+)*)(?=[^\\/]*\.[a-zA-Z0-9]+$)",
    "date": r"(\d{4}[-_]\d{2}[-_]\d{2}|\d{8})",
    "git_commit": r"_g([a-f0-9]{7})",
    "type": r"(PRO|ENG|DEV|TMP|DEBUG)(?!.*(?:PRO|ENG|DEV|TMP|DEBUG))",
    "filename": r"([^/\\\\]+)$",
    "extension": r"\.([^./\\\\]+)$",
}

def extract(self, filename: str) -> str:
    pattern = BUILTIN_PATTERNS.get(self.match.lower(), self.match)
    compiled = re.compile(pattern, re.IGNORECASE)
    match = compiled.search(filename)
    if not match:
        return self.default
    
    try:
        if self.transform:
            return match.expand(self.transform)
        else:
            # Default fallback: group 1 if available, else group 0
            return match.group(1) if match.lastindex and match.lastindex >= 1 else match.group(0)
    except Exception:
        return self.default

4. GUI & Treeview Integration

  • column_names: Internal dictionary keys (e.g. ("File", "Version", "ProjectBuild")).
  • column_headers: Display names mapped from name (falling back to key).
  • column_stretches: Tuple of booleans mapped from stretch passed into ttk.Treeview.column(..., stretch=...).

5. Testing & Verification

  1. Unit tests for built-in macro resolution via match.
  2. Unit tests for multi-group backreference formatting in transform.
  3. Configuration validation and GUI integration tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions