Skip to content

Raise error when non-existing task paths are added to the config. #517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
## 0.4.5 - 2023-12-xx

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

## 0.4.4 - 2023-12-04

Expand Down
35 changes: 24 additions & 11 deletions src/_pytask/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import glob
import warnings
from pathlib import Path
from typing import Any
from typing import Iterable
Expand Down Expand Up @@ -46,17 +47,29 @@ def to_list(scalar_or_iter: Any) -> list[Any]:

def parse_paths(x: Any | None) -> list[Path] | None:
"""Parse paths."""
if x is not None:
paths = [Path(p) for p in to_list(x)]
paths = [
Path(p).resolve()
for path in paths
for p in glob.glob(path.as_posix()) # noqa: PTH207
]
out = paths
else:
out = None
return out
if x is None:
return None

if isinstance(x, str):
msg = (
"Specifying paths as a string in 'pyproject.toml' is deprecated and will "
"result in an error in v0.5. Please use a list of strings instead: "
f'["{x}"].'
)
warnings.warn(msg, category=FutureWarning, stacklevel=1)
x = [x]

paths = [Path(p) for p in to_list(x)]
for p in paths:
if not p.exists():
msg = f"The path '{p}' does not exist."
raise FileNotFoundError(msg)

return [
Path(p).resolve()
for path in paths
for p in glob.glob(path.as_posix()) # noqa: PTH207
]


def reduce_names_of_multiple_nodes(
Expand Down
13 changes: 13 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from pytask import build
from pytask import cli
from pytask import ExitCode


Expand Down Expand Up @@ -59,3 +60,15 @@ def test_passing_paths_via_configuration_file(tmp_path, file_or_folder):

assert session.exit_code == ExitCode.OK
assert len(session.tasks) == 1


def test_not_existing_path_in_config(runner, tmp_path):
config = """
[tool.pytask.ini_options]
paths = "not_existing_path"
"""
tmp_path.joinpath("pyproject.toml").write_text(textwrap.dedent(config))

with pytest.warns(FutureWarning, match="Specifying paths as a string"):
result = runner.invoke(cli, [tmp_path.as_posix()])
assert result.exit_code == ExitCode.CONFIGURATION_FAILED