sacred icon indicating copy to clipboard operation
sacred copied to clipboard

Replace deprecated pkg_resources usage in mongo observer

Open pulkitgoyal56 opened this issue 1 month ago • 3 comments

Summary

Prefer stdlib importlib.resources to locate sacred/data/mime.types and fall back to pkg_resources only if necessary. This avoids UserWarning about pkg_resources deprecation when importing sacred.observers.mongo.

./.venv/lib/python3.13/site-packages/sacred/dependencies.py:11: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.

This adds support for Python 3.13/14.

Rationale

pkg_resources is deprecated as an API; importlib.resources is the modern replacement in the stdlib and available in most supported Python versions.

This change is backwards-compatible and preserves previous behavior by falling back to pkg_resources when importlib.resources is not available.

Files Changed

sacred/observers/mongo.py

Testing

Smoke-tested import and mime detection locally.

Follow-up

Consider removing other uses of pkg_resources (e.g., sacred/dependencies.py).

pulkitgoyal56 avatar Oct 28 '25 19:10 pulkitgoyal56

Hi @pulkitgoyal56! Thanks for addressing this issue! It seems like your modification is not backward-compatible, can you fix it for Python <=3.9?

Also, we use black formatting, please run the pre-commit hook. It will fix the test_pre_commit test case.

thequilo avatar Nov 06 '25 08:11 thequilo

Hey, thanks for your reply. I'll fix it and apply the formatting.

pulkitgoyal56 avatar Nov 06 '25 09:11 pulkitgoyal56

I'd like to finish this issue, but keeping support for Python <= 3.9 is just hacky. Given that they have reached EOL, maybe this is not really required?

But if you still want to keep support for it, I'll cancel this pull request.

pulkitgoyal56 avatar Dec 05 '25 18:12 pulkitgoyal56