Skip to content

Commit 0a444cb

Browse files
IsaacDayannoamgeller1024
authored andcommitted
fix: Remove deprecated pkg_resources usage to support setuptools>=81
The pkg_resources.declare_namespace() call is deprecated and will be removed from setuptools as early as 2025-11-30. This was causing UserWarning messages in environments with newer setuptools versions. Modern Python (3.3+) handles namespace packages automatically via PEP 420, making the declare_namespace() call unnecessary. Added backwards compatibility check for Python 2.7 and older Python 3 versions that might still need it. This change: - Eliminates deprecation warnings in modern environments - Maintains compatibility with older Python versions - Prepares the codebase for setuptools>=81
1 parent de29808 commit 0a444cb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pyformance/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
__import__("pkg_resources").declare_namespace(__name__)
1+
# Maintain backwards compatibility while avoiding deprecation warnings
2+
import sys
3+
if sys.version_info < (3, 3):
4+
# Only use pkg_resources for Python < 3.3 which doesn't support PEP 420
5+
try:
6+
__import__("pkg_resources").declare_namespace(__name__)
7+
except ImportError:
8+
pass
9+
# For Python 3.3+, namespace packages work automatically (PEP 420)
210

311
from .registry import MetricsRegistry, global_registry, set_global_registry
412
from .registry import timer, counter, meter, histogram, gauge, event

0 commit comments

Comments
 (0)