Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

porting the .csv files to .talon-list files #1268

Merged
merged 73 commits into from
Sep 1, 2024
Merged

Conversation

saidelike
Copy link
Contributor

The goal of this PR is to:

  • remove code to generate the .csv files
  • include the default .talon-list files
  • port code in .python files to use the new .talon-list instead of the .csv

This initial commit is about porting {user.letter}: alphabet.csv -> letter.talon-list

It includes a .tools/convert_all_csv_files_to_talon-list.py file in a hidden directory so it is not picked up by talon. Running this script gives something like:

C:\Users\User\AppData\Roaming\talon\user\community\.tools> python convert_all_csv_files_to_talon-list.py
Base directory: C:\Users\User\AppData\Roaming\talon\user\community
Skipping unsuppported convertion yet: apps\emacs\emacs_commands.csv
Skipping unsuppported convertion yet: apps\git\git_arguments.csv
Skipping unsuppported convertion yet: apps\git\git_commands.csv
Skipping unsuppported convertion yet: core\app_switcher\app_name_overrides.linux.csv
Skipping unsuppported convertion yet: core\app_switcher\app_name_overrides.mac.csv
Skipping unsuppported convertion yet: core\app_switcher\app_name_overrides.windows.csv
Skipping unsuppported convertion yet: core\homophones\homophones.csv
Skipping unsuppported convertion yet: settings\abbreviations.csv
Skipping unsuppported convertion yet: settings\additional_words.csv
Converting csv file: settings\alphabet.csv -> talon-list file: core\keys\letter.talon-list
Skipping non default csv file settings\bla.csv
Skipping unsuppported convertion yet: settings\file_extensions.csv
Skipping unsuppported convertion yet: settings\search_engines.csv
Skipping unsuppported convertion yet: settings\system_paths.csv
Skipping unsuppported convertion yet: settings\unix_utilities.csv
Skipping unsuppported convertion yet: settings\websites.csv
Skipping unsuppported convertion yet: settings\words_to_replace.csv
Skipping unsuppported convertion yet: tags\emoji\emoji.csv
Skipping unsuppported convertion yet: tags\emoji\emoticon.csv
Skipping unsuppported convertion yet: tags\emoji\kaomoji.csv

This script retrieves all the .csv files from the community/ folder and try to convert them to .talon-list files. It only support converting those that are default on knausj using a whitelist. Atm, only alphabet.csv is implemented and the others are skipped on purpose. Also, a non default bla.csv was created in settings in my local folder in order to show it is skipped.

I am aware that some other PR exist (#1239 and #1240) but the idea of this new PR is to distinguish talon-list changes to make them more likely to be merged sooner than later. And also provide a script that people can run in order to upgrade their own csv if they have modified them.

Later, this script could support porting non default csv files but the users will still need to update their code accordingly to support the new talon-list files so we can't automate it.

I am mainly interested in feedbacks before we port the other .csv files to .talon-list files.

@nriley
Copy link
Collaborator

nriley commented Oct 14, 2023

Some thoughts from the grooming session today:

  • This requires the user have a non-Talon version of python installed. For many less technical users this will not be the case. It might make sense to turn this into a Talon action the way core Talon did when we migrated action definitions out of .talon files.

  • For users who have customized their non-settings CSV files, we need to have a reasonable migration path. One possible option might be:

    1. Convert all of the standard settings CSV files to .talon-list files.
    2. Add a comment to the beginning of every standard non-settings CSV file to encourage use of the action to convert your CSV customizations (and delete the corresponding CSV after conversion?)
    3. Display a warning (imgui?) if customized non-settings CSV files remain.

knausj85 and others added 3 commits January 21, 2024 21:50
- move logic to migration_helpers.py
- Auto-convert known and supported CSVs in on_ready
- initial example conversion of git_commands
@knausj85 knausj85 marked this pull request as draft January 22, 2024 03:52
@knausj85
Copy link
Member

knausj85 commented Jan 22, 2024

I took a swing at making progress on this.

Proposal:

  1. Autoconvert supported CSVs in OnReady + commit default .talon-lists. When the custom *.csv is processed, the existing logic overwrites the .talon-list in-place.
  2. Certain CSVs need to remain as CSVs as the format is either not a list or (2) it's utilized by create_spoken_forms: homophones, emacs_commands, app_name_overrides, abbreviations, file_extensions. I propose we use the new resource.watch functionality for these and keep them as-is.

If this seems reasonable to folks, this is what needs attention:

  • Need logic to correctly handle files like emoticon.csv and kaomoji.csv
  • Need to sort out what to do with system_paths. It's probably most robust to make this a host-specific conversion,
  • Could probably use some unit tests 😓
  • Need to update edit_text_file.py
  • Implement action for custom, non-standard CSV conversion?

tags/emoji/emoji.talon-list Show resolved Hide resolved
tags/emoji/emoticon.talon-list Outdated Show resolved Hide resolved
tags/emoji/kaomoji.talon-list Show resolved Hide resolved
knausj85 and others added 2 commits January 27, 2024 17:26
add is_first_line_header parameter to the config for each file
@knausj85 knausj85 marked this pull request as ready for review January 27, 2024 23:28
@knausj85
Copy link
Member

I'm pretty satisfied with this approach. Reopening for review.

I don't have time to really think through all the edge cases though, so there might be a handful of conversion issues. Perhaps some other folks can help out if motivated.

Could probably use some testing if folks have time.

Great work on the initial implementation @saidelike, btw!

Copy link
Collaborator

@pokey pokey left a comment

Choose a reason for hiding this comment

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

Looks good! I'd be happy to give this a spin before we hit the final merge button to make sure it works for me; I have a heavily custom fork so should be a good test case

Speaking of test cases, those would be nice to have, but seems difficult

core/keys/letter.talon-list Show resolved Hide resolved
core/system_paths.py Show resolved Hide resolved
migration_helpers/migration_helpers.py Outdated Show resolved Hide resolved
migration_helpers/migration_helpers.py Outdated Show resolved Hide resolved
migration_helpers/migration_helpers.py Outdated Show resolved Hide resolved
migration_helpers/migration_helpers.py Outdated Show resolved Hide resolved
migration_helpers/migration_helpers.py Show resolved Hide resolved
core/keys/letter.talon-list Outdated Show resolved Hide resolved
knausj85 and others added 3 commits February 4, 2024 10:08
- switch to using data class for supported files
- added missing conversions
@knausj85
Copy link
Member

  • What is this going to mean for the subset of users who "do not want to modify community"? The defaults for these files and any modifications will be tracked in Git by default, unlike the settings folder.

Ultimately, talon has evolved and the repo needs to evolve alongside. I ran the converter some months ago, and vastly prefer tracking these files in git:

  1. Consistency with .talon files. Gets us close to a point where one could "delete all talon and talon-list files" and build their own grammar
  2. Reduces mystery for newbs vs autogenerated CSVs
  3. When merging, one can focus on largely python-side changes and mostly ignore .talon-list

FWIW there was some discussion of this issue on
#1382 and
#1221 (comment)

TL,DR:
It's a good step forward: (1) provides us a potential mechanism for creating a more terse grammar in the future, and (2) we can't please everyone :). I think we commit and move on.

@nriley
Copy link
Collaborator

nriley commented Aug 31, 2024

Did a bunch of cleanup on the README. Ready for (hopefully) final review!

@nriley nriley marked this pull request as ready for review August 31, 2024 18:35
nriley added a commit to nriley/TalonWiki that referenced this pull request Aug 31, 2024
Copy link
Member

@knausj85 knausj85 left a comment

Choose a reason for hiding this comment

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

This looks good to me.

@nriley nriley merged commit 940fe69 into talonhub:main Sep 1, 2024
2 checks passed
@ekuiter
Copy link

ekuiter commented Sep 3, 2024

2024-09-03 08:37:49.116 DEBUG [+] /Users/ek/.talon/user/modules/community/migration_helpers/migration_helpers.py
2024-09-03 08:37:49.122 ERROR cb error topic="ready" cb=on_ready
   23:                                   lib/python3.11/threading.py:1002* # cron thread
   22:                                   lib/python3.11/threading.py:1045* 
   21:                                   lib/python3.11/threading.py:982 * 
   20:                                                 talon/cron.py:153 * 
   19:                                       talon/scripting/rctx.py:235 * # 'cron' main:Cron.interval.<locals>.call()
   18:                                                 talon/cron.py:181 * 
   17:                                                   talon/fs.py:62  * 
   16:                                                   talon/fs.py:58  * 
   15:                                       talon/scripting/rctx.py:235 * # 'fs' main:Loader.on_change()
   14:                                       app/resources/loader.py:751 * 
   13:                                       app/resources/loader.py:716 * 
   12:                                       app/resources/loader.py:425 * 
   11:                          lib/python3.11/importlib/__init__.py:126 * 
   10:                                       app/resources/loader.py:235 * 
    9: user/modules/community/migration_helpers/migration_helpers.py:261 | app.register("ready", on_ready)
    8:                                                  talon/app.py:23  | 
    7: ------------------------------------------------------------------# [stack splice]
    6:                                       talon/scripting/rctx.py:235 | # 'ready' user.modules.community.migration_helpers.migration_helpers:on_ready()
    5: user/modules/community/migration_helpers/migration_helpers.py:258 | actions.user.migrate_known_csv_files()
    4:                                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    3:                                    talon/scripting/actions.py:62  | 
    2:                                    talon/scripting/actions.py:156 | 
    1:                                    talon/scripting/actions.py:152 | 
KeyError: "Action 'user.migrate_known_csv_files' is not declared."

Is this migration of CSV files supposed to run automatically? If yes, it does not work on my machine. For now, I have to revert this pull request in my setup.

@nriley
Copy link
Collaborator

nriley commented Sep 3, 2024


2024-09-03 08:37:49.116 DEBUG [+] /Users/ek/.talon/user/modules/community/migration_helpers/migration_helpers.py

2024-09-03 08:37:49.122 ERROR cb error topic="ready" cb=on_ready

   23:                                   lib/python3.11/threading.py:1002* # cron thread

   22:                                   lib/python3.11/threading.py:1045* 

   21:                                   lib/python3.11/threading.py:982 * 

   20:                                                 talon/cron.py:153 * 

   19:                                       talon/scripting/rctx.py:235 * # 'cron' main:Cron.interval.<locals>.call()

   18:                                                 talon/cron.py:181 * 

   17:                                                   talon/fs.py:62  * 

   16:                                                   talon/fs.py:58  * 

   15:                                       talon/scripting/rctx.py:235 * # 'fs' main:Loader.on_change()

   14:                                       app/resources/loader.py:751 * 

   13:                                       app/resources/loader.py:716 * 

   12:                                       app/resources/loader.py:425 * 

   11:                          lib/python3.11/importlib/__init__.py:126 * 

   10:                                       app/resources/loader.py:235 * 

    9: user/modules/community/migration_helpers/migration_helpers.py:261 | app.register("ready", on_ready)

    8:                                                  talon/app.py:23  | 

    7: ------------------------------------------------------------------# [stack splice]

    6:                                       talon/scripting/rctx.py:235 | # 'ready' user.modules.community.migration_helpers.migration_helpers:on_ready()

    5: user/modules/community/migration_helpers/migration_helpers.py:258 | actions.user.migrate_known_csv_files()

    4:                                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    3:                                    talon/scripting/actions.py:62  | 

    2:                                    talon/scripting/actions.py:156 | 

    1:                                    talon/scripting/actions.py:152 | 

KeyError: "Action 'user.migrate_known_csv_files' is not declared."

Is this migration of CSV files supposed to run automatically? If yes, it does not work on my machine. For now, I have to revert this pull request in my setup.

I ran into this too. I think it's a core Talon bug not recognizing the action even though we call it from a ready callback. The conversion should run when Talon is restarted, but not sure if we should try to work around this from community.

@jaresty
Copy link
Contributor

jaresty commented Sep 3, 2024

I ran into this too and opted to manually migrate my alphabet though I'm not sure what other talon lists I may have missed. I wonder if it would be helpful to have a develop branch of the community repository where people could try out new features like this before they hit the main branch.

@nriley
Copy link
Collaborator

nriley commented Sep 3, 2024 via email

@jaresty
Copy link
Contributor

jaresty commented Sep 3, 2024

All good. For my part, I would gladly use a develop branch and provide feedback on it, which could intercept some issues before they hit main. I can't make it to the backlog sessions (unfortunately) and don't have time to check out each PR individually so any feedback I provide on those would be just based on reading them, not based on my actual experience using them (hence not quite as authoritative, IMO).

Besides being another hoop, a develop branch might free up merging PRs more easily since there would be another opportunity for feedback before merging to main. It also allows for PRs to be integrated and issues that come from integration to be discovered sooner. (that's how I've seen them used, anyhow)

@nriley
Copy link
Collaborator

nriley commented Sep 7, 2024

Some updates from discussion this week and in the community backlog session this morning:

  • ready is clearly firing too soon before the action is appropriately registered. According to aegis this is fixed for him, but there has not yet been a beta release incorporating this fix and it may be some time until the fix is in the public version of talon.
  • Instead of working around the bug we decided to simply display a notification if the bug occurs indicating that you should restart Talon. I filed Display message when encountering core Talon issue with ready callback. #1558 with this change.

@knausj85
Copy link
Member

knausj85 commented Sep 7, 2024

#1558 has been merged FYI

@ekuiter
Copy link

ekuiter commented Sep 7, 2024

thanks for investigating and taking care of this!

nriley added a commit to nriley/talon_community that referenced this pull request Sep 7, 2024
Use `hostname:` rather than `host:` to (correctly) match a hostname.

Generate a default `system_paths-<hostname>.talon-list` akin to the
prior CSV.

Also makes some minor tweaks to the generated spoken forms:

- only use "profile" for Windows; "home" for other platforms
- add "talon recordings" (because I want to use it in the wiki)
nriley added a commit to nriley/talon_community that referenced this pull request Sep 7, 2024
Use `hostname:` rather than `host:` to (correctly) match a hostname.

Generate a default `system_paths-<hostname>.talon-list` akin to the
prior CSV.

Also makes some minor tweaks to the generated spoken forms:

- only use "profile" for Windows; "home" for other platforms
- add "talon recordings" (because I want to use it in the wiki)
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.

9 participants