From 143e9075f93d04a3601b0e3302214d851e1b6147 Mon Sep 17 00:00:00 2001 From: Nat Noordanus Date: Sat, 23 Sep 2023 15:45:31 +0200 Subject: [PATCH] Allow use_exec option with expr tasks --- docs/tasks/options.rst | 2 +- docs/tasks/task_types/expr.rst | 2 +- poethepoet/task/expr.py | 1 + pyproject.toml | 2 +- tests/fixtures/expr_project/pyproject.toml | 9 +++++---- tests/test_expr_task.py | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/tasks/options.rst b/docs/tasks/options.rst index d342f41c..3af75b0c 100644 --- a/docs/tasks/options.rst +++ b/docs/tasks/options.rst @@ -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 diff --git a/docs/tasks/task_types/expr.rst b/docs/tasks/task_types/expr.rst index c12ef7a2..886d346e 100644 --- a/docs/tasks/task_types/expr.rst +++ b/docs/tasks/task_types/expr.rst @@ -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: diff --git a/poethepoet/task/expr.py b/poethepoet/task/expr.py index c65ebd91..5303a188 100644 --- a/poethepoet/task/expr.py +++ b/poethepoet/task/expr.py @@ -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( diff --git a/pyproject.toml b/pyproject.toml index 6825e1d0..153d8cf3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/tests/fixtures/expr_project/pyproject.toml b/tests/fixtures/expr_project/pyproject.toml index 8ea183d4..9a2820a0 100644 --- a/tests/fixtures/expr_project/pyproject.toml +++ b/tests/fixtures/expr_project/pyproject.toml @@ -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" @@ -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" diff --git a/tests/test_expr_task.py b/tests/test_expr_task.py index e866bfc3..d0d891e7 100644 --- a/tests/test_expr_task.py +++ b/tests/test_expr_task.py @@ -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 == ""