Skip to content

Commit

Permalink
Merge pull request #45 from elcaminoreal/missing-bits
Browse files Browse the repository at this point in the history
fix example stuff
  • Loading branch information
moshez authored Jan 18, 2024
2 parents a7c9863 + ad408da commit 41c7b75
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
7 changes: 7 additions & 0 deletions src/gather/example/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Example commands and plugins
"""

from gather import entry

ENTRY_DATA = entry.EntryData.create(__name__)
13 changes: 6 additions & 7 deletions src/gather/example/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Run the example commands"""
from gather import entry
from . import ENTRY_DATA

if __name__ != "__main__":
raise ImportError("only run")

from . import main
from gather.commands import run

run(parser=main.get_parser())
entry.dunder_main(
globals_dct=globals(),
command_data=ENTRY_DATA,
)
7 changes: 5 additions & 2 deletions src/gather/example/breakfast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

import gather

from . import ENTRY_DATA

BREAKFAST = gather.Collector()


def breakfast(_args):
@ENTRY_DATA.register()
def breakfast(args):
"""Collect breakfast plugins, make breakfast"""
foods = [klass() for klass in BREAKFAST.collect().values()]
foods = [klass() for klass in gather.unique(BREAKFAST.collect()).values()]
for food in foods:
food.prepare()
for food in foods:
Expand Down
28 changes: 11 additions & 17 deletions src/gather/example/main.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
"""Example commands"""
import sys
import gather
from gather import commands
from gather.commands import add_argument

_COMMANDS_COLLECTOR = gather.Collector()
REGISTER = commands.make_command_register(_COMMANDS_COLLECTOR)
from commander_data.common import LOCAL_PYTHON as PYTHON

from gather.commands import add_argument

def get_parser():
"""Get parser dispatching to example commands"""
return commands.set_parser(collected=_COMMANDS_COLLECTOR.collect())
from . import ENTRY_DATA


@REGISTER(
@ENTRY_DATA.register(
add_argument("--value"),
name="do-something",
)
def _do_something(*, args, env, run):
def _do_something(args):
print(args.value)
print(env["SHELL"])
run([sys.executable, "-c", "print(1+1)"], check=True)
print(args.env["SHELL"])
args.safe_run(PYTHON(c="print(1+1)"), capture_output=False)


@REGISTER(
@ENTRY_DATA.register(
add_argument("--no-dry-run", action="store_true"),
name="do-something-else",
)
def _do_something_else(*, args, env, run):
def _do_something_else(args):
print(args.no_dry_run)
print(env["SHELL"])
run([sys.executable, "-c", "print(1+1)"], check=True)
print(args.env["SHELL"])
args.safe_run(PYTHON(c="print(1+1)"), capture_output=False)

0 comments on commit 41c7b75

Please sign in to comment.