Skip to content

Commit

Permalink
Write readme section for multiple option & make tests work better on …
Browse files Browse the repository at this point in the history
…windows
  • Loading branch information
nat-n committed Jun 10, 2022
1 parent 20814f7 commit 6e4d654
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 35 deletions.
25 changes: 25 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,31 @@ Named arguments support the following configuration options:
If set to true then the argument becomes a position argument instead of an option
argument. Note that positional arguments may not have type *bool*.

- **multiple** : Union[bool, int]
If the multiple option is set to true on a positional or option argument then that
argument will accept multiple values.

If set to a number, then the argument will accept exactly that number of values.

For positional aguments, only the last positional argument may have the multiple
option set.

The multiple option is not compatible with arguments with type boolean since
these are interpreted as flags. However multiple ones or zeros can be passed to an
argument of type "integer" for similar effect.

The values provided to an argument with the multiple option set are available on
the environment as a string of whitespace separated values. For script tasks, the
values will be provided to your python function as a list of values. In a cmd task
the values can be passed as separate arugments to the task via templating as in the
following example.

.. code-block:: toml
[tool.poe.tasks.save]
cmd = "echo ${FILE_PATHS}"
args = [{ name = "FILE_PATHS", positional = true, multiple = true }]
- **required** : bool
If true then not providing the argument will result in an error. Arguments are not
required by default.
Expand Down
12 changes: 6 additions & 6 deletions tests/fixtures/example_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ env.DEST = "MARS"


[tool.poe.tasks.echo]
cmd = "echo POE_ROOT:$POE_ROOT ${BEST_PASSWORD}, task_args:"
cmd = "poe_test_echo POE_ROOT:$POE_ROOT ${BEST_PASSWORD}, task_args:"
help = "It says what you say"
env = { BEST_PASSWORD = "Password1" }


[tool.poe.tasks]
show_env = "env"
show_env = "poe_test_env"
greet = { script = "dummy_package:main" }
greet-shouty = { script = "dummy_package:main(upper=True)" }

Expand All @@ -37,13 +37,13 @@ echo "my life got flipped;
echo "bam bam baaam bam"
"""

part1 = "echo 'Hello'"
_part2.cmd = "echo '${SUBJECT}!'"
part1 = "poe_test_echo 'Hello'"
_part2.cmd = "poe_test_echo '${SUBJECT}!'"
_part2.env = { SUBJECT = "World" }
composite_task.sequence = [
["part1", "_part2"],
# wrapping in arrays means we can have different types of task in the sequence
[{cmd = "echo '${SMILEY}!'"}]
[{cmd = "poe_test_echo '${SMILEY}!'"}]
]
# env var is inherited by subtask
composite_task.env = { SMILEY = ":)" }
Expand All @@ -54,7 +54,7 @@ greet-multiple.sequence = ["dummy_package:main('Tom')", "dummy_package:main('Jer
greet-multiple.default_item_type = "script"

travel = [
{ cmd = "echo 'from $PLANET to'" },
{ cmd = "poe_test_echo 'from $PLANET to'" },
{ script = "dummy_package:print_var('DEST')" }
]

Expand Down
10 changes: 5 additions & 5 deletions tests/fixtures/graphs_project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[tool.poe.tasks]

greet = "echo hello"
greet = "poe_test_echo hello"

_noop.shell = ":"
_about = "echo about"
_do_setup = "echo here we go..."
_about = "poe_test_echo about"
_do_setup = "poe_test_echo here we go..."


[tool.poe.tasks.think]
cmd = "echo Thinking $first_thing and $subject2"
shell = "echo Thinking $first_thing and $subject2"
deps = ["_noop", "_do_setup"]
uses = { first_thing = "_about $subject1" }
args = [{ name = "subject1", positional = true }, { name = "subject2", positional = true }]

[tool.poe.tasks.deep-graph-with-args]
cmd = "echo $greeting1 and $greeting2"
shell = "echo $greeting1 and $greeting2"
deps = ["_do_setup", "think $subject1 $subject2"]
uses = { greeting1 = "greet $subject1", greeting2 = "greet $subject2"}
args = ["subject1", "subject2"]
2 changes: 1 addition & 1 deletion tests/fixtures/high_verbosity/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
verbosity = 1

[tool.poe.tasks]
test = "echo Hello there!"
test = "poe_test_echo Hello there!"
2 changes: 1 addition & 1 deletion tests/fixtures/low_verbosity/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
verbosity = -1

[tool.poe.tasks]
test = "echo Hello there!"
test = "poe_test_echo Hello there!"
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cowsay = "../../packages/python_cowsay-1.0.1-py3-none-any.whl"
poetry_command = ""

[tool.poe.tasks]
echo = { cmd = "echo", help = "It's like echo"}
echo = { cmd = "poe_test_echo", help = "It's like echo"}
cow-greet = "cowsay 'good day sir!'"

[build-system]
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/poetry_plugin_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pre_env_info = "echo 'THIS IS YOUR ENV!'"
post_env_info = "echo 'THAT WAS YOUR ENV!'"

[tool.poe.tasks]
echo = { cmd = "echo", help = "It's like echo"}
echo = { cmd = "poe_test_echo", help = "It's like echo"}
cow-greet = "cowsay 'good day sir!'"
cow-cheese.shell = "import cowsay; print(list(cowsay.char_names)[1])"
cow-cheese.interpreter = "python"
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/scripts_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ default_array_item_task_type = "cmd"

[tool.poe.tasks]
# Interpret subtasks as cmd instead of ref
composite_task = ["echo Hello", "echo World!"]
composite_task = ["poe_test_echo Hello", "poe_test_echo World!"]

# test_setting_default_task_type
echo-args = "pkg:echo_args"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_version_option(run_poe):

def test_dry_run(run_poe_subproc):
result = run_poe_subproc("-d", "show_env")
assert result.capture == f"Poe => env\n"
assert result.capture == f"Poe => poe_test_env\n"
assert result.stdout == ""
assert result.stderr == ""

Expand Down
10 changes: 7 additions & 3 deletions tests/test_cmd_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ def test_cmd_alias_env_var(run_poe_subproc):
assert result.stderr == ""


def test_cmd_multiple_value_arg(run_poe_subproc):
def test_cmd_task_with_multiple_value_arg(run_poe_subproc, is_windows):
result = run_poe_subproc("multiple-value-arg", "hey", "1", "2", "3", project="cmds")
assert result.capture == "Poe => poe_test_echo first: hey second: 1 2 3\n"
assert result.stdout == "first: hey second: 1 2 3\n"
if is_windows:
assert result.capture == 'Poe => poe_test_echo "first: hey second: 1 2 3"\n'
assert result.stdout == '"first: hey second: 1 2 3\n"'
else:
assert result.capture == "Poe => poe_test_echo first: hey second: 1 2 3\n"
assert result.stdout == "first: hey second: 1 2 3\n"
assert result.stderr == ""
10 changes: 5 additions & 5 deletions tests/test_graph_execution.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
def test_call_attr_func(run_poe_subproc):
result = run_poe_subproc("deep-graph-with-args", project="graphs")
assert result.capture == (
"Poe => echo here we go...\n"
"Poe => poe_test_echo here we go...\n"
"Poe => :\n"
"Poe <= echo about\n"
"Poe <= echo hello\n"
"Poe => echo Thinking about and\n"
"Poe => echo hello and hello\n"
"Poe <= poe_test_echo about\n"
"Poe <= poe_test_echo hello\n"
"Poe => echo Thinking $first_thing and $subject2\n"
"Poe => echo $greeting1 and $greeting2\n"
)
assert result.stdout == (
"here we go...\n" "Thinking about and\n" "hello and hello\n"
Expand Down
17 changes: 12 additions & 5 deletions tests/test_poe_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,25 @@ def test_setting_default_task_type(run_poe_subproc, projects, esc_prefix):

def test_setting_default_array_item_task_type(run_poe_subproc):
result = run_poe_subproc("composite_task", project="scripts")
assert result.capture == f"Poe => echo Hello\nPoe => echo World!\n"
assert (
result.capture == f"Poe => poe_test_echo Hello\nPoe => poe_test_echo World!\n"
)
assert result.stdout == f"Hello\nWorld!\n"
assert result.stderr == ""


def test_setting_global_env_vars(run_poe_subproc, is_windows):
result = run_poe_subproc("travel")
if is_windows:
assert result.capture == f"Poe => echo 'from EARTH to'\nPoe => travel[1]\n"
assert (
result.capture
== f"Poe => poe_test_echo 'from EARTH to'\nPoe => travel[1]\n"
)
assert result.stdout == f"'from EARTH to'\nMARS\n"
else:
assert result.capture == f"Poe => echo from EARTH to\nPoe => travel[1]\n"
assert (
result.capture == f"Poe => poe_test_echo from EARTH to\nPoe => travel[1]\n"
)
assert result.stdout == f"from EARTH to\nMARS\n"
assert result.stderr == ""

Expand All @@ -51,7 +58,7 @@ def test_override_default_verbosity(run_poe_subproc, low_verbosity_project_path)
"test",
cwd=low_verbosity_project_path,
)
assert result.capture == "Poe => echo Hello there!\n"
assert result.capture == "Poe => poe_test_echo Hello there!\n"
assert result.stdout == "Hello there!\n"
assert result.stderr == ""

Expand All @@ -62,7 +69,7 @@ def test_partially_decrease_verbosity(run_poe_subproc, high_verbosity_project_pa
"test",
cwd=high_verbosity_project_path,
)
assert result.capture == "Poe => echo Hello there!\n"
assert result.capture == "Poe => poe_test_echo Hello there!\n"
assert result.stdout == "Hello there!\n"
assert result.stderr == ""

Expand Down
4 changes: 2 additions & 2 deletions tests/test_poetry_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_task_accepts_any_args(run_poetry, projects, setup_poetry_project):
cwd=projects["poetry_plugin"],
)
assert result.stdout == (
"Poe => echo --lol=:D --version --help\n--lol=:D --version --help\n"
"Poe => poe_test_echo --lol=:D --version --help\n--lol=:D --version --help\n"
)
# assert result.stderr == ""

Expand All @@ -83,7 +83,7 @@ def test_running_tasks_without_poe_command_prefix(
cwd=projects["poetry_plugin/empty_prefix"].parent,
)
assert result.stdout == (
"Poe => echo --lol=:D --version --help\n--lol=:D --version --help\n"
"Poe => poe_test_echo --lol=:D --version --help\n--lol=:D --version --help\n"
)
# assert result.stderr == ""

Expand Down
2 changes: 1 addition & 1 deletion tests/test_sequence_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_a_script_sequence_task_with_args(run_poe_subproc, esc_prefix):
assert result.stderr == ""


def test_cmd_multiple_value_arg(run_poe_subproc):
def test_sequence_task_with_multiple_value_arg(run_poe_subproc):
result = run_poe_subproc(
"multiple-value-arg", "hey", "1", "2", "3", project="sequences"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_shell_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_global_interpreter_config(run_poe_subproc, projects):
assert result.stderr == ""


def test_cmd_multiple_value_arg(run_poe_subproc):
def test_shell_task_with_multiple_value_arg(run_poe_subproc):
result = run_poe_subproc(
"multiple-value-arg", "hey", "1", "2", "3", project="shells"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_task_running.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def test_ref_task(run_poe_subproc, projects, esc_prefix):
result = run_poe_subproc("also_echo", "foo", "!")
assert (
result.capture
== f"Poe => echo POE_ROOT:{projects['example']} Password1, task_args: foo !\n"
== f"Poe => poe_test_echo POE_ROOT:{projects['example']} Password1, task_args: foo !\n"
)
assert (
result.stdout == f"POE_ROOT:{projects['example']} Password1, task_args: foo !\n"
Expand Down

0 comments on commit 6e4d654

Please sign in to comment.