Skip to content

fix(cli): read kernel metadata and source files using UTF-8 in kernels_push#1093

Open
sridipbasu wants to merge 1 commit into
Kaggle:mainfrom
sridipbasu:fix/windows-utf8-kernels-push
Open

fix(cli): read kernel metadata and source files using UTF-8 in kernels_push#1093
sridipbasu wants to merge 1 commit into
Kaggle:mainfrom
sridipbasu:fix/windows-utf8-kernels-push

Conversation

@sridipbasu

Copy link
Copy Markdown
Contributor

Summary

This PR updates kernels_push() to explicitly read the kernel metadata and source files using UTF-8 instead of relying on the platform's default encoding.

Problem

On Windows systems where the default text encoding is not UTF-8, running:

kaggle kernels push -p .

can fail with an error similar to:

'charmap' codec can't decode byte 0x81...

This happens because kernel-metadata.json and the kernel source file are opened without specifying an encoding. If either file contains Unicode characters (for example emojis, accented characters, or non-English text), reading the file may fail depending on the system's default encoding.

Solution

This PR adds encoding="utf-8" to the two file reads in kernels_push():

  • kernel-metadata.json
  • Kernel source file (.py, .ipynb, etc.)

This makes file reading consistent across platforms while preserving the existing behavior.

Tests

Added a regression test that:

  • Creates a temporary kernel directory.
  • Writes UTF-8 encoded metadata and source files containing Unicode characters.
  • Verifies that kernels_push() reads them successfully.
  • Confirms the test fails with the original implementation and passes with this change.

Why this change is safe

  • JSON metadata files are expected to be UTF-8.
  • Python source files and Jupyter notebooks are also expected to use UTF-8.
  • The change only affects two open() calls inside kernels_push().
  • No other commands or file operations are modified.

@stevemessick

Copy link
Copy Markdown
Contributor

/gcbrun

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