From 35c48766d7b00119e933b2384e36b593de57631c Mon Sep 17 00:00:00 2001 From: Tobias Gruetzmacher Date: Sat, 3 Jun 2023 17:51:16 +0200 Subject: [PATCH] Modernize importlib.resources usage (#270) See https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy --- dosagelib/plugins/comicskingdom.py | 11 +++++++---- pyproject.toml | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dosagelib/plugins/comicskingdom.py b/dosagelib/plugins/comicskingdom.py index 48cf54b65..5ced8fa49 100644 --- a/dosagelib/plugins/comicskingdom.py +++ b/dosagelib/plugins/comicskingdom.py @@ -1,7 +1,10 @@ # SPDX-License-Identifier: MIT -# Copyright (C) 2019-2022 Tobias Gruetzmacher -# Copyright (C) 2019 Thomas W. Littauer -from importlib.resources import path as get_path +# SPDX-FileCopyrightText: © 2019 Tobias Gruetzmacher +# SPDX-FileCopyrightText: © 2019 Thomas W. Littauer +try: + from importlib_resources import as_file, files +except ImportError: + from importlib.resources import as_file, files from ..helpers import bounceStarter, joinPathPartsNamer from ..scraper import ParserScraper @@ -25,7 +28,7 @@ class ComicsKingdom(ParserScraper): # slightly iffy hack taken from certifi # We need or own certificate bundle since ComicsKingdom screws up their # TLS setup from time to time, this should "fix" it) - self.cert_ctx = get_path('dosagelib.data', 'godaddy-bundle-g2-2031.pem') + self.cert_ctx = as_file(files('dosagelib.data') / 'godaddy-bundle-g2-2031.pem') self.session.add_host_options('comicskingdom.com', { 'verify': str(self.cert_ctx.__enter__()), }) diff --git a/pyproject.toml b/pyproject.toml index 8e935c4b2..923f77874 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ dependencies = [ "requests>=2.0", "cached_property;python_version<'3.8'", "importlib_metadata;python_version<'3.8'", + "importlib_resources>=5.0.0;python_version<'3.9'", ] dynamic = ["version"]