From c99687cc80f76fa610477b23a540632ec5e9ddc3 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Sat, 7 Jan 2023 20:44:08 -0700 Subject: [PATCH] Switch to Python3 importlib --- app/build_containers.py | 8 +++++--- app/build_npms.py | 8 +++++--- app/data/__init__.py | 0 app/deploy_system.py | 8 +++++--- app/setup_repositories.py | 8 +++++--- 5 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 app/data/__init__.py diff --git a/app/build_containers.py b/app/build_containers.py index c74df1e..fde6c30 100644 --- a/app/build_containers.py +++ b/app/build_containers.py @@ -24,7 +24,7 @@ import os from decouple import config import subprocess import click -import pkg_resources +import importlib from .util import include_exclude_check # TODO: find a place for this @@ -58,8 +58,10 @@ def command(ctx, include, exclude): if not os.path.isdir(dev_root_path): print('Dev root directory doesn\'t exist, creating') - with pkg_resources.resource_stream(__name__, "data/container-image-list.txt") as container_list_file: - containers = container_list_file.read().decode().splitlines() + # See: https://stackoverflow.com/a/20885799/1701505 + from . import data + with importlib.resources.open_text(data, "container-image-list.txt") as container_list_file: + containers = container_list_file.read().splitlines() if verbose: print(f'Containers: {containers}') diff --git a/app/build_npms.py b/app/build_npms.py index e00c073..905a54c 100644 --- a/app/build_npms.py +++ b/app/build_npms.py @@ -21,7 +21,7 @@ import os from decouple import config import click -import pkg_resources +import importlib from python_on_whales import docker from .util import include_exclude_check @@ -50,8 +50,10 @@ def command(ctx, include, exclude): if not os.path.isdir(dev_root_path): print('Dev root directory doesn\'t exist, creating') - with pkg_resources.resource_stream(__name__, "data/npm-package-list.txt") as package_list_file: - packages = package_list_file.read().decode().splitlines() + # See: https://stackoverflow.com/a/20885799/1701505 + from . import data + with importlib.resources.open_text(data, "npm-package-list.txt") as package_list_file: + packages = package_list_file.read().splitlines() if verbose: print(f'Packages: {packages}') diff --git a/app/data/__init__.py b/app/data/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/deploy_system.py b/app/deploy_system.py index 45f6b61..169e0d6 100644 --- a/app/deploy_system.py +++ b/app/deploy_system.py @@ -20,7 +20,7 @@ import os import sys from python_on_whales import DockerClient import click -import pkg_resources +import importlib from .util import include_exclude_check @@ -49,8 +49,10 @@ def command(ctx, include, exclude, cluster, command, services): if verbose: print(f"Using cluster name: {cluster}") - with pkg_resources.resource_stream(__name__, "data/pod-list.txt") as pod_list_file: - pods = pod_list_file.read().decode().splitlines() + # See: https://stackoverflow.com/a/20885799/1701505 + from . import data + with importlib.resources.open_text(data, "pod-list.txt") as pod_list_file: + pods = pod_list_file.read().splitlines() if verbose: print(f"Pods: {pods}") diff --git a/app/setup_repositories.py b/app/setup_repositories.py index 3086cbb..bb1c3c6 100644 --- a/app/setup_repositories.py +++ b/app/setup_repositories.py @@ -22,7 +22,7 @@ from decouple import config import git from tqdm import tqdm import click -import pkg_resources +import importlib from .util import include_exclude_check @@ -91,8 +91,10 @@ def command(ctx, include, exclude, git_ssh, check_only, pull, branches_file): print('Dev root directory doesn\'t exist, creating') os.makedirs(dev_root_path) - with pkg_resources.resource_stream(__name__, "data/repository-list.txt") as repository_list_file: - all_repos = repository_list_file.read().decode().splitlines() + # See: https://stackoverflow.com/a/20885799/1701505 + from . import data + with importlib.resources.open_text(data, "repository-list.txt") as repository_list_file: + all_repos = repository_list_file.read().splitlines() if verbose: print(f"Repos: {all_repos}")