Skip to content

Commit 62077ed

Browse files
authored
Raise error when non-existing task paths are added to the config. (#517)
1 parent 0577393 commit 62077ed

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

docs/source/changes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
88
## 0.4.5 - 2023-12-xx
99

1010
- {pull}`515` enables tests with graphviz in CI. Thanks to {user}`NickCrews`.
11+
- {pull}`517` raises an error when the configuration file contains a non-existing path
12+
(fixes #514). Also adds a warning if the path is configured as a string and not a list
13+
of strings.
1114

1215
## 0.4.4 - 2023-12-04
1316

src/_pytask/shared.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import annotations
33

44
import glob
5+
import warnings
56
from pathlib import Path
67
from typing import Any
78
from typing import Iterable
@@ -46,17 +47,29 @@ def to_list(scalar_or_iter: Any) -> list[Any]:
4647

4748
def parse_paths(x: Any | None) -> list[Path] | None:
4849
"""Parse paths."""
49-
if x is not None:
50-
paths = [Path(p) for p in to_list(x)]
51-
paths = [
52-
Path(p).resolve()
53-
for path in paths
54-
for p in glob.glob(path.as_posix()) # noqa: PTH207
55-
]
56-
out = paths
57-
else:
58-
out = None
59-
return out
50+
if x is None:
51+
return None
52+
53+
if isinstance(x, str):
54+
msg = (
55+
"Specifying paths as a string in 'pyproject.toml' is deprecated and will "
56+
"result in an error in v0.5. Please use a list of strings instead: "
57+
f'["{x}"].'
58+
)
59+
warnings.warn(msg, category=FutureWarning, stacklevel=1)
60+
x = [x]
61+
62+
paths = [Path(p) for p in to_list(x)]
63+
for p in paths:
64+
if not p.exists():
65+
msg = f"The path '{p}' does not exist."
66+
raise FileNotFoundError(msg)
67+
68+
return [
69+
Path(p).resolve()
70+
for path in paths
71+
for p in glob.glob(path.as_posix()) # noqa: PTH207
72+
]
6073

6174

6275
def reduce_names_of_multiple_nodes(

tests/test_config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from pytask import build
7+
from pytask import cli
78
from pytask import ExitCode
89

910

@@ -59,3 +60,15 @@ def test_passing_paths_via_configuration_file(tmp_path, file_or_folder):
5960

6061
assert session.exit_code == ExitCode.OK
6162
assert len(session.tasks) == 1
63+
64+
65+
def test_not_existing_path_in_config(runner, tmp_path):
66+
config = """
67+
[tool.pytask.ini_options]
68+
paths = "not_existing_path"
69+
"""
70+
tmp_path.joinpath("pyproject.toml").write_text(textwrap.dedent(config))
71+
72+
with pytest.warns(FutureWarning, match="Specifying paths as a string"):
73+
result = runner.invoke(cli, [tmp_path.as_posix()])
74+
assert result.exit_code == ExitCode.CONFIGURATION_FAILED

0 commit comments

Comments
 (0)