Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
moshez committed Jan 19, 2024
1 parent 8884690 commit 8c9a097
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 73 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dynamic = ["version"]
description = "A gatherer"
readme = "README.rst"
authors = [{name = "Moshe Zadka", email = "[email protected]"}]
dependencies = ["attrs", "incremental", "venusian", "toolz"]
dependencies = ["attrs", "incremental", "venusian", "toolz", "commander_data"]
requires-python = ">=3.11"

[project.optional-dependencies]
Expand Down
32 changes: 14 additions & 18 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --extra=docs --output-file=requirements-docs.txt pyproject.toml
# pip-compile --output-file=- -
#
alabaster==0.7.16
# via sphinx
attrs==23.2.0
# via gather (pyproject.toml)
# via -r -
babel==2.14.0
# via sphinx
certifi==2023.11.17
# via requests
charset-normalizer==3.3.2
# via requests
commander-data==2024.1.19.63931
# via -r -
docutils==0.20.1
# via sphinx
idna==3.6
# via requests
imagesize==1.4.1
# via sphinx
incremental==22.10.0
# via gather (pyproject.toml)
# via -r -
jinja2==3.1.3
# via sphinx
markupsafe==2.1.3
Expand All @@ -35,28 +37,22 @@ requests==2.31.0
snowballstemmer==2.2.0
# via sphinx
sphinx==7.2.6
# via
# gather (pyproject.toml)
# sphinxcontrib-applehelp
# sphinxcontrib-devhelp
# sphinxcontrib-htmlhelp
# sphinxcontrib-qthelp
# sphinxcontrib-serializinghtml
sphinxcontrib-applehelp==1.0.7
# via -r -
sphinxcontrib-applehelp==1.0.8
# via sphinx
sphinxcontrib-devhelp==1.0.5
sphinxcontrib-devhelp==1.0.6
# via sphinx
sphinxcontrib-htmlhelp==2.0.4
sphinxcontrib-htmlhelp==2.0.5
# via sphinx
sphinxcontrib-jsmath==1.0.1
# via sphinx
sphinxcontrib-qthelp==1.0.6
sphinxcontrib-qthelp==1.0.7
# via sphinx
sphinxcontrib-serializinghtml==1.1.9
sphinxcontrib-serializinghtml==1.1.10
# via sphinx
toolz==0.12.0
# via gather (pyproject.toml)
# via -r -
urllib3==2.1.0
# via requests
venusian==3.1.0
# via gather (pyproject.toml)
# via -r -
20 changes: 11 additions & 9 deletions requirements-lint.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --extra=lint --output-file=requirements-lint.txt pyproject.toml
# pip-compile --output-file=- -
#
astroid==3.0.2
# via pylint
attrs==23.2.0
# via gather (pyproject.toml)
# via -r -
black==23.12.1
# via gather (pyproject.toml)
# via -r -
click==8.1.7
# via black
commander-data==2024.1.19.63931
# via -r -
dill==0.3.7
# via pylint
flake8==7.0.0
# via gather (pyproject.toml)
# via -r -
incremental==22.10.0
# via gather (pyproject.toml)
# via -r -
isort==5.13.2
# via pylint
mccabe==0.7.0
Expand All @@ -39,10 +41,10 @@ pycodestyle==2.11.1
pyflakes==3.2.0
# via flake8
pylint==3.0.3
# via gather (pyproject.toml)
# via -r -
tomlkit==0.12.3
# via pylint
toolz==0.12.0
# via gather (pyproject.toml)
# via -r -
venusian==3.1.0
# via gather (pyproject.toml)
# via -r -
16 changes: 9 additions & 7 deletions requirements-mypy.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --extra=mypy --output-file=requirements-mypy.txt pyproject.toml
# pip-compile --output-file=- -
#
attrs==23.2.0
# via gather (pyproject.toml)
# via -r -
commander-data==2024.1.19.63931
# via -r -
incremental==22.10.0
# via gather (pyproject.toml)
# via -r -
mypy==1.8.0
# via gather (pyproject.toml)
# via -r -
mypy-extensions==1.0.0
# via mypy
toolz==0.12.0
# via gather (pyproject.toml)
# via -r -
typing-extensions==4.9.0
# via mypy
venusian==3.1.0
# via gather (pyproject.toml)
# via -r -
20 changes: 11 additions & 9 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --extra=tests --output-file=requirements-tests.txt pyproject.toml
# pip-compile --output-file=- -
#
attrs==23.2.0
# via
# -r -
# automat
# gather (pyproject.toml)
# twisted
# virtue
automat==22.10.0
Expand All @@ -16,34 +16,36 @@ click==8.1.7
# via virtue
colorama==0.4.6
# via virtue
commander-data==2024.1.19.63931
# via -r -
constantly==23.10.4
# via twisted
coverage[toml]==7.4.0
# via gather (pyproject.toml)
# via -r -
hyperlink==21.0.0
# via twisted
idna==3.6
# via hyperlink
incremental==22.10.0
# via
# gather (pyproject.toml)
# -r -
# twisted
pyhamcrest==2.1.0
# via gather (pyproject.toml)
# via -r -
pyrsistent==0.20.0
# via virtue
six==1.16.0
# via automat
toolz==0.12.0
# via gather (pyproject.toml)
# via -r -
twisted==23.10.0
# via virtue
typing-extensions==4.9.0
# via twisted
venusian==3.1.0
# via gather (pyproject.toml)
# via -r -
virtue==2023.8.2
# via gather (pyproject.toml)
# via -r -
zope-interface==6.1
# via twisted

Expand Down
16 changes: 16 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --output-file=- -
#
attrs==23.2.0
# via -r -
commander-data==2024.1.19.63931
# via -r -
incremental==22.10.0
# via -r -
toolz==0.12.0
# via -r -
venusian==3.1.0
# via -r -
31 changes: 3 additions & 28 deletions src/gather/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Sequence, Any, Tuple

import attrs
from commander_data.run import Runner

from .api import Wrapper, unique

Expand Down Expand Up @@ -89,33 +90,6 @@ def set_parser(*, collected, parser=None):
return parser


def _make_safe_run(args):
no_dry_run = getattr(args, "no_dry_run", False)
orig_run = args.orig_run

@functools.wraps(orig_run)
def wrapped_run(cmdargs, **kwargs):
real_kwargs = dict(text=True, check=True, capture_output=True)
real_kwargs.update(kwargs)
LOGGER.info("Running: %s", cmdargs)
try:
return orig_run(cmdargs, **real_kwargs)
except subprocess.CalledProcessError as exc:
exc.add_note(f"STDERR: {exc.stderr}")
exc.add_note(f"STDOUT: {exc.stdout}")
raise

@functools.wraps(orig_run)
def wrapped_dry_run(cmdargs, **kwargs):
LOGGER.info("Running: %s", cmdargs)
LOGGER.info("Dry run, skipping")

unsafe_run = wrapped_run if no_dry_run else wrapped_dry_run
args.run = unsafe_run
args.safe_run = wrapped_run
args.orig_run = orig_run


def run_maybe_dry(
*,
parser,
Expand Down Expand Up @@ -151,7 +125,8 @@ def error(args):
args = parser.parse_args(argv[1:])
args.orig_run = sp_run
args.env = env
_make_safe_run(args)
a_runner = Runner.from_args(args)
args.run, args.safe_run = a_runner.run, a_runner.safe_run
try:
command = args.__gather_command__
except AttributeError:
Expand Down
3 changes: 2 additions & 1 deletion src/gather/example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ def _do_something(args):


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

0 comments on commit 8c9a097

Please sign in to comment.