Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
faermanj committed Nov 2, 2023
1 parent 9ddf38b commit a486fb5
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 881 deletions.
3 changes: 1 addition & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
tasks:
- name: CLI
init: |
cd ./up_cli
cd ./upcli
poetry install
alias up='poetry run up'
command: |
echo "Ready at $(date)"
vscode:
extensions:
- ms-azuretools.vscode-docker
Expand Down
25 changes: 25 additions & 0 deletions install_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -ex

rm -f */poetry.lock
rm -rf /workspace/.pyenv_mirror/poetry/virtualenvs/*

pushd uplib
poetry config virtualenvs.create false
poetry install -vvv
popd

pushd up_ansible
poetry config virtualenvs.create false
poetry install -vvv
popd

pushd up_splat
poetry install
popd

pushd upcli
poetry install
popd

echo "done installing all"
427 changes: 9 additions & 418 deletions up_ansible/poetry.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions up_ansible/up_ansible/run_for_prompt.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from uplib import hookimpl
from uplib.match import match_prompt
from uplib.containers import RunConfig
import uplib as up

def mk_run_config(prompt):
result = RunConfig(
result = up.RunConfig(
image="cytopia/ansible:latest",
command=prompt)
return result

@hookimpl

@up.hookimpl
def run_for_prompt(prompt):
return match_prompt(mk_run_config, prompt, "ansible")
return up.match_prompt(mk_run_config, prompt, "ansible")
15 changes: 14 additions & 1 deletion up_splat/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions up_splat/up_splat/run_for_prompt.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from uplib import hookimpl
from uplib.match import match_prompt
from uplib.containers import RunConfig
import uplib as up


def mk_run_config(prompt):
result = RunConfig(
result = up.RunConfig(
image="fedora",
command=['echo', 'Thanks for trying UP: '] + prompt)
return result

@hookimpl
@up.hookimpl
def run_for_prompt(prompt):
return match_prompt(mk_run_config, prompt, "splat")
return up.match_prompt(mk_run_config, prompt, "splat")

456 changes: 16 additions & 440 deletions upcli/poetry.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions uplib/uplib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import pluggy
from typing import TypeAlias

Context:TypeAlias = dict[str, str]
Prompt:TypeAlias = list[str]

Context: TypeAlias = dict[str, str]
Prompt: TypeAlias = list[str]


hookspec = pluggy.HookspecMarker("up")
hookimpl = pluggy.HookimplMarker("up")
pm = pluggy.PluginManager("up")

from .match import does_match, match_prompt
from .containers import RunConfig

__all__ = [Context,
Prompt,
RunConfig,
hookspec,
hookimpl,
pm,
does_match,
match_prompt]
6 changes: 4 additions & 2 deletions uplib/uplib/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
from typing import Callable
from .containers import RunConfig


def does_match(prompt: Prompt, args) -> bool:
for p, a in zip(prompt, args):
if p != a:
return False
return True


def match_prompt(mk_run_config: Callable[[], RunConfig],
prompt: Prompt,
prompt: Prompt,
*args) -> list[RunConfig]:
if not prompt:
return None
if does_match(prompt, args):
log.info(f"MATCH: prompt={prompt}, args={args}")
return [mk_run_config(prompt)]
log.info(f"NO MATCH: prompt={prompt}, args={args}")
return None
return None
10 changes: 6 additions & 4 deletions uplib/uplib/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import pkgutil
import pluggy

from . import hookspec
from . import hookspec
from .containers import Containers
from .hookspecs import run_for_prompt


def load_plugins(context):
log.info("Loading plugins")
discovered_plugins = {
Expand All @@ -15,9 +16,10 @@ def load_plugins(context):
in pkgutil.iter_modules()
if name.startswith('up_')
}
log.info("Discovered %s plugins: %s", len(discovered_plugins), discovered_plugins)
log.info("Discovered %s plugins: %s", len(
discovered_plugins), discovered_plugins)
# create a manager and add the spec
# pm.load_setuptools_entrypoints("up")
# pm.add_hookspecs(hookspec)
log.debug("Plugins loaded.")
log.debug(str(pm.get_plugins()))
# log.debug("Plugins loaded.")
# log.debug(str(pm.get_plugins()))

0 comments on commit a486fb5

Please sign in to comment.