Skip to content

Added standard imghdr implementation to replace deleted module. #7002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

E1k3
Copy link

@E1k3 E1k3 commented Jun 23, 2025

Motivation for features / changes

The imghdr module was deprecated some time ago and was removed in 3.13.
As discussed in #6964, the final original imghdr implementation contains very little code and has not changed in years, so it should not incur a high maintenance cost.

Technical description of changes

Copied https://github.com/python/cpython/blob/3.12/Lib/imghdr.py into tensorboard/util and removed deprecation warnings.
Replaced all occurrences of import imghdr with from tensorboard.util import imghdr.

Screenshots of UI changes (or N/A)

N/A

Detailed steps to verify changes work correctly (as executed by you)

I am currently unable to test the changes on my machine.
Testing by anyone interested in these changes would be appreciated.

Alternate designs / implementations considered (or N/A)

Alternatively a new dependency like https://github.com/h2non/filetype.py could be added.
While filetype.py still gets regular updates, tensorboards requirements are met by the unchanged standard implementation.

Copy link

google-cla bot commented Jun 23, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@E1k3
Copy link
Author

E1k3 commented Jun 23, 2025

I cannot create a Google account (phone number cannot be used for verification), so I am unable to sign the CLA.
Consider adding the option to sign without an account.

@arcra
Copy link
Member

arcra commented Jun 24, 2025

Thank you, @E1k3 !!

This seems a reasonable and simple way to go about it. I need to figure out what's the right way to include license attribution, tho, especially with our internal repository and tooling. The license mentions something about this. I hope I can take a look at this sometime next week.

About the CLA... I don't think there's something that I can do, sorry. This seems to be a company policy with legal implications that would likely be hard to work around.

I don't mind replicating your change and submitting it (and crediting you), but it won't be technically registered as your contribution in the system, unfortunately.

@E1k3
Copy link
Author

E1k3 commented Jun 24, 2025

@arcra I don't mind the contribution to be someone else's, go ahead.
Regarding the license, I'm not sure if the PSF 2 is compatible with tensorboards license and if it would have to be included in the imghdr.py file.

If it turns out to be incompatible, maybe consider using https://github.com/h2non/filetype.py or copying the necessary code from that project, which is MIT licensed.

@@ -0,0 +1,175 @@
"""Recognize image file formats based on their first few bytes."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be add a line of reference to the original library, i believe it's
https://github.com/python/cpython/blob/3.12/Lib/imghdr.py?

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.

3 participants