Repository navigation
Conversation
importers.import_metadata adds a JSON object's fields to the document's: each is set where it is, or added after the others, the JSON's value winning. Values become text as the migration makes an old file's fields text: a list of plain values stays a list of texts, null is empty text, anything else is its JSON. A `media length` key, in any letter case, sets the length through build.set_media_length while no media is attached; a positive number written as text counts. While media is attached it is ignored, with a note. A length it refuses fails the import. A file that doesn't exist, isn't UTF-8, isn't JSON or isn't an object raises ImportFailed with TiLiA's texts, and the import changes nothing. The importers package exports import_metadata and its result types. Part of TimeLineAnnotator/project-management#276 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Claude
Adds
tilia_core.importers.import_metadata(document, path), TiLiA'smetadata importin the core. It changes the document in memory and returns anImportResult.Fields. Each field of the JSON object is set where the document has it, or added after the others. The JSON's value wins, and the document's other fields stay. Names and values are stored in NFC, by
build.set_field.Values become text as the migration makes an old file's fields text (
migrate/to_1.py's_field, in Read files from older TiLiA versions through the migration #745 (read old files through the migration)):nullbecomes empty text;1795gives"1795",truegives"true",{"a": 1}gives'{"a": 1}'.media length, in any letter case, sincemetadata setrefuses it as a field in any letter case:build.set_media_length, with all its checks. A positive number written as text ("312.5") counts, as the migration reads an old file's length. A length it refuses fails the import with the refusal's text, and nothing is set, not even the other fields.result.notes:media length ignored: Can't change media length when a media file is loaded.A file it can't import raises
ImportFailedand changes nothing:File {path} not found.;Error when parsing file {path}:+ line break + the error'srepr, as TiLiA shows it. This includes nesting too deep to read and a number too long to read, where TiLiA would crash;expected an object of fields;'{path}' is not a valid UTF-8 encoded JSON file., TiLiA'sUTF8_DECODE_FAILEDfilled withJSON.A byte-order mark is accepted. A path that can't be opened for another reason, such as a folder, raises
OSError, as_csv.read_csvdoes.tilia_core.importersexportsimport_metadata,ImportResult,RowProblemandImportFailed.TimeLineAnnotator/project-management#326 (metadata import: a refused media length and three texts) is open on four of these points. It covers a refused length failing the import, a length written as text, the note's text, and the texts for JSON that isn't an object and a file that isn't UTF-8. An answer there changes only that behaviour and its tests.
Tests
tests/importers/test_importers_metadata.py(77 tests), written first:media lengthwith and without media, in other letter cases, written as text, and each refusal;Every failure is checked to leave the document as it was.
uv run --package tilia-core pytest packages/tilia-core -q: 978 passed, 21 skipped, 8 xfailed. The importers' tests also pass on Python 3.10 and 3.14.python scripts/check_packages.pypasses. black (22.12.0) and ruff are clean, and the files have LF line endings.This branch starts from feat(core): build a script's document: fields, media, its length and timelines #748's 7e935a2. feat(core): build a script's document: fields, media, its length and timelines #748 has since gained b032e08. This commit cherry-picks onto that cleanly, and the suite passes there too (989 passed, 21 skipped, 8 xfailed). The branch still needs a rebase onto it, which means a force-push.
Guarantees. I neutralised the code behind each one, ran
test_importers_metadata.py(77 tests), then restored it:str()in place ofjson.dumpsensure_ascii=Falsenullbecomes empty textNonecasemedia lengthin any letter caselower()media_pathcheckbuild.set_media_lengthmedia_lengthdirectlyreturnin place ofraiseisfiniteand> 0checkFileNotFoundErrorcaseUnicodeDecodeErrorcaseValueErrorin theexceptRecursionErrorin theexceptreprstr()in place ofrepr()dictcheckutf-8-sigexceptTwo guarantees have no code of their own here, so none could be neutralised:
media lengthleaves the length alone. Nothing resets it.test_the_media_length_and_the_other_fields_are_left_alonefails if a reset is added.build.set_fielddoes this, and feat(core): build a script's document: fields, media, its length and timelines #748's tests cover it.Stacked on #748.
Part of TimeLineAnnotator/project-management#276
🤖 Generated with Claude Code