minus action prefix: Tollerant action surviving possible execution failure

19 views
Skip to first unread message

jan.vl...@gmail.com

unread,
May 29, 2015, 1:26:45 AM5/29/15
to pytho...@googlegroups.com

Dear doers.

In make, one can prepend "-" to mark a command which is allowed to fail and will not break the whole set of actions.

E.g. following (modified) snippet from Makefile for building PDF documentation tries few times command pdflatex (and all must succeed), then it tries command makeindex, which is allowed to fail without breaking whole task execution, and finally gives few more executions of pdflatex.

%.pdf: %.tex
    pdflatex '$<'
    pdflatex '$<'
    pdflatex '$<'
    -makeindex -s python.ist '$(basename $<).idx'
    pdflatex '$<'
    pdflatex '$<'

Question: is such an option available in doit?

Some ideas and proposals for case it is not possible (yet):

def task_shaker():
    """Does something, survives particular failures"""
    return
    {
        "actions": [
            # simply prefix "-" to the command string
            "-makeindex -s python.ist data.idx",
            # "-" first item for cmd arg list
            ["-", "makeindex", "-s", "python.ist", "data.idx"],
            # CmdAction arg fail_safe=True
            CmdAction("makeindex -s python.ist data.idx", fail_safe=True),
            # "-" prefix recognized even in CmdAction
            CmdAction("-makeindex -s python.ist data.idx", cwd=subdir),
            # CmdFailSafe wrapps cmd-action failure, always pretends success
            CmdFailSafe("makeindex -s python.ist data.idx", cwd=subdir),
            # failsafe wrapps python-actions, always pretends success
            failsafe(makeindex, args, kwargs),
            # minus prefix in cmd-action tupple variant
            ("-", "makeindex -s python.ist data.idx"),
            # minus in terms "next one to fail safe"
            "-",
            "makeindex -s python.ist data.idx",
            # the same, just written on one line
            "-", "makeindex -s python.ist data.idx",
            # minus as "next one to fail safe" works for python-action too
            "-", (makeindex, args, kwargs),
        ]
    }

My preference (from dodo.py author point of view) would be whatever uses the "-".
  1. Last two would suffice
  2. Any other "-" related ones two would be easy to understand.
  3. Adding too many other options could be counter productive but could be done if there are good reasons for that.

With best regards

Jan Vlčinský

Eduardo Schettino

unread,
May 31, 2015, 11:28:38 PM5/31/15
to python-doit
On Fri, May 29, 2015 at 6:24 AM, <jan.vl...@gmail.com> wrote:

Dear doers.

In make, one can prepend "-" to mark a command which is allowed to fail and will not break the whole set of actions.

Question: is such an option available in doit?

No. But it is so easy and clear to do in shell. Just use the `true` command, and put them in a single line.

$  mycmd; true
Using things like this "-" in Make is a perfect example of its cryptic (and impossible to search for in the documentation) syntax.
*doit* is very much against things like that, always preferring to be more verbose and meaningful.
From your options, something like `CmdFailSafe` would be the way to go.

cheers
 

Jan Vlčinský (TamTam Research)

unread,
Jun 11, 2015, 5:14:48 PM6/11/15
to pytho...@googlegroups.com
Eduardo
doit might differ from make and other tools by being more portable (less dependent on system commands available on given operating system). Personally I aim at Linux and secondary at MS Windows (to support my colleagues) and enjoy excellent python package py (with from py.path import local being far more powerfull than pathlib).

For this reason using command true does not fit very well as it is not present on MS Windows by default.

Anyway - we already have one option - using doit.tools.LongRunning - as it ignores result code it serves exactly what we need, at least for command-actions.

I am even thinking of idiom:

from doit.tools import LongRunning as FailSafe


def task_failing():
    """Task with always failing action - always breaking the task"""
    return {
        "actions": [
            "echo Shiny happy people laughing",
            "false",
            "echo which will never happen"
        ],
        "verbosity": 2
    }


def task_failing_safe():
    """Task with always failing action - but failing safe"""
    return {
        "actions": [
            "echo Shiny happy people laughing",
            FailSafe("false"),
            "echo we got over our troubles"
        ],
        "verbosity": 2
    }

Jan


--
You received this message because you are subscribed to the Google Groups "python-doit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-doit...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages