remove importlib_resources (#10076)

this is part of my work on
https://github.com/certbot/certbot/issues/10035 based on erica's comment
at
https://github.com/certbot/certbot/issues/10035#issuecomment-2452212686
This commit is contained in:
Brad Warren
2024-12-06 12:37:17 -08:00
committed by GitHub
parent 3f9387bd15
commit 7a48c235a9
23 changed files with 66 additions and 146 deletions
+1
View File
@@ -15,6 +15,7 @@ Certbot adheres to [Semantic Versioning](https://semver.org/).
* Updated our Docker images to be based on Alpine Linux 3.20.
* Our runtime dependency on setuptools has been dropped from all Certbot
components.
* Certbot's packages no longer depend on library importlib_resources.
### Fixed
+3 -8
View File
@@ -1,7 +1,7 @@
"""Certbot constants."""
import atexit
import importlib.resources
import logging
import sys
from contextlib import ExitStack
from typing import Any
from typing import Dict
@@ -10,11 +10,6 @@ from acme import challenges
from certbot.compat import misc
from certbot.compat import os
if sys.version_info >= (3, 9): # pragma: no cover
import importlib.resources as importlib_resources
else: # pragma: no cover
import importlib_resources
SETUPTOOLS_PLUGINS_ENTRY_POINT = "certbot.plugins"
"""Setuptools entry point group name for plugins."""
@@ -228,8 +223,8 @@ def _generate_ssl_dhparams_src_static() -> str:
# Python process, and will be automatically cleaned up on exit.
file_manager = ExitStack()
atexit.register(file_manager.close)
ssl_dhparams_src_ref = importlib_resources.files("certbot") / "ssl-dhparams.pem"
return str(file_manager.enter_context(importlib_resources.as_file(ssl_dhparams_src_ref)))
ssl_dhparams_src_ref = importlib.resources.files("certbot") / "ssl-dhparams.pem"
return str(file_manager.enter_context(importlib.resources.as_file(ssl_dhparams_src_ref)))
SSL_DHPARAMS_SRC = _generate_ssl_dhparams_src_static()
"""Path to the nginx ssl_dhparams file found in the Certbot distribution."""
+3 -8
View File
@@ -2,10 +2,10 @@
from abc import ABCMeta
from abc import abstractmethod
import argparse
import importlib.resources
import logging
import re
import shutil
import sys
import tempfile
from typing import Any
from typing import Callable
@@ -31,11 +31,6 @@ from certbot.interfaces import Installer as AbstractInstaller
from certbot.interfaces import Plugin as AbstractPlugin
from certbot.plugins.storage import PluginStorage
if sys.version_info >= (3, 9): # pragma: no cover
import importlib.resources as importlib_resources
else: # pragma: no cover
import importlib_resources
logger = logging.getLogger(__name__)
@@ -465,8 +460,8 @@ def dir_setup(test_dir: str, pkg: str) -> Tuple[str, str, str]: # pragma: no co
filesystem.chmod(config_dir, constants.CONFIG_DIRS_MODE)
filesystem.chmod(work_dir, constants.CONFIG_DIRS_MODE)
test_dir_ref = importlib_resources.files(pkg).joinpath("testdata").joinpath(test_dir)
with importlib_resources.as_file(test_dir_ref) as path:
test_dir_ref = importlib.resources.files(pkg).joinpath("testdata").joinpath(test_dir)
with importlib.resources.as_file(test_dir_ref) as path:
shutil.copytree(
path, os.path.join(temp_dir, test_dir), symlinks=True)
+4 -8
View File
@@ -3,6 +3,7 @@ import atexit
from contextlib import ExitStack
import copy
from importlib import reload as reload_module
import importlib.resources
import io
import logging
import multiprocessing
@@ -38,11 +39,6 @@ from certbot.compat import os
from certbot.display import util as display_util
from certbot.plugins import common
if sys.version_info >= (3, 9): # pragma: no cover
import importlib.resources as importlib_resources
else: # pragma: no cover
import importlib_resources
class DummyInstaller(common.Installer):
"""Dummy installer plugin for test purpose."""
@@ -84,14 +80,14 @@ def vector_path(*names: str) -> str:
"""Path to a test vector."""
_file_manager = ExitStack()
atexit.register(_file_manager.close)
vector_ref = importlib_resources.files(__package__).joinpath('testdata', *names)
path = _file_manager.enter_context(importlib_resources.as_file(vector_ref))
vector_ref = importlib.resources.files(__package__).joinpath('testdata', *names)
path = _file_manager.enter_context(importlib.resources.as_file(vector_ref))
return str(path)
def load_vector(*names: str) -> bytes:
"""Load contents of a test vector."""
vector_ref = importlib_resources.files(__package__).joinpath('testdata', *names)
vector_ref = importlib.resources.files(__package__).joinpath('testdata', *names)
data = vector_ref.read_bytes()
# Try at most to convert CRLF to LF when data is text
try:
-1
View File
@@ -32,7 +32,6 @@ install_requires = [
'configobj>=5.0.6',
'cryptography>=3.2.1',
'distro>=1.0.1',
'importlib_resources>=1.3.1; python_version < "3.9"',
'importlib_metadata>=4.6; python_version < "3.10"',
# Josepy 2+ may introduce backward incompatible changes by droping usage of
# deprecated PyOpenSSL APIs.