File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
13
13
- {pull}` 619 ` makes coiled an optional import for tests. Thanks to {user}` erooke ` .
14
14
- {pull}` 620 ` makes tests more flexible about their location. Thanks to {user}` erooke ` .
15
15
- {pull}` 621 ` fixes the pull requests template.
16
+ - {pull}` 627 ` adds a warning when users explicitly pass files to pytask that pytask is
17
+ going to ignore because they do not match a pattern. Happens quite often when the task
18
+ module's name does not start with ` task_ ` .
16
19
17
20
## 0.5.0 - 2024-05-26
18
21
Original file line number Diff line number Diff line change 7
7
from typing import TYPE_CHECKING
8
8
from typing import Any
9
9
10
+ from _pytask .console import console
10
11
from _pytask .pluginmanager import hookimpl
11
12
from _pytask .shared import parse_markers
12
13
from _pytask .shared import parse_paths
@@ -115,3 +116,16 @@ def pytask_parse_config(config: dict[str, Any]) -> None:
115
116
def pytask_post_parse (config : dict [str , Any ]) -> None :
116
117
"""Sort markers alphabetically."""
117
118
config ["markers" ] = {k : config ["markers" ][k ] for k in sorted (config ["markers" ])}
119
+
120
+ # Show a warning to the user if they passed a path pointing to a Python module that
121
+ # does not match the task file pattern.
122
+ for path in config ["paths" ]:
123
+ if path .is_file () and not any (
124
+ path .match (pattern ) for pattern in config ["task_files" ]
125
+ ):
126
+ msg = (
127
+ f"Warning: The path '{ path } ' does not match any of the task file "
128
+ f"patterns in { config ['task_files' ]} . Rename the file or configure a "
129
+ "different 'task_files' pattern if you want to collect it."
130
+ )
131
+ console .print (msg , style = "warning" )
Original file line number Diff line number Diff line change @@ -582,3 +582,17 @@ def task_example() -> Annotated[str, Path("file.txt")]: ...
582
582
result = runner .invoke (cli , [tmp_path .as_posix ()])
583
583
assert result .exit_code == ExitCode .COLLECTION_FAILED
584
584
assert "The task uses multiple ways to parse" in result .output
585
+
586
+
587
+ @pytest .mark .end_to_end ()
588
+ def test_print_warning_if_non_matching_path_is_passed (runner , tmp_path ):
589
+ tmp_path .joinpath ("task.py" ).write_text ("def task_example(): pass" )
590
+ result = runner .invoke (cli , [tmp_path .as_posix ()])
591
+ assert result .exit_code == ExitCode .OK
592
+ assert "Collected 0 tasks" in result .output
593
+ assert "Warning: The path" not in result .output
594
+
595
+ result = runner .invoke (cli , [tmp_path .joinpath ("task.py" ).as_posix ()])
596
+ assert result .exit_code == ExitCode .OK
597
+ assert "Collected 0 tasks" in result .output
598
+ assert "Warning: The path" in result .output
You can’t perform that action at this time.
0 commit comments