From 1d7128c6e1daf97c09b68b505a7a865333261ed0 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Tue, 17 Jan 2023 16:05:50 -0700 Subject: [PATCH 1/3] Initial implementation of stack --- app/setup_repositories.py | 11 +++++++++++ cli.py | 10 +++++++--- requirements.txt | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/setup_repositories.py b/app/setup_repositories.py index 28ee2c9e..8f00ae0f 100644 --- a/app/setup_repositories.py +++ b/app/setup_repositories.py @@ -23,6 +23,7 @@ import git from tqdm import tqdm import click import importlib.resources +import yaml from .util import include_exclude_check @@ -64,9 +65,11 @@ def command(ctx, include, exclude, git_ssh, check_only, pull, branches_file): quiet = ctx.obj.quiet verbose = ctx.obj.verbose dry_run = ctx.obj.dry_run + stack = ctx.obj.stack branches = [] + # TODO: branches file needs to be re-worked in the context of stacks if branches_file: if verbose: print(f"loading branches from: {branches_file}") @@ -96,8 +99,16 @@ def command(ctx, include, exclude, git_ssh, check_only, pull, branches_file): with importlib.resources.open_text(data, "repository-list.txt") as repository_list_file: all_repos = repository_list_file.read().splitlines() + if stack: + resource_data_dir = importlib.resources.files(data) + with importlib.resources.as_file(resource_data_dir.joinpath(f"stacks/{stack}/stack.yml")) as stack_file_path: + stack_config = yaml.safe_load(open(stack_file_path, "r")) + print(f"stack is: {stack_config}") + if verbose: print(f"Repos: {all_repos}") + if stack: + print(f"Stack: {stack}") repos = [] for repo in all_repos: diff --git a/cli.py b/cli.py index e2e94ab2..c0fa3990 100644 --- a/cli.py +++ b/cli.py @@ -24,8 +24,11 @@ from app import version CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) +# TODO: this seems kind of weird and heavy on boilerplate -- check it is +# the best Python can do for us. class Options(object): - def __init__(self, quiet, verbose, dry_run, local_stack, debug): + def __init__(self, stack, quiet, verbose, dry_run, local_stack, debug): + self.stack = stack self.quiet = quiet self.verbose = verbose self.dry_run = dry_run @@ -34,6 +37,7 @@ class Options(object): @click.group(context_settings=CONTEXT_SETTINGS) +@click.option('--stack', help="specify a stack to build/deploy") @click.option('--quiet', is_flag=True, default=False) @click.option('--verbose', is_flag=True, default=False) @click.option('--dry-run', is_flag=True, default=False) @@ -41,9 +45,9 @@ class Options(object): @click.option('--debug', is_flag=True, default=False) # See: https://click.palletsprojects.com/en/8.1.x/complex/#building-a-git-clone @click.pass_context -def cli(ctx, quiet, verbose, dry_run, local_stack, debug): +def cli(ctx, stack, quiet, verbose, dry_run, local_stack, debug): """Laconic Stack Orchestrator""" - ctx.obj = Options(quiet, verbose, dry_run, local_stack, debug) + ctx.obj = Options(stack, quiet, verbose, dry_run, local_stack, debug) cli.add_command(setup_repositories.command, "setup-repositories") diff --git a/requirements.txt b/requirements.txt index 7ee8181a..128ee3a0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ GitPython>=3.1.27 tqdm>=4.64.0 python-on-whales>=0.52.0 click>=8.1.3 +pyyaml>=6.0 -- 2.45.2 From 04a3049162ee6fc99f0633eff4c1539dedd5c546 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Tue, 17 Jan 2023 22:25:04 -0700 Subject: [PATCH 2/3] Make code compatible with Pyton 3.8 --- app/setup_repositories.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/setup_repositories.py b/app/setup_repositories.py index 8f00ae0f..1969c29c 100644 --- a/app/setup_repositories.py +++ b/app/setup_repositories.py @@ -23,6 +23,7 @@ import git from tqdm import tqdm import click import importlib.resources +from pathlib import Path import yaml 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() if stack: - resource_data_dir = importlib.resources.files(data) - with importlib.resources.as_file(resource_data_dir.joinpath(f"stacks/{stack}/stack.yml")) as stack_file_path: + # In order to be compatible with Python 3.8 we need to use this hack to get the 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")) print(f"stack is: {stack_config}") -- 2.45.2 From b0947081debe122007617b4355a134a95099b53c Mon Sep 17 00:00:00 2001 From: David Boreham Date: Tue, 17 Jan 2023 22:38:30 -0700 Subject: [PATCH 3/3] Update version info --- app/data/stacks/laconicd/stack.yml | 2 +- app/data/version.txt | 2 +- app/setup_repositories.py | 10 +++++++--- setup.py | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/data/stacks/laconicd/stack.yml b/app/data/stacks/laconicd/stack.yml index 6e262a08..d47a6fe5 100644 --- a/app/data/stacks/laconicd/stack.yml +++ b/app/data/stacks/laconicd/stack.yml @@ -1,5 +1,5 @@ version: "1.0" -name: laconicd-fixturenet +name: fixturenet-laconicd repos: - cerc-io/laconicd - cerc-io/laconic-sdk diff --git a/app/data/version.txt b/app/data/version.txt index 09f6b7b3..b583e2ff 100644 --- a/app/data/version.txt +++ b/app/data/version.txt @@ -1,2 +1,2 @@ # This file should be re-generated running: scripts/update-version-file.sh script -v1.0.9-alpha-32b4c00 +v1.0.9-alpha-04a3049 diff --git a/app/setup_repositories.py b/app/setup_repositories.py index 1969c29c..6f148b87 100644 --- a/app/setup_repositories.py +++ b/app/setup_repositories.py @@ -100,21 +100,25 @@ def command(ctx, include, exclude, git_ssh, check_only, pull, branches_file): with importlib.resources.open_text(data, "repository-list.txt") as repository_list_file: all_repos = repository_list_file.read().splitlines() + repos_in_scope = [] if stack: # In order to be compatible with Python 3.8 we need to use this hack to get the 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")) - print(f"stack is: {stack_config}") + # TODO: syntax check the input here + repos_in_scope = stack_config['repos'] + else: + repos_in_scope = all_repos if verbose: - print(f"Repos: {all_repos}") + print(f"Repos: {repos_in_scope}") if stack: print(f"Stack: {stack}") repos = [] - for repo in all_repos: + for repo in repos_in_scope: if include_exclude_check(repo, include, exclude): repos.append(repo) else: diff --git a/setup.py b/setup.py index 19e416b2..759c8c1e 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("requirements.txt", "r", encoding="utf-8") as fh: requirements = fh.read() setup( name='laconic-stack-orchestrator', - version='0.0.5', + version='1.0.9', author='Cerc', author_email='info@cerc.io', license='GNU Affero General Public License', -- 2.45.2