Skip to content

Rename graph.py to dag_command.py and improve collect_command.py. #451

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 2 commits into from
Oct 16, 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
1 change: 1 addition & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
## 0.4.2 - 2023-xx-xx

- {pull}`449` simplifies the code building the plugin manager.
- {pull}`451` improves `collect_command.py` and renames `graph.py` to `dag_command.py`.

## 0.4.1 - 2023-10-11

Expand Down
4 changes: 2 additions & 2 deletions src/_pytask/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def pytask_add_hooks(pm: pluggy.PluginManager) -> None:
from _pytask import database
from _pytask import debugging
from _pytask import execute
from _pytask import graph
from _pytask import dag_command
from _pytask import live
from _pytask import logging
from _pytask import mark
Expand All @@ -76,7 +76,7 @@ def pytask_add_hooks(pm: pluggy.PluginManager) -> None:
pm.register(database)
pm.register(debugging)
pm.register(execute)
pm.register(graph)
pm.register(dag_command)
pm.register(live)
pm.register(logging)
pm.register(mark)
Expand Down
44 changes: 19 additions & 25 deletions src/_pytask/collect_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import sys
from collections import defaultdict
from pathlib import Path
from typing import Any
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -36,6 +35,7 @@


if TYPE_CHECKING:
from pathlib import Path
from typing import NoReturn


Expand Down Expand Up @@ -149,7 +149,7 @@ def _organize_tasks(tasks: list[PTaskWithPath]) -> dict[Path, list[PTaskWithPath
return sorted_dict


def _print_collected_tasks( # noqa: PLR0912
def _print_collected_tasks(
dictionary: dict[Path, list[PTaskWithPath]],
show_nodes: bool,
editor_url_scheme: str,
Expand Down Expand Up @@ -193,37 +193,31 @@ def _print_collected_tasks( # noqa: PLR0912
)

if show_nodes:
nodes: list[PNode] = list(
tree_leaves(task.depends_on) # type: ignore[arg-type]
)
sorted_nodes = sorted(nodes, key=lambda x: x.name)
for node in sorted_nodes:
deps: list[PNode] = list(tree_leaves(task.depends_on)) # type: ignore[arg-type]
for node in sorted(
deps,
key=(
lambda x: x.path.as_posix()
if isinstance(x, PPathNode)
else x.name
),
):
if isinstance(node, PPathNode):
if node.path.as_posix() in node.name:
reduced_node_name = str(
relative_to(node.path, common_ancestor)
)
else:
reduced_node_name = node.name
reduced_node_name = str(relative_to(node.path, common_ancestor))
url_style = create_url_style_for_path(
node.path, editor_url_scheme
)
text = Text(reduced_node_name, style=url_style)
else:
try:
path_part, rest = node.name.split("::", maxsplit=1)
reduced_path = str(
relative_to(Path(path_part), common_ancestor)
)
text = Text(reduced_path + "::" + rest)
except Exception: # noqa: BLE001
text = Text(node.name)

text = Text(node.name)
task_branch.add(Text.assemble(FILE_ICON, "<Dependency ", text, ">"))

for node in sorted( # type: ignore[assignment]
tree_leaves(task.produces),
key=lambda x: x.path if isinstance(x, PPathNode) else x.name, # type: ignore[attr-defined]
products: list[PNode] = list(tree_leaves(task.produces)) # type: ignore[arg-type]
for node in sorted(
products,
key=lambda x: x.path.as_posix()
if isinstance(x, PPathNode)
else x.name,
):
if isinstance(node, PPathNode):
reduced_node_name = str(relative_to(node.path, common_ancestor))
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/pytask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from _pytask.compat import import_optional_dependency
from _pytask.config import hookimpl
from _pytask.console import console
from _pytask.dag_command import build_dag
from _pytask.database_utils import BaseTable
from _pytask.database_utils import create_database
from _pytask.database_utils import DatabaseSession
Expand All @@ -25,7 +26,6 @@
from _pytask.exceptions import NodeNotFoundError
from _pytask.exceptions import PytaskError
from _pytask.exceptions import ResolvingDependenciesError
from _pytask.graph import build_dag
from _pytask.mark import Mark
from _pytask.mark import MARK_GEN as mark # noqa: N811
from _pytask.mark import MarkDecorator
Expand Down
2 changes: 1 addition & 1 deletion tests/test_graph.py → tests/test_dag_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import textwrap

import pytest
from _pytask.graph import _RankDirection
from _pytask.dag_command import _RankDirection
from pytask import cli
from pytask import ExitCode

Expand Down