Repository navigation
Use importlib.metadata instead of pkg_resources - #82
Conversation
|
Note on the red CI here — it is not caused by this change. All six
GitHub now auto-fails any workflow referencing I have opened #83 to fix the CI configuration separately, so this PR stays scoped to the one-file library change. For what it is worth, the two changes together were verified green on a fork — all 7 jobs passing on Python 3.7 through 3.12. There is also a neat confirmation that this patch is doing its job: on the #83 branch, which does not include this fix, the |
pkg_resources was removed in setuptools 82.0.0, so `import pinax.referrals` raises ModuleNotFoundError on any environment with a current setuptools. Since the package is in INSTALLED_APPS, this breaks Django startup outright. importlib.metadata is used where available (Python 3.8+), falling back to pkg_resources on Python 3.7, which is still listed in the CI matrix and the tox envlist. No new dependency is introduced. If 3.7 support is dropped, the fallback can go with it and the import becomes a one-liner. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
d53d1db to
88e1b95
Compare
setuptools 82.0.0 removed
pkg_resources, so on any environment with a current setuptools:>>> import pinax.referrals ModuleNotFoundError: No module named 'pkg_resources'The import is unconditional and at module level in
pinax/referrals/__init__.py. Because the package lives inINSTALLED_APPS, this breaks Django startup outright — the whole site fails to boot, not just the referrals feature.pkg_resourcesis used for exactly one thing here: reading the package's own version.importlib.metadata.version()is the direct replacement.Compatibility
importlib.metadatais stdlib from Python 3.8. This package still lists 3.7 in both the CI matrix (.github/workflows/main.yml) and the tox envlist, so I kept a fallback topkg_resourcesonImportErrorrather than silently dropping that support. No new dependency is introduced — the fallback uses what 3.7 environments already have.If you have dropped 3.7 since, I am happy to squash this down to a plain one-line
from importlib.metadata import version— just say the word.Verified
Both paths were exercised against the installed 4.3.0 distribution: the
importlib.metadatapath and the fallback path (withimportlib.metadataforced to be unimportable) each yield__version__ == "4.3.0", withdefault_app_configunchanged.🤖 Generated with Claude Code