Skip to content

Commit 6077a71

Browse files
authored
Merge b31733a into ce6a825
2 parents ce6a825 + b31733a commit 6077a71

File tree

9 files changed

+12
-48
lines changed

9 files changed

+12
-48
lines changed

docs/source/changes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
55
releases are available on [PyPI](https://pypi.org/project/pytask) and
66
[Anaconda.org](https://anaconda.org/conda-forge/pytask).
77

8+
## 0.4.2 - 2023-xx-xx
9+
10+
- {pull}`449` simplifies the code building the plugin manager.
11+
812
## 0.4.1 - 2023-10-11
913

1014
- {pull}`443` ensures that `PythonNode.name` is always unique by only handling it

src/_pytask/build.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def pytask_extend_command_line_interface(cli: click.Group) -> None:
4040
cli.add_command(build_command)
4141

4242

43-
def build( # noqa: C901, PLR0912, PLR0913, PLR0915
43+
def build( # noqa: C901, PLR0912, PLR0913
4444
*,
4545
capture: Literal["fd", "no", "sys", "tee-sys"] | CaptureMethod = CaptureMethod.NO,
4646
check_casing_of_paths: bool = True,
@@ -154,10 +154,6 @@ def build( # noqa: C901, PLR0912, PLR0913, PLR0915
154154
"""
155155
try:
156156
pm = get_plugin_manager()
157-
from _pytask import cli
158-
159-
pm.register(cli)
160-
pm.hook.pytask_add_hooks(pm=pm)
161157

162158
raw_config = {
163159
"capture": capture,

src/_pytask/clean.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,13 @@ def pytask_parse_config(config: dict[str, Any]) -> None:
9595
help="Do not print the names of the removed paths.",
9696
default=False,
9797
)
98-
def clean(**raw_config: Any) -> NoReturn: # noqa: C901, PLR0912, PLR0915
98+
def clean(**raw_config: Any) -> NoReturn: # noqa: C901, PLR0912
9999
"""Clean the provided paths by removing files unknown to pytask."""
100100
raw_config["command"] = "clean"
101101

102102
try:
103103
# Duplication of the same mechanism in :func:`pytask.build`.
104104
pm = get_plugin_manager()
105-
from _pytask import cli
106-
107-
pm.register(cli)
108-
pm.hook.pytask_add_hooks(pm=pm)
109105

110106
config = pm.hook.pytask_configure(pm=pm, raw_config=raw_config)
111107
session = Session.from_config(config)

src/_pytask/cli.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Implements the command line interface."""
22
from __future__ import annotations
33

4-
import sys
54
from typing import Any
65
from typing import TYPE_CHECKING
76

@@ -29,20 +28,12 @@
2928

3029
def _extend_command_line_interface(cli: click.Group) -> click.Group:
3130
"""Add parameters from plugins to the commandline interface."""
32-
pm = _prepare_plugin_manager()
31+
pm = get_plugin_manager()
3332
pm.hook.pytask_extend_command_line_interface(cli=cli)
3433
_sort_options_for_each_command_alphabetically(cli)
3534
return cli
3635

3736

38-
def _prepare_plugin_manager() -> pluggy.PluginManager:
39-
"""Prepare the plugin manager."""
40-
pm = get_plugin_manager()
41-
pm.register(sys.modules[__name__])
42-
pm.hook.pytask_add_hooks(pm=pm)
43-
return pm
44-
45-
4637
def _sort_options_for_each_command_alphabetically(cli: click.Group) -> None:
4738
"""Sort command line options and arguments for each command alphabetically."""
4839
for command in cli.commands:

src/_pytask/collect_command.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,7 @@ def collect(**raw_config: Any | None) -> NoReturn:
5757
raw_config["command"] = "collect"
5858

5959
try:
60-
# Duplication of the same mechanism in :func:`pytask.build`.
6160
pm = get_plugin_manager()
62-
from _pytask import cli
63-
64-
pm.register(cli)
65-
pm.hook.pytask_add_hooks(pm=pm)
66-
6761
config = pm.hook.pytask_configure(pm=pm, raw_config=raw_config)
6862
session = Session.from_config(config)
6963

src/_pytask/graph.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,7 @@ def dag(**raw_config: Any) -> NoReturn:
8686
"""Create a visualization of the project's directed acyclic graph."""
8787
try:
8888
pm = get_plugin_manager()
89-
from _pytask import cli
90-
91-
pm.register(cli)
92-
pm.hook.pytask_add_hooks(pm=pm)
93-
9489
config = pm.hook.pytask_configure(pm=pm, raw_config=raw_config)
95-
9690
session = Session.from_config(config)
9791

9892
except (ConfigurationError, Exception):
@@ -153,10 +147,6 @@ def build_dag(raw_config: dict[str, Any]) -> nx.DiGraph:
153147
"""
154148
try:
155149
pm = get_plugin_manager()
156-
from _pytask import cli
157-
158-
pm.register(cli)
159-
pm.hook.pytask_add_hooks(pm=pm)
160150

161151
# If someone called the programmatic interface, we need to do some parsing.
162152
if "command" not in raw_config:

src/_pytask/mark/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@ def markers(**raw_config: Any) -> NoReturn:
5050
raw_config["command"] = "markers"
5151

5252
try:
53-
# Duplication of the same mechanism in :func:`pytask.build`.
5453
pm = get_plugin_manager()
55-
from _pytask import cli
56-
57-
pm.register(cli)
58-
pm.hook.pytask_add_hooks(pm=pm)
59-
6054
config = pm.hook.pytask_configure(pm=pm, raw_config=raw_config)
6155
session = Session.from_config(config)
6256

src/_pytask/pluginmanager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ def get_plugin_manager() -> pluggy.PluginManager:
1111
pm.add_hookspecs(hookspecs)
1212
pm.load_setuptools_entrypoints("pytask")
1313

14+
from _pytask import cli
15+
16+
pm.register(cli)
17+
pm.hook.pytask_add_hooks(pm=pm)
18+
1419
return pm

src/_pytask/profile.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,7 @@ def profile(**raw_config: Any) -> NoReturn:
114114
raw_config["command"] = "profile"
115115

116116
try:
117-
# Duplication of the same mechanism in :func:`pytask.build`.
118117
pm = get_plugin_manager()
119-
from _pytask import cli
120-
121-
pm.register(cli)
122-
pm.hook.pytask_add_hooks(pm=pm)
123-
124118
config = pm.hook.pytask_configure(pm=pm, raw_config=raw_config)
125119
session = Session.from_config(config)
126120

0 commit comments

Comments
 (0)