Skip to content

Commit e15dfc9

Browse files
authored
Fix bug when passing no path on the command line. (#337)
1 parent 88326dd commit e15dfc9

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

docs/source/changes.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
55
releases are available on [PyPI](https://pypi.org/project/pytask) and
66
[Anaconda.org](https://anaconda.org/conda-forge/pytask).
77

8-
## 0.3.0 - 2022-12-xx
8+
## 0.3.1 - 2023-12-25
9+
10+
- {pull}`337` fixes fallback to root path when `pytask collect` or `pytask clean` are
11+
used without paths.
12+
13+
## 0.3.0 - 2023-12-22
914

1015
- {pull}`313` refactors the configuration. INI configurations are no longer supported.
1116
- {pull}`326` fixes the badge for status of the workflow.

src/_pytask/config_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def set_defaults_from_config(
3232
context.params["config"] = value
3333
context.params["root"] = context.params["config"].parent
3434
else:
35-
if context.params["paths"] is None:
35+
if not context.params["paths"]:
3636
context.params["paths"] = (Path.cwd(),)
3737

3838
context.params["paths"] = parse_paths(context.params["paths"])

tests/test_clean.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from __future__ import annotations
22

3+
import os
34
import subprocess
45
import textwrap
6+
from pathlib import Path
57

68
import pytest
79
from _pytask.git import init_repo
@@ -54,6 +56,19 @@ def task_write_text(produces):
5456
return tmp_path
5557

5658

59+
@pytest.mark.end_to_end()
60+
def test_clean_with_auto_collect(project, runner):
61+
cwd = Path.cwd()
62+
os.chdir(project)
63+
result = runner.invoke(cli, ["clean"])
64+
os.chdir(cwd)
65+
66+
assert result.exit_code == ExitCode.OK
67+
text_without_linebreaks = result.output.replace("\n", "")
68+
assert "to_be_deleted_file_1.txt" in text_without_linebreaks
69+
assert "to_be_deleted_file_2.txt" in text_without_linebreaks
70+
71+
5772
@pytest.mark.end_to_end()
5873
@pytest.mark.parametrize("flag", ["-e", "--exclude"])
5974
@pytest.mark.parametrize("pattern", ["*_1.txt", "to_be_deleted_file_[1]*"])

tests/test_collect_command.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
import textwrap
45
from pathlib import Path
56

@@ -49,6 +50,32 @@ def task_example():
4950
assert "out.txt>" in captured
5051

5152

53+
@pytest.mark.end_to_end()
54+
def test_collect_task_in_root_dir(runner, tmp_path):
55+
source = """
56+
import pytask
57+
58+
@pytask.mark.depends_on("in.txt")
59+
@pytask.mark.produces("out.txt")
60+
def task_example():
61+
pass
62+
"""
63+
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
64+
tmp_path.joinpath("in.txt").touch()
65+
66+
cwd = Path.cwd()
67+
os.chdir(tmp_path)
68+
result = runner.invoke(cli, ["collect"])
69+
os.chdir(cwd)
70+
71+
assert result.exit_code == ExitCode.OK
72+
captured = result.output.replace("\n", "").replace(" ", "")
73+
assert "<Module" in captured
74+
assert "task_module.py>" in captured
75+
assert "<Function" in captured
76+
assert "task_example>" in captured
77+
78+
5279
@pytest.mark.end_to_end()
5380
def test_collect_parametrized_tasks(runner, tmp_path):
5481
source = """

tests/test_execute.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from __future__ import annotations
22

3+
import os
34
import re
45
import subprocess
56
import sys
67
import textwrap
8+
from pathlib import Path
79

810
import pytest
911
from _pytask.exceptions import NodeNotFoundError
@@ -20,6 +22,17 @@ def test_python_m_pytask(tmp_path):
2022
subprocess.run(["python", "-m", "pytask", tmp_path.as_posix()], check=True)
2123

2224

25+
@pytest.mark.end_to_end()
26+
def test_execute_w_autocollect(runner, tmp_path):
27+
tmp_path.joinpath("task_module.py").write_text("def task_example(): pass")
28+
cwd = Path.cwd()
29+
os.chdir(tmp_path)
30+
result = runner.invoke(cli)
31+
os.chdir(cwd)
32+
assert result.exit_code == ExitCode.OK
33+
assert "1 Succeeded" in result.output
34+
35+
2336
@pytest.mark.end_to_end()
2437
def test_task_did_not_produce_node(tmp_path):
2538
source = """

0 commit comments

Comments
 (0)