Skip to content

Commit 2891130

Browse files
authored
Merge 913b6bb into 03fb027
2 parents 03fb027 + 913b6bb commit 2891130

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

docs/source/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
1212
with path nodes.
1313
- {pull}`485` adds missing steps to unconfigure pytask after the job is done which
1414
caused flaky tests.
15+
- {pull}`486` adds default names to {class}`~pytask.PPathNode`.
1516

1617
## 0.4.2 - 2023-11-8
1718

src/_pytask/collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def pytask_collect_node(session: Session, path: Path, node_info: NodeInfo) -> PN
344344
node.path, session.config["check_casing_of_paths"]
345345
)
346346

347-
if isinstance(node, PathNode) and (
347+
if isinstance(node, PPathNode) and (
348348
not node.name or node.name == node.path.as_posix()
349349
):
350350
# Shorten name of PathNodes.

src/_pytask/nodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class PathNode(PPathNode):
157157
158158
"""
159159

160-
name: str
161160
path: Path
161+
name: str = ""
162162

163163
@property
164164
def signature(self) -> str:
@@ -298,8 +298,8 @@ class PickleNode:
298298
299299
"""
300300

301-
name: str
302301
path: Path
302+
name: str = ""
303303

304304
@property
305305
def signature(self) -> str:

tests/test_collect.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ def task_example(path: Annotated[Path, Path("file.txt"), Product]) -> None: ...
578578
"node",
579579
[
580580
"Path(__file__).parent",
581-
"PathNode(name='path', path=Path(__file__).parent)",
582-
"PickleNode(name='', path=Path(__file__).parent)",
581+
"PathNode(path=Path(__file__).parent)",
582+
"PickleNode(path=Path(__file__).parent)",
583583
],
584584
)
585585
def test_error_when_path_dependency_is_directory(runner, tmp_path, node):
@@ -599,8 +599,8 @@ def task_example(path = {node}): ...
599599
"node",
600600
[
601601
"Path(__file__).parent",
602-
"PathNode(name='path', path=Path(__file__).parent)",
603-
"PickleNode(name='', path=Path(__file__).parent)",
602+
"PathNode(path=Path(__file__).parent)",
603+
"PickleNode(path=Path(__file__).parent)",
604604
],
605605
)
606606
def test_error_when_path_product_is_directory(runner, tmp_path, node):
@@ -616,3 +616,28 @@ def task_example(path: Annotated[Any, Product] = {node}): ...
616616
result = runner.invoke(cli, [tmp_path.as_posix()])
617617
assert result.exit_code == ExitCode.COLLECTION_FAILED
618618
assert all(i in result.output for i in ("only", "files", "are", "allowed"))
619+
620+
621+
@pytest.mark.parametrize(
622+
"node",
623+
[
624+
"Path(__file__).parent / 'file.txt'",
625+
"PathNode(path=Path(__file__).parent / 'file.txt')",
626+
"PickleNode(path=Path(__file__).parent / 'file.txt')",
627+
],
628+
)
629+
def test_default_name_of_path_nodes(tmp_path, node):
630+
source = f"""
631+
from pathlib import Path
632+
from pytask import PickleNode, Product, PathNode
633+
from typing_extensions import Annotated
634+
from typing import Any
635+
636+
def task_example() -> Annotated[str, {node}]:
637+
return "Hello, World!"
638+
"""
639+
tmp_path.joinpath("task_example.py").write_text(textwrap.dedent(source))
640+
session = build(paths=tmp_path)
641+
assert session.exit_code == ExitCode.OK
642+
assert tmp_path.joinpath("file.txt").exists()
643+
assert session.tasks[0].produces["return"].name == tmp_path.name + "/file.txt"

0 commit comments

Comments
 (0)