Repository navigation
fix: Ignore the suffix of a directory path when choosing the image format - #484
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
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.
Summary
When
pathis an existing directory whose name has a dot, such asreports/2024.01.31,coerce_for_jstakes the part after the last dot as the image format. The render fails withValueError: Invalid format '31'and no file is written. With the defaultcancel_on_error=Falsethe error is only returned, so the call looks like it succeeds. A directory namedplots.svgsilently switches the output to SVG.determine_pathalready treats such a path as a directory. This change makescoerce_for_jsagree with it: only a file path's suffix sets the format, and a directory falls back to theformatoption or the defaultpng.Fixes #483
Changes
kaleido/_utils/fig_tools.py: skippath.suffixwhenpathis a directory.tests/test_fig_tools.py: addtest_coerce_for_js_directory_with_suffixfor2024.01.31andplots.svg, passed asPathandstr.CHANGELOG.md: add an entry under Unreleased.Testing
uv run pytest tests/test_fig_tools.py -k directory_with_suffix: 2 failed before the change (ValueError: Invalid format '31',assert 'svg' == 'png'), 2 passed after.uv run pytest tests/test_fig_tools.py tests/test_path_tools.py: 276 passed.kaleido.write_fig_sync(fig, path=<dir>/2024.01.31)returned theValueErrorand wrote nothing before, and writesSales.pngafter.ruff check .passes.