Skip to content

fix: replace deprecated pkg_resources with importlib.resources (#116)#122

Open
DhruvrajSinhZala24 wants to merge 1 commit intofossology:masterfrom
DhruvrajSinhZala24:fix/issue-116
Open

fix: replace deprecated pkg_resources with importlib.resources (#116)#122
DhruvrajSinhZala24 wants to merge 1 commit intofossology:masterfrom
DhruvrajSinhZala24:fix/issue-116

Conversation

@DhruvrajSinhZala24
Copy link
Copy Markdown

Fixes #116

Problem

Atarashi fails with ModuleNotFoundError: No module named 'pkg_resources' when running on Python 3.10+ environments where setuptools >= 80 is installed. This is particularly prevalent in modern distributions like Ubuntu 22.04+ with Python 3.12.

Reproduction Steps

  1. Initialize a Python 3.12 environment.
  2. Ensure setuptools >= 80.0.0 is installed.
  3. Run any atarashi command (e.g., atarashi -h) or try to import the evaluator (from atarashi.evaluator.evaluator import evaluate).
  4. Result: ModuleNotFoundError: No module named 'pkg_resources'.

Root Cause

The pkg_resources API is part of setuptools but has been deprecated for several years and is officially removed from the default installation in recent versions (v80+). Atarashi was using pkg_resources.resource_filename to 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.py to use importlib.resources, which is the standard library replacement for pkg_resources.

  • Replaced pkg_resources.resource_filename with importlib.resources.files.
  • Added a graceful fallback to the importlib_resources backport (which is already a project dependency) for maximum compatibility.
  • This fix ensures that the project does not depend on setuptools at runtime, aligning with current PyPA recommendations.

Testing Performed

  • Verified that atarashi -h and evaluator imports work perfectly in an environment with setuptools 80.10.2 and Python 3.13.
  • Verified that all default resource paths for processedLicenses.csv and Ngram_keywords.json are resolved correctly.

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.

ModuleNotFoundError: No module named 'pkg_resources' with setuptools >=80 (Python 3.12)

1 participant