Skip to content

Commit

Permalink
Fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasraabe committed Dec 6, 2023
1 parent 4b613df commit a6a229f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
6 changes: 6 additions & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
releases are available on [PyPI](https://pypi.org/project/pytask) and
[Anaconda.org](https://anaconda.org/conda-forge/pytask).

## 0.4.5 - 2023-12-xx

- {pull}`xxx` 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

- {pull}`509` improves the documentation.
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,6 @@ exclude_also = [
"\\.\\.\\.",
"def __repr__",
]

[tool.pytask.ini_options]
paths = "does_not_exist"
1 change: 0 additions & 1 deletion src/_pytask/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def pytask_configure(
def pytask_parse_config(config: dict[str, Any]) -> None:
"""Parse the configuration."""
config["root"].joinpath(".pytask").mkdir(exist_ok=True, parents=True)

config["paths"] = parse_paths(config["paths"])

config["markers"] = {
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

0 comments on commit a6a229f

Please sign in to comment.