You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What this PR does:
A potential solution for issue #413.
The current use of pkg_resources raises a DeprecationWarning during import. pkgutil is recommended as a lightweight, standard-library alternative. Also, pkg_resources from setuptools has been deprecated, since implicit namespace packages were introduced in PEP 420.
This PR replaces the deprecated pkg_resources.declare_namespace with pkgutil.extend_path for namespace declaration in tika/__init__.py.
Edited Files:
tika/__init__.py: Replaced pkg_resources.declare_namespace(__name__) with pkgutil.extend_path(__path__, __name__) and removed the fallback for pkg_resources.
setup.py: Added namespace_packages=['tika'].
Updated on Apr 1, 2025:
Removed namespace_packages=['tika'] from setup.py. setup.py remains the same as the original version.
thanks @Zili-Yang-z how can I test that this resolves the error?
You're welcome!
I'm testing by importing tika in Google Colab.
When importing the original tika with warnings.simplefilter('always'), I got:
/usr/local/lib/python3.11/dist-packages/pkg_resources/__init__.py:3154: DeprecationWarning: Deprecated call to pkg_resources.declare_namespace('sphinxcontrib').
...
Implementing implicit namespace packages (as specified in PEP 420) is preferred to pkg_resources.declare_namespace. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
__import__('pkg_resources').declare_namespace(__name__)
Then I zipped and installed the modified tika that uses pkgutil.extend_path in __init__.py. After importing it with warnings.simplefilter('always'), the DeprecationWarnings disappeared as expected.
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
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.
What this PR does:
A potential solution for issue #413.
The current use of
pkg_resourcesraises aDeprecationWarningduring import.pkgutilis recommended as a lightweight, standard-library alternative. Also,pkg_resourcesfromsetuptoolshas been deprecated, since implicit namespace packages were introduced in PEP 420.This PR replaces the deprecated
pkg_resources.declare_namespacewithpkgutil.extend_pathfor namespace declaration intika/__init__.py.Edited Files:
tika/__init__.py: Replacedpkg_resources.declare_namespace(__name__)withpkgutil.extend_path(__path__, __name__)and removed the fallback forpkg_resources.setup.py: Addednamespace_packages=['tika'].Updated on Apr 1, 2025:
Removed
namespace_packages=['tika']fromsetup.py.setup.pyremains the same as the original version.