Repository navigation
Fix Python 3 incompatibilities in bin/docker-to-squash.py - #9296
Open
ToniAdreal wants to merge 1 commit into
Open
ToniAdreal wants to merge 1 commit into
ToniAdreal wants to merge 1 commit into
Conversation
The script cannot run on Python 3: Iterable is imported from collections (removed in 3.10), the --untagged-transition-sec argument uses type=long, calculate_string_hash passes a str to hashlib, and write_local_image_tag_to_hash uses dict.iteritems(). Import Iterable from collections.abc, use type=int, encode the string as UTF-8 before hashing, and use dict.items(). Also replace two 'is not ""' comparisons with '!=' to silence SyntaxWarning. Signed-off-by: ToniAdreal <184365500+ToniAdreal@users.noreply.github.com>
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.
Fixes #9291.
bin/docker-to-squash.pycannot run on Python 3 at all. Reproduced on Python 3.12.3 against master (4fca209):python3 docker-to-squash.py --helpfails immediately withImportError: cannot import name 'Iterable' from 'collections'.NameError: name 'long' is not definedfor--untagged-transition-sec.calculate_string_hash("x")raisesTypeError: Strings must be encoded before hashing.write_local_image_tag_to_hashraisesAttributeError: 'dict' object has no attribute 'iteritems'.Changes, all in
bin/docker-to-squash.py:Iterablefromcollections.abctype=long->type=intfor--untagged-transition-seccalculate_string_hashdict.iteritems()->dict.items()image is not ""comparisons ->!= ""(SyntaxWarning since Python 3.8)Testing:
python3 -m unittest test_docker_to_squash.pyinbin/errors on the import before this change and passes after it.--helpnow builds the full parser, andcalculate_string_hash/write_local_image_tag_to_hashwere exercised directly.This is one of the four docker-to-squash.py fixes that #9284 left to separate PRs (the others are #9289, #9290, #9292). It is also a prerequisite for testing the rest, since the test file cannot be imported on Python 3.10+ without it.