Skip to content

xhc-hb04: rename dashed ini identifiers, migrate old configs in update_ini - #4601

Open
grandixximo wants to merge 2 commits into
LinuxCNC:masterfrom
grandixximo:ini-strict-identifiers
Open

grandixximo wants to merge 2 commits into
LinuxCNC:masterfrom
grandixximo:ini-strict-identifiers

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

The new ini parser restricts identifiers to letters, digits and underscore. The historic parser had no character restrictions, so the xhc-hb04 pendant files used dashes and no longer parse: the [XHC_HB04_BUTTONS] keys in the sample configs (start-pause, goto-zero, ...) and the [XHC-HB04] section of the pendant's own layout cfg files, which the component parses with the same IniFile class.

Per the 2026-09-27 dev meeting (conclusion in #4566), the strict identifier rule stays and the in-tree files and code are updated instead. This replaces the accept-the-dash approach of #4573.

First commit renames the dashed identifiers to underscores:

  • [XHC-HB04] => [XHC_HB04] in the component's hardcoded section name, the shipped layout cfg files and the docs
  • the button keys in the three sample config includes (start-pause => start_pause, goto-zero => goto_zero, ...)
  • xhc-hb04.tcl maps the underscored INI button names back to the dashed HAL pin names (xhc-hb04.button-start-pause etc.), which are unchanged, so existing user HAL files referencing the pins keep working

Second commit adds the migration for existing user configs. A dashed file can not be parsed at all, and the launcher exits on the inivalue parse check before the [EMC]VERSION check that invokes update_ini, so the version-triggered path never fires. Instead update_ini gets a content-triggered text pass that runs before parsing: dashed (but otherwise valid) section and tag identifiers are rewritten with underscores in the ini file, its #INCLUDE'd files and a custom layout cfg found via a loose scan of [XHC_HB04_CONFIG]layout. Every modified file keeps a .bak copy and every rename is listed. The launcher runs this as update_ini --fix-identifiers when the parse check fails and retries afterwards, so old pendant configs migrate themselves on first boot. Identifiers that are invalid even without the dash (leading dash or digit) are left alone and fail with the original error. No THIS_VERSION bump.

One limitation: HAL files referencing [XHC_HB04_BUTTONS]start-pause through halcmd ini substitution are not rewritten. The xhc-hb04.tcl mechanism does not use such references, so this only affects hand-written HAL files.

Behavior note: the migration rewrites the user's config files on first boot without asking for confirmation. The renames are listed on stdout and a .bak copy is kept for every modified file, but a GUI user starting from a menu may never see that output. The version-based conversion path, in contrast, asks with a confirmation dialog and refuses to run without an X display. I kept the identifier fix automatic because the config does not start at all without it, the change is small and reversible, and the meeting asked for an automated update. @BsAtHome: do you want a confirmation dialog here when a display is available, like the version-based conversion has?

Testing: new tests/update_ini/dash-identifiers (ini file + included file + custom cfg + .bak + invalid identifiers), the inivalue test gains plain dash-rejection cases, full inifile suite passes 11/11. All four xhc-hb04 sample configs boot with the pendant pins and button nets present (including the std_start_pause path), and a config reverted to the old dashed form boots through the launcher and migrates itself.

The new ini parser restricts section and tag identifiers to letters, digits and underscore, not starting with a digit. The historic parser had no identifier character restrictions, so the xhc-hb04 pendant files used dashes freely and no longer parse:

- the [XHC_HB04_BUTTONS] keys in the sample configs (start-pause, goto-zero, ...)
- the [XHC-HB04] section of the pendant's own layout cfg files, which the component parses with the same IniFile class, making it exit at startup

Rename the identifiers to use underscores: the INI button keys in the sample configs, the [XHC_HB04] section in the shipped layout cfg files and in the component's hardcoded section name, plus documentation.

The HAL pin names are unchanged and keep their dashes (xhc-hb04.button-start-pause). The xhc-hb04.tcl script maps the underscored INI button names back to the dashed pin names, so existing user HAL files that reference the pins keep working.
Comment thread scripts/linuxcnc.in
@grandixximo
grandixximo force-pushed the ini-strict-identifiers branch 2 times, most recently from 0ac0834 to b70f9ee Compare September 28, 2026 13:58
Comment thread src/emc/ini/update_ini.py
@grandixximo
grandixximo force-pushed the ini-strict-identifiers branch from b70f9ee to b1e6487 Compare September 30, 2026 16:02
Comment thread src/emc/ini/update_ini.py Outdated
Configs using dashed identifiers (old xhc-hb04 pendant setups) can not be parsed at all any more, so the version-triggered update path never gets a chance to run: the launcher exits on the inivalue parse check before reaching the [EMC]VERSION check that invokes update_ini.

Add a text pass to update_ini that runs before parsing and independent of [EMC]VERSION: section and tag identifiers containing dashes (but otherwise valid) are rewritten with underscores in the ini file, in its #INCLUDE'd files and in a custom xhc-hb04 layout cfg found via a loose scan of [XHC_HB04_CONFIG]layout. Every modified file keeps a .bak copy and every rename is listed. The pass is available standalone as update_ini --fix-identifiers.

The launcher runs this mode when the inivalue parse check fails and retries parsing afterwards, so old pendant configs migrate themselves on first boot. Identifiers that are invalid even without the dash (leading dash or digit) are left alone and still fail with the original error.

Add a tests/update_ini/dash-identifiers test covering the ini file, an included file, a custom layout cfg, the .bak copies and the invalid-identifier cases, and extend the inivalue test with plain dash-rejection cases.
@grandixximo
grandixximo force-pushed the ini-strict-identifiers branch from b1e6487 to 2200eef Compare October 1, 2026 02:07
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.

2 participants