Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Release 1.14.0 (2025-??-??)
* Fixed an error when using json encoder with cookie based sessions
* Removed support for pylibmc
* Beaker is now tested on Python 3.8+ ... 3.13
* Load entry points with importlib.metadata instead of deprecated pkg_resources

Release 1.13.0 (2024-04-11)
===========================
Expand Down
64 changes: 29 additions & 35 deletions beaker/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,42 +80,36 @@ def __getitem__(self, key):
raise e

def _init(self):
try:
import pkg_resources

# Load up the additional entry point defined backends
for entry_point in pkg_resources.iter_entry_points('beaker.backends'):
import importlib.metadata

# Load up the additional entry point defined backends
for entry_point in importlib.metadata.entry_points(group='beaker.backends'):
try:
namespace_manager = entry_point.load()
name = entry_point.name
if name in self._clsmap:
raise BeakerException("NamespaceManager name conflict,'%s' "
"already loaded" % name)
self._clsmap[name] = namespace_manager
except (InvalidCacheBackendError, SyntaxError):
# Ignore invalid backends
pass
except Exception:
# Warn when there's a problem loading a NamespaceManager
import traceback
try:
namespace_manager = entry_point.load()
name = entry_point.name
if name in self._clsmap:
raise BeakerException("NamespaceManager name conflict,'%s' "
"already loaded" % name)
self._clsmap[name] = namespace_manager
except (InvalidCacheBackendError, SyntaxError):
# Ignore invalid backends
pass
except:
import sys
from pkg_resources import DistributionNotFound
# Warn when there's a problem loading a NamespaceManager
if not isinstance(sys.exc_info()[1], DistributionNotFound):
import traceback
try:
from StringIO import StringIO # Python2
except ImportError:
from io import StringIO # Python3

tb = StringIO()
traceback.print_exc(file=tb)
warnings.warn(
"Unable to load NamespaceManager "
"entry point: '%s': %s" % (
entry_point,
tb.getvalue()),
RuntimeWarning, 2)
except ImportError:
pass
from StringIO import StringIO # Python2

@amol- amol- Nov 17, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beaker currently declares official support only for Python 3, so no need to add the backward compatible code for Python2. Especially since importlib didn't even exist on py2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this py2-compat code (which was already present, I did not add it) is rather obsolete now; I'll remove it.

except ImportError:
from io import StringIO # Python3

tb = StringIO()
traceback.print_exc(file=tb)
warnings.warn(
"Unable to load NamespaceManager "
"entry point: '%s': %s" % (
entry_point,
tb.getvalue()),
RuntimeWarning, 2)

# Initialize the basic available backends
clsmap = _backends({
Expand Down