From 2e272a39d0efee74c840873e9164dce50640a3d8 Mon Sep 17 00:00:00 2001
From: Scott Talbert <swt@techie.net>
Date: Wed, 16 Jun 2021 14:19:40 -0400
Subject: [PATCH] Fix building with Python 3.10
---
src/calibre/constants.py | 4 ++--
src/calibre/db/cache.py | 3 ++-
src/calibre/db/lazy.py | 2 +-
src/calibre/test_build.py | 2 +-
src/calibre/utils/dbus_service.py | 2 +-
src/calibre/utils/run_tests.py | 5 ++---
src/css_selectors/ordered_set.py | 4 ++--
7 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/calibre/constants.py b/src/calibre/constants.py
index 330ef1e0e1..b0b9002de2 100644
--- a/src/calibre/constants.py
+++ b/src/calibre/constants.py
@@ -2,7 +2,7 @@
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
from polyglot.builtins import map, unicode_type, environ_item, hasenv, getenv
-import sys, locale, codecs, os, collections
+import sys, locale, codecs, os, collections, collections.abc
__appname__ = 'calibre'
numeric_version = (5, 21, 0)
@@ -291,7 +291,7 @@ def find_spec(self, fullname, path=None, target=None):
from calibre_extensions import winutil
-class Plugins(collections.Mapping):
+class Plugins(collections.abc.Mapping):
def __iter__(self):
from importlib.resources import contents
diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py
index 958da81fa1..d0fa2403b9 100644
--- a/src/calibre/db/cache.py
+++ b/src/calibre/db/cache.py
@@ -12,7 +12,8 @@
import shutil
import sys
import traceback
-from collections import MutableSet, Set, defaultdict
+from collections import defaultdict
+from collections.abc import MutableSet, Set
from functools import partial, wraps
from io import BytesIO
from threading import Lock
diff --git a/src/calibre/db/lazy.py b/src/calibre/db/lazy.py
index d2b7398f24..d67ec8397c 100644
--- a/src/calibre/db/lazy.py
+++ b/src/calibre/db/lazy.py
@@ -8,7 +8,7 @@
import weakref
from functools import wraps
-from collections import MutableMapping, MutableSequence
+from collections.abc import MutableMapping, MutableSequence
from copy import deepcopy
from calibre.ebooks.metadata.book.base import Metadata, SIMPLE_GET, TOP_LEVEL_IDENTIFIERS, NULL_VALUES, ALL_METADATA_FIELDS
diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py
index 799bc02179..5c58ff5431 100644
--- a/src/calibre/test_build.py
+++ b/src/calibre/test_build.py
@@ -48,7 +48,7 @@ def test_dbus(self):
def test_loaders(self):
import importlib
- ldr = importlib.import_module('calibre').__spec__.loader
+ ldr = importlib.import_module('calibre').__spec__.loader.get_resource_reader()
self.assertIn('ebooks', ldr.contents())
try:
raw = ldr.open_resource('__init__.py').read()
diff --git a/src/calibre/utils/dbus_service.py b/src/calibre/utils/dbus_service.py
index e04b6524b6..fb38136daf 100644
--- a/src/calibre/utils/dbus_service.py
+++ b/src/calibre/utils/dbus_service.py
@@ -33,7 +33,7 @@
import logging
import threading
import traceback
-from collections import Sequence
+from collections.abc import Sequence
import _dbus_bindings
from dbus import (
diff --git a/src/calibre/utils/run_tests.py b/src/calibre/utils/run_tests.py
index 673de4bcc4..2b5034b01b 100644
--- a/src/calibre/utils/run_tests.py
+++ b/src/calibre/utils/run_tests.py
@@ -3,7 +3,7 @@
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
-import unittest, functools, importlib
+import unittest, functools, importlib, importlib.resources
from calibre.utils.monotonic import monotonic
@@ -54,8 +54,7 @@ def stopTestRun(self):
def find_tests_in_package(package, excludes=('main.py',)):
- loader = importlib.import_module(package).__spec__.loader
- items = list(loader.contents())
+ items = list(importlib.resources.contents(package))
suits = []
excludes = set(excludes) | {x + 'c' for x in excludes}
seen = set()
diff --git a/src/css_selectors/ordered_set.py b/src/css_selectors/ordered_set.py
index 369d3e122d..51c30c2eb2 100644
--- a/src/css_selectors/ordered_set.py
+++ b/src/css_selectors/ordered_set.py
@@ -5,7 +5,7 @@
__license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
-import collections
+import collections.abc
from polyglot.builtins import string_or_bytes
SLICE_ALL = slice(None)
@@ -23,7 +23,7 @@ def is_iterable(obj):
return hasattr(obj, '__iter__') and not isinstance(obj, string_or_bytes)
-class OrderedSet(collections.MutableSet):
+class OrderedSet(collections.abc.MutableSet):
"""
An OrderedSet is a custom MutableSet that remembers its order, so that
every entry has an index that can be looked up.
--
2.31.1