Merge pull request #99 from cerc-io/dboreham/fix-shiv

Refactor for shiv package
This commit is contained in:
David Boreham 2023-01-08 20:12:33 -07:00 committed by GitHub
commit 4494f2ca62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
128 changed files with 30 additions and 17 deletions

View File

@ -24,7 +24,8 @@ import os
from decouple import config from decouple import config
import subprocess import subprocess
import click import click
import pkg_resources import importlib
from pathlib import Path
from .util import include_exclude_check from .util import include_exclude_check
# TODO: find a place for this # TODO: find a place for this
@ -43,8 +44,8 @@ def command(ctx, include, exclude):
dry_run = ctx.obj.dry_run dry_run = ctx.obj.dry_run
local_stack = ctx.obj.local_stack local_stack = ctx.obj.local_stack
# TODO: check this still works in the shiv package scenario # See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure
container_build_dir = os.path.join(os.getcwd(), "container-build") container_build_dir = Path(__file__).absolute().parent.joinpath("data", "container-build")
if local_stack: if local_stack:
dev_root_path = os.getcwd()[0:os.getcwd().rindex("stack-orchestrator")] dev_root_path = os.getcwd()[0:os.getcwd().rindex("stack-orchestrator")]
@ -58,8 +59,10 @@ def command(ctx, include, exclude):
if not os.path.isdir(dev_root_path): if not os.path.isdir(dev_root_path):
print('Dev root directory doesn\'t exist, creating') print('Dev root directory doesn\'t exist, creating')
with pkg_resources.resource_stream(__name__, "data/container-image-list.txt") as container_list_file: # See: https://stackoverflow.com/a/20885799/1701505
containers = container_list_file.read().decode().splitlines() 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: if verbose:
print(f'Containers: {containers}') print(f'Containers: {containers}')
@ -88,7 +91,7 @@ def command(ctx, include, exclude):
# Check if we have a repo for this container. If not, set the context dir to the container-build subdir # Check if we have a repo for this container. If not, set the context dir to the container-build subdir
repo_full_path = os.path.join(dev_root_path, repo_dir) repo_full_path = os.path.join(dev_root_path, repo_dir)
repo_dir_or_build_dir = repo_dir if os.path.exists(repo_full_path) else build_dir repo_dir_or_build_dir = repo_dir if os.path.exists(repo_full_path) else build_dir
build_command = os.path.join("container-build", "default-build.sh") + f" {container} {repo_dir_or_build_dir}" build_command = os.path.join(container_build_dir, "default-build.sh") + f" {container} {repo_dir_or_build_dir}"
if not dry_run: if not dry_run:
if verbose: if verbose:
print(f"Executing: {build_command}") print(f"Executing: {build_command}")

View File

@ -21,7 +21,7 @@
import os import os
from decouple import config from decouple import config
import click import click
import pkg_resources import importlib
from python_on_whales import docker from python_on_whales import docker
from .util import include_exclude_check from .util import include_exclude_check
@ -50,8 +50,10 @@ def command(ctx, include, exclude):
if not os.path.isdir(dev_root_path): if not os.path.isdir(dev_root_path):
print('Dev root directory doesn\'t exist, creating') print('Dev root directory doesn\'t exist, creating')
with pkg_resources.resource_stream(__name__, "data/npm-package-list.txt") as package_list_file: # See: https://stackoverflow.com/a/20885799/1701505
packages = package_list_file.read().decode().splitlines() 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: if verbose:
print(f'Packages: {packages}') print(f'Packages: {packages}')

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

Some files were not shown because too many files have changed in this diff Show More