Skip to content

Commit

Permalink
Allow use_exec option with expr tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-n committed Sep 23, 2023
1 parent f487993 commit 143e907
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/tasks/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The following options can be configured on your tasks and are not specific to an

.. attention::

This option is only applicable to **cmd** and **script** tasks, and it implies the task in question cannot be referenced by another task.
This option is only applicable to **cmd**, **script**, and **expr** tasks, and it implies the task in question cannot be referenced by another task.


Setting task specific environment variables
Expand Down
2 changes: 1 addition & 1 deletion docs/tasks/task_types/expr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
Available task options
----------------------

``expr`` tasks support all of the :doc:`standard task options <../options>` with the exception of ``use_exec``.
``expr`` tasks support all of the :doc:`standard task options <../options>`.

The following options are also accepted:

Expand Down
1 change: 1 addition & 0 deletions poethepoet/task/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ExprTask(PoeTask):
__options__: Dict[str, Union[Type, Tuple[Type, ...]]] = {
"imports": list,
"assert": (bool, int),
"use_exec": bool,
}

def _handle_run(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ _clean_docs.script = "shutil:rmtree('docs/_build', ignore_errors=1)"

[tool.poe.tasks.test-quick]
help = "Run unit and feature tests, excluding slow ones"
cmd = "pytest -m \"not slow\""
cmd = "pytest -m 'not slow'"

[tool.poe.tasks.types]
help = "Run the type checker"
Expand Down
9 changes: 5 additions & 4 deletions tests/fixtures/expr_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ args = [{ name = "power_level", positional = true, type = "integer", default = 4
expr = """"power level is " + (f"only {sys.argv[1]}" if int(sys.argv[1]) <= 9000 else 'over nine thousand!') """

[tool.poe.tasks.expr_with_env_vars]
expr = "[${VAR_FOO} * int(${VAR_BAR})][0] + (f'{${VAR_BAZ}}')"
expr = "[${VAR_FOO} * int(${VAR_BAR})][0] + (f'{${VAR_BAZ}}') + '${NOTHING}'"

[tool.poe.tasks.expr_with_imports]
help = "check if the argument looks like an email address"
Expand All @@ -17,9 +17,10 @@ env.EMAIL.default = 'user@example.com'
assert = false

[tool.poe.tasks.expr_with_assert]
expr = "min_value < 3"
args = [{ name = "min_value", positional = true, type = "integer", required = true}]
assert = true
expr = "min_value < 3"
args = [{ name = "min_value", positional = true, type = "integer", required = true}]
assert = true
use_exec = true

[tool.poe.tasks]
_days_since_incident.expr = "0"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_expr_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_expr_with_env_vars(run_poe_subproc):
)
assert (
result.capture
== "Poe => [${VAR_FOO} * int(${VAR_BAR})][0] + (f'{${VAR_BAZ}}')\n"
== "Poe => [${VAR_FOO} * int(${VAR_BAR})][0] + (f'{${VAR_BAZ}}') + '${NOTHING}'\n"
)
assert result.stdout == "foofooboo\n"
assert result.stderr == ""
Expand Down

0 comments on commit 143e907

Please sign in to comment.