migration_helpers
The community/migration_helpers directory is designed to handle the transition of user configuration and data files from legacy CSV formats to the newer, native .talon-list format. This modernization improves Talon's performance and parsing reliability.
CSV to Talon List Migration
The logic for this process is self-contained in migration_helpers.py.
How it Works
The conversion pipeline automatically detects old configuration CSVs, translates their content, writes the new .talon-list files, and renames the legacy files to prevent redundant runs while preserving them as backups.
The system is built around several key components:
CSVDataConfiguration Tracker: A dataclass that maps each target CSV file to its expected output.talon-listpath. It maintains properties such as:- Whether the first line is a header.
- Whether the spoken form or value appears first in the CSV.
-
Custom hooks for processing values or adding dynamic headers (e.g., appending the local hostname to system paths).
-
Built-in Migrations: The helper is pre-configured with a list of core community CSV configurations to migrate, including:
- Git arguments and commands (
git_arguments.csv,git_commands.csv) - Vocabulary additions (
additional_words.csv) - Key alphabet mappings (
alphabet.csv) - System paths, search engines, unix utilities, and websites
-
Emojis, emoticons, and kaomojis
-
Format Translation (
convert_csv_to_talonlist): This function parses a 1- or 2-column CSV file into the standard Talon list structure: - It skips empty lines, whitespace-only rows, and comments (starting with
#). - It maps the columns to
spoken_form: valuesyntax. -
It automatically handles string representation formatting (using
repr) if values contain quotes or non-printable characters, ensuring syntactically valid.talon-listoutputs. -
File Operations and Safety (
convert_files): To prevent data loss: - If a target
.talon-listfile already exists, it is backed up with a.baksuffix. - After a successful migration, the original CSV is renamed to
.csv-converted-to-talon-listinstead of being deleted immediately, allowing you to verify the migration manually.
Startup Execution and Actions
The script integrates directly into Talon's lifecycle and action system:
- Automatic Migration: On startup,
app.register("ready", on_ready)attempts to run the migrations automatically. If Talon's core loader encounters a known timing issue where the action isn't fully registered at boot, a notification is displayed prompting you to restart. - Declarative Actions: The module exposes two Talon actions:
user.migrate_known_csv_files(): Triggers the standard migration pipeline.user.migrate_custom_csv(...): Allows you to programmatically trigger migrations for custom, user-defined CSV structures outside of the default community set.