Switch to Python3 importlib

This commit is contained in:
David Boreham 2023-01-07 20:44:08 -07:00
parent cd2735fa24
commit c99687cc80
5 changed files with 20 additions and 12 deletions

View File

@ -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}')

View File

@ -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}')

0
app/data/__init__.py Normal file
View File

View File

@ -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}")

View File

@ -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}")