Make code compatible with Pyton 3.8

This commit is contained in:
David Boreham 2023-01-17 22:25:04 -07:00
parent 1d7128c6e1
commit 04a3049162

View File

@ -23,6 +23,7 @@ import git
from tqdm import tqdm from tqdm import tqdm
import click import click
import importlib.resources import importlib.resources
from pathlib import Path
import yaml import yaml
from .util import include_exclude_check from .util import include_exclude_check
@ -100,8 +101,10 @@ def command(ctx, include, exclude, git_ssh, check_only, pull, branches_file):
all_repos = repository_list_file.read().splitlines() all_repos = repository_list_file.read().splitlines()
if stack: if stack:
resource_data_dir = importlib.resources.files(data) # In order to be compatible with Python 3.8 we need to use this hack to get the path:
with importlib.resources.as_file(resource_data_dir.joinpath(f"stacks/{stack}/stack.yml")) as stack_file_path: # See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
stack_file_path = Path(__file__).absolute().parent.joinpath("data", "stacks", stack, "stack.yml")
with stack_file_path:
stack_config = yaml.safe_load(open(stack_file_path, "r")) stack_config = yaml.safe_load(open(stack_file_path, "r"))
print(f"stack is: {stack_config}") print(f"stack is: {stack_config}")