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

Error reading template file #22

Closed
Epigee opened this issue Nov 7, 2024 · 13 comments · Fixed by #23 or #24
Closed

Error reading template file #22

Epigee opened this issue Nov 7, 2024 · 13 comments · Fixed by #23 or #24
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Epigee
Copy link

Epigee commented Nov 7, 2024

I'm not a python dev so this could be really simple - but when I pull this down and try to run it no changes i get the following error.

2024-11-07 11:47:47,649 - app - ERROR - Error reading template file: 'charmap' codec can't decode byte 0x90 in position 17317: character maps to

I just downloaded the latest python to try it (3.13.0 - perhaps this is too new?).

@rtuszik
Copy link
Owner

rtuszik commented Nov 7, 2024

Can you check if the yaml file is encoded as UTF-8?
Seems like there is a character in the yaml file that doesn't play well.

Could you provide the yaml file?

@Epigee
Copy link
Author

Epigee commented Nov 7, 2024

I simply copy and pasted in from the example so i could understand it better. VSCode says its UTF-8 in the bottom right and i trust it.

Note - the error (when i attempted to debug it) appears to be coming from this line

template = Template(file.read())

in the template_renderer.py class (again not a py dev)

Below is a copy paste of my yaml from the example.

title: "KoalaKeys"
RenderKeys: true # defaults to true
AllowText: false # defaults to false - requires RenderKeys: false
layout:
  keyboard: US
  system: Darwin
shortcuts:
  General:
    "CMD+C":
      description: "Copy selected item"
    "CMD+X":
      description: "Cut selected item"
  File and App Management:
    "CMD+N":
      description: "Open new window or document"
    "CMD+O":
      description: "Open selected item or display dialog to choose file to open"

@rtuszik
Copy link
Owner

rtuszik commented Nov 7, 2024

Interesting. Can you try one of the other yaml files from the collection?

I'll be pushing an update this week that will improve the way the yaml files are read among other things.

I'll see if I can replicate this once im back at home.

@rtuszik rtuszik added the bug Something isn't working label Nov 7, 2024
@rtuszik rtuszik self-assigned this Nov 7, 2024
@Epigee
Copy link
Author

Epigee commented Nov 7, 2024

Im afraid I only see end products on the link you provided. I see only html files and no yaml files - apologies if I am misunderstanding!

@rtuszik
Copy link
Owner

rtuszik commented Nov 7, 2024

You are entirely correct. My bad. I need to update that repo.

Here is one: https://github.com/rtuszik/KoalaKeys/blob/a6a2eb3e768f904eebf8bf202db20cb8819904c0/cheatsheets/ipad.yaml

@Epigee
Copy link
Author

Epigee commented Nov 7, 2024

Same error with that one - I don't believe the code is getting to the point where its reading the yaml files. I believe the copy of the cheatsheet_template.html contains some character that the newest version of the requirements.txt or python is unable to parse. (this is my guess).

2024-11-07 12:32:46,799 - app - ERROR - Error reading template file: 'charmap' codec can't decode byte 0x90 in position 17317: character maps to

@rtuszik
Copy link
Owner

rtuszik commented Nov 8, 2024

I haven't been able to reproduce the issue, but I have streamlined some of the logic with regards to opening yaml. Could you try again using the yaml branch? https://github.com/rtuszik/KoalaKeys/tree/yaml

@Epigee
Copy link
Author

Epigee commented Nov 8, 2024

This is the result - no output.

  File "C:\Users\zmanj\Documents\GitHub\KoalaKeys\src\generate_cheatsheet.py", line 216, in <module>
    title, filename = main(yaml_file)
                      ~~~~^^^^^^^^^^^
  File "C:\Users\zmanj\Documents\GitHub\KoalaKeys\src\generate_cheatsheet.py", line 184, in main
    if not write_html_content(html_output, html_content):
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\zmanj\Documents\GitHub\KoalaKeys\src\generate_cheatsheet.py", line 158, in write_html_content
    file.write(html_content)
    ~~~~~~~~~~^^^^^^^^^^^^^^
  File "C:\Users\zmanj\AppData\Local\Programs\Python\Python313\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\u25d0' in position 14938: character maps to <undefined>

@rtuszik
Copy link
Owner

rtuszik commented Nov 8, 2024

Im pretty sure I have found the issue. I don't specify UTF-8 encoding when writing to html. I assume that this is an issue with windows not defaulting to UTF-8. Windows uses cp1252 encoding.

I will fix this once I am at my desk in a few hours.

@rtuszik rtuszik linked a pull request Nov 8, 2024 that will close this issue
@Epigee
Copy link
Author

Epigee commented Nov 8, 2024

Great!
I use a ZSA moonlander keyboard with global hotkeys for obsidian, ticktick, and my own apps. I'm excited to catalog them in one space!

@rtuszik
Copy link
Owner

rtuszik commented Nov 8, 2024

Sweet, I haven't made the move to a split keyboard yet, but im sure I will soon.

Could you try again with the latest pushes to the yaml branch? I don't have any windows systems to test on.

@Epigee
Copy link
Author

Epigee commented Nov 8, 2024

Woo success

2024-11-08 17:28:10,013 - app - INFO - YAML validation successful: C:\Users\zmanj\Documents\GitHub\KoalaKeys\cheatsheets\example-cheatsheet.yaml
2024-11-08 17:28:10,043 - app - INFO - Cheatsheet generated: C:\Users\zmanj\Documents\GitHub\KoalaKeys\output\koalakeys_cheatsheet.html
2024-11-08 17:28:10,057 - app - INFO - Index page generated: C:\Users\zmanj\Documents\GitHub\KoalaKeys\output\index.html
Generated cheatsheets for 1 YAML files.

I also highly recommend a programable one! Here's a look at my customizations https://configure.zsa.io/moonlander/layouts/3aD3w/latest/0

Thanks for the fix - happy to be a windows tester.

@rtuszik
Copy link
Owner

rtuszik commented Nov 8, 2024

Awesome! Thanks for opening the issue. If you have any feature requests or any more issues let me know.

I'll make sure to remember in case there are more Windows issues!

@rtuszik rtuszik closed this as completed Nov 8, 2024
@rtuszik rtuszik mentioned this issue Nov 8, 2024
@rtuszik rtuszik added this to the v0.5.0 milestone Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants