fix: replace deprecated pkg_resources with importlib.resources (#116)#122
Open
DhruvrajSinhZala24 wants to merge 1 commit intofossology:masterfrom
Open
fix: replace deprecated pkg_resources with importlib.resources (#116)#122DhruvrajSinhZala24 wants to merge 1 commit intofossology:masterfrom
DhruvrajSinhZala24 wants to merge 1 commit intofossology:masterfrom
Conversation
c7300e2 to
32e5b15
Compare
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 #116
Problem
Atarashi fails with
ModuleNotFoundError: No module named 'pkg_resources'when running on Python 3.10+ environments wheresetuptools >= 80is installed. This is particularly prevalent in modern distributions like Ubuntu 22.04+ with Python 3.12.Reproduction Steps
setuptools >= 80.0.0is installed.atarashi -h) or try to import the evaluator (from atarashi.evaluator.evaluator import evaluate).ModuleNotFoundError: No module named 'pkg_resources'.Root Cause
The
pkg_resourcesAPI is part ofsetuptoolsbut has been deprecated for several years and is officially removed from the default installation in recent versions (v80+). Atarashi was usingpkg_resources.resource_filenameto locate internal license and data files, which is no longer a reliable or standard practice in modern Python packaging.Fix Implemented
I have migrated the resource loading logic in
atarashi/evaluator/evaluator.pyto useimportlib.resources, which is the standard library replacement forpkg_resources.pkg_resources.resource_filenamewithimportlib.resources.files.importlib_resourcesbackport (which is already a project dependency) for maximum compatibility.setuptoolsat runtime, aligning with current PyPA recommendations.Testing Performed
atarashi -handevaluatorimports work perfectly in an environment withsetuptools 80.10.2and Python 3.13.processedLicenses.csvandNgram_keywords.jsonare resolved correctly.