Skip to content

fix(jobs): write and read job.json as UTF-8 - #137

Open
nefayran wants to merge 1 commit into
huggingface:mainfrom
nefayran:fix/job-json-utf8
Open

nefayran wants to merge 1 commit into
huggingface:mainfrom
nefayran:fix/job-json-utf8

Conversation

@nefayran

Copy link
Copy Markdown

Fixes #131.

register_imported() names a model Imported 路 <label> when no name is given, and _write_meta() wrote job.json in the platform's default encoding. On Japanese Windows that is CP932, which has no 路, so the import failed with 'cp932' codec can't encode character '\xb7'.

What changed

  • _write_meta() and the output-dir migration write job.json as UTF-8.
  • Both readers go through a new _read_job_meta(), which reads UTF-8 and falls back to the platform encoding. Without the fallback, a job.json that an earlier version wrote in CP932 with non-ASCII text (a Japanese job name, say) would fail to parse, and the job would drop out of the list.

How this was tested

  • Two tests in tests/test_jobs.py make Path.read_text/write_text default to CP932. One imports a model with the default name and loads it back; it fails on main with the error from the issue. The other loads a CP932 job.json written the old way; it fails if the fallback is removed.
  • pytest tests/test_jobs.py: 23 passed. The rest of the suite needs lerobot, which I didn't install locally.
  • On macOS with PYTHONUTF8=0 LC_ALL=ja_JP.SJIS, register_imported() on a local model raises UnicodeEncodeError on main and registers the model on this branch.
  • ruff check and ruff format --check (0.14.1, the pre-commit version) pass on both files.

Other text reads in jobs.py (the training log, config.json) still use the default encoding. I left them out to keep this to job.json.

Written with Claude Code (Claude Opus 5.5).

The default name of an imported model contains U+00B7, which CP932 cannot
encode, so on Japanese Windows the import failed while writing job.json.
Reading falls back to the platform encoding for job.json files written by
earlier versions.

Fixes huggingface#131
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.

Model import fails on Japanese Windows: CP932 cannot encode U+00B7 in the default job name

1 participant