Skip to content

Commit 5de64e3

Browse files
authored
Refactor pytask to two packages, pytask and _pytask. (#14)
1 parent d7a03aa commit 5de64e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+216
-195
lines changed

.github/workflows/continuous-integration-workflow.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535

3636
- name: Run unit tests and doctests.
3737
shell: bash -l {0}
38-
run: tox -e pytest -- -m "unit or (not integration and not end_to_end)" --cov=./ --cov-report=xml -n auto
38+
run: tox -e pytest -- -m "unit or (not integration and not end_to_end)" --cov=./src --cov-report=xml -n auto
3939

4040
- name: Upload coverage report for unit tests and doctests.
4141
if: runner.os == 'Linux' && matrix.python-version == '3.8'
@@ -44,7 +44,7 @@ jobs:
4444

4545
- name: Run integration tests.
4646
shell: bash -l {0}
47-
run: tox -e pytest -- -m integration --cov=./ --cov-report=xml -n auto
47+
run: tox -e pytest -- -m integration --cov=./src --cov-report=xml -n auto
4848

4949
- name: Upload coverage reports of integration tests.
5050
if: runner.os == 'Linux' && matrix.python-version == '3.8'
@@ -53,7 +53,7 @@ jobs:
5353

5454
- name: Run end-to-end tests.
5555
shell: bash -l {0}
56-
run: tox -e pytest -- -m end_to_end --cov=./ --cov-report=xml -n auto
56+
run: tox -e pytest -- -m end_to_end --cov=./src --cov-report=xml -n auto
5757

5858
- name: Upload coverage reports of end-to-end tests.
5959
if: runner.os == 'Linux' && matrix.python-version == '3.8'

codecov.yml

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ coverage:
2222
ignore:
2323
- ".tox/**/*"
2424
- "setup.py"
25+
- "tests/**/*"

setup.cfg

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[bumpversion]
22
current_version = 0.0.4
33
parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))(\-?((dev)?(?P<dev>\d+))?)
4-
serialize =
4+
serialize =
55
{major}.{minor}.{patch}dev{dev}
66
{major}.{minor}.{patch}
77

@@ -10,3 +10,5 @@ serialize =
1010
[bumpversion:file:docs/conf.py]
1111

1212
[bumpversion:file:src/pytask/__init__.py]
13+
14+
[bumpversion:file:src/_pytask/__init__.py]

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"Programming Language :: Python :: 3.8",
3737
],
3838
platforms="any",
39-
entry_points={"console_scripts": ["pytask=pytask.cli:pytask"]},
39+
entry_points={"console_scripts": ["pytask=pytask:pytask"]},
4040
packages=find_packages(where="src"),
4141
package_dir={"": "src"},
4242
)

src/_pytask/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.0.4"

src/pytask/cli.py renamed to src/_pytask/cli.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from pathlib import Path
33

44
import click
5-
from pytask.config import hookimpl
6-
from pytask.pluginmanager import get_plugin_manager
5+
from _pytask.config import hookimpl
6+
from _pytask.pluginmanager import get_plugin_manager
77

88

99
CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}
@@ -28,17 +28,17 @@ def _prepare_plugin_manager():
2828

2929
@hookimpl
3030
def pytask_add_hooks(pm):
31-
from pytask import collect
32-
from pytask import config
33-
from pytask import database
34-
from pytask import debugging
35-
from pytask import execute
36-
from pytask import logging
37-
from pytask import main
38-
from pytask import parametrize
39-
from pytask import resolve_dependencies
40-
from pytask import skipping
41-
from pytask import mark_
31+
from _pytask import collect
32+
from _pytask import config
33+
from _pytask import database
34+
from _pytask import debugging
35+
from _pytask import execute
36+
from _pytask import logging
37+
from _pytask import main
38+
from _pytask import parametrize
39+
from _pytask import resolve_dependencies
40+
from _pytask import skipping
41+
from _pytask import mark
4242

4343
pm.register(collect)
4444
pm.register(config)
@@ -50,7 +50,7 @@ def pytask_add_hooks(pm):
5050
pm.register(parametrize)
5151
pm.register(resolve_dependencies)
5252
pm.register(skipping)
53-
pm.register(mark_)
53+
pm.register(mark)
5454

5555

5656
def _to_path(ctx, param, value): # noqa: U100

src/pytask/collect.py renamed to src/_pytask/collect.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
from pathlib import Path
99

1010
import click
11-
import pytask
12-
from pytask.exceptions import CollectionError
13-
from pytask.exceptions import TaskDuplicatedError
14-
from pytask.mark_ import has_marker
15-
from pytask.nodes import FilePathNode
16-
from pytask.nodes import PythonFunctionTask
17-
from pytask.report import CollectionReport
18-
from pytask.report import CollectionReportFile
19-
from pytask.report import CollectionReportTask
20-
21-
22-
@pytask.hookimpl
11+
from _pytask.config import hookimpl
12+
from _pytask.exceptions import CollectionError
13+
from _pytask.exceptions import TaskDuplicatedError
14+
from _pytask.mark import has_marker
15+
from _pytask.nodes import FilePathNode
16+
from _pytask.nodes import PythonFunctionTask
17+
from _pytask.report import CollectionReport
18+
from _pytask.report import CollectionReportFile
19+
from _pytask.report import CollectionReportTask
20+
21+
22+
@hookimpl
2323
def pytask_collect(session):
2424
reports = _collect_from_paths(session)
2525
tasks = _extract_tasks_from_reports(reports)
@@ -66,13 +66,13 @@ def _collect_from_paths(session):
6666
return collected_reports
6767

6868

69-
@pytask.hookimpl
69+
@hookimpl
7070
def pytask_ignore_collect(path, config):
7171
ignored = any(fnmatch.fnmatch(path, pattern) for pattern in config["ignore"])
7272
return ignored
7373

7474

75-
@pytask.hookimpl
75+
@hookimpl
7676
def pytask_collect_file_protocol(session, path, reports):
7777
try:
7878
reports = session.hook.pytask_collect_file(
@@ -85,7 +85,7 @@ def pytask_collect_file_protocol(session, path, reports):
8585
return reports
8686

8787

88-
@pytask.hookimpl
88+
@hookimpl
8989
def pytask_collect_file(session, path, reports):
9090
if path.name.startswith("task_") and path.suffix == ".py":
9191
spec = importlib.util.spec_from_file_location(path.stem, str(path))
@@ -115,7 +115,7 @@ def pytask_collect_file(session, path, reports):
115115
return collected_reports
116116

117117

118-
@pytask.hookimpl
118+
@hookimpl
119119
def pytask_collect_task_protocol(session, reports, path, name, obj):
120120
try:
121121
session.hook.pytask_collect_task_setup(
@@ -132,7 +132,7 @@ def pytask_collect_task_protocol(session, reports, path, name, obj):
132132
return CollectionReportTask.from_exception(path, name, exc_info)
133133

134134

135-
@pytask.hookimpl(trylast=True)
135+
@hookimpl(trylast=True)
136136
def pytask_collect_task_setup(session, reports, path, name):
137137
paths_to_tasks_w_ident_name = [
138138
i.path.as_posix()
@@ -148,7 +148,7 @@ def pytask_collect_task_setup(session, reports, path, name):
148148
)
149149

150150

151-
@pytask.hookimpl(trylast=True)
151+
@hookimpl(trylast=True)
152152
def pytask_collect_task(session, path, name, obj):
153153
"""Collect a task which is a function.
154154
@@ -163,7 +163,7 @@ def pytask_collect_task(session, path, name, obj):
163163
)
164164

165165

166-
@pytask.hookimpl(trylast=True)
166+
@hookimpl(trylast=True)
167167
def pytask_collect_node(path, node):
168168
"""Collect a node of a task as a :class:`pytask.nodes.FilePathNode`.
169169
@@ -219,7 +219,7 @@ def _extract_tasks_from_reports(reports):
219219
return [i.task for i in reports if i.successful]
220220

221221

222-
@pytask.hookimpl
222+
@hookimpl
223223
def pytask_collect_log(session, reports, tasks):
224224
tm_width = session.config["terminal_width"]
225225

src/pytask/config.py renamed to src/_pytask/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import click
1010
import pluggy
11-
from pytask.shared import get_first_not_none_value
12-
from pytask.shared import to_list
11+
from _pytask.shared import get_first_not_none_value
12+
from _pytask.shared import to_list
1313

1414

1515
hookimpl = pluggy.HookimplMarker("pytask")
File renamed without changes.

src/pytask/database.py renamed to src/_pytask/database.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from pathlib import Path
22

33
import click
4-
import pytask
4+
from _pytask.config import hookimpl
5+
from _pytask.shared import get_first_not_none_value
56
from pony import orm
6-
from pytask.shared import get_first_not_none_value
77

88

99
db = orm.Database()
@@ -35,7 +35,7 @@ def create_or_update_state(first_key, second_key, state):
3535
state_in_db.state = state
3636

3737

38-
@pytask.hookimpl
38+
@hookimpl
3939
def pytask_add_parameters_to_cli(command):
4040
additional_parameters = [
4141
click.Option(
@@ -60,7 +60,7 @@ def pytask_add_parameters_to_cli(command):
6060
command.params.extend(additional_parameters)
6161

6262

63-
@pytask.hookimpl
63+
@hookimpl
6464
def pytask_parse_config(config, config_from_cli, config_from_file):
6565
provider = get_first_not_none_value(
6666
config_from_cli, config_from_file, key="database_provider", default="sqlite"

src/pytask/debugging.py renamed to src/_pytask/debugging.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import traceback
44

55
import click
6-
import pytask
7-
from pytask.nodes import PythonFunctionTask
8-
from pytask.shared import get_first_not_none_value
6+
from _pytask.config import hookimpl
7+
from _pytask.nodes import PythonFunctionTask
8+
from _pytask.shared import get_first_not_none_value
99

1010

11-
@pytask.hookimpl
11+
@hookimpl
1212
def pytask_add_parameters_to_cli(command):
1313
additional_parameters = [
1414
click.Option(
@@ -24,7 +24,7 @@ def pytask_add_parameters_to_cli(command):
2424
command.params.extend(additional_parameters)
2525

2626

27-
@pytask.hookimpl
27+
@hookimpl
2828
def pytask_parse_config(config, config_from_cli, config_from_file):
2929
config["pdb"] = get_first_not_none_value(
3030
config_from_cli, config_from_file, key="pdb", default=False
@@ -34,7 +34,7 @@ def pytask_parse_config(config, config_from_cli, config_from_file):
3434
)
3535

3636

37-
@pytask.hookimpl
37+
@hookimpl
3838
def pytask_post_parse(config):
3939
if config["pdb"]:
4040
config["pm"].register(PdbDebugger)
@@ -45,7 +45,7 @@ def pytask_post_parse(config):
4545

4646
class PdbDebugger:
4747
@staticmethod
48-
@pytask.hookimpl(hookwrapper=True)
48+
@hookimpl(hookwrapper=True)
4949
def pytask_execute_task(task):
5050
if isinstance(task, PythonFunctionTask):
5151
task.function = wrap_function_for_post_mortem_debugging(task.function)
@@ -67,7 +67,7 @@ def wrapper(*args, **kwargs):
6767

6868
class PdbTrace:
6969
@staticmethod
70-
@pytask.hookimpl(hookwrapper=True)
70+
@hookimpl(hookwrapper=True)
7171
def pytask_execute_task(task):
7272
if isinstance(task, PythonFunctionTask):
7373
task.function = wrap_function_for_tracing(task.function)
File renamed without changes.
File renamed without changes.

src/pytask/execute.py renamed to src/_pytask/execute.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
import traceback
55

66
import click
7-
import pytask
8-
from pytask import hookimpl
9-
from pytask.dag import descending_tasks
10-
from pytask.dag import node_and_neigbors
11-
from pytask.dag import sort_tasks_topologically
12-
from pytask.database import create_or_update_state
13-
from pytask.exceptions import ExecutionError
14-
from pytask.exceptions import NodeNotFoundError
15-
from pytask.mark_ import Mark
16-
from pytask.nodes import FilePathNode
17-
from pytask.report import ExecutionReport
18-
from pytask.report import format_execute_footer
7+
from _pytask.config import hookimpl
8+
from _pytask.dag import descending_tasks
9+
from _pytask.dag import node_and_neigbors
10+
from _pytask.dag import sort_tasks_topologically
11+
from _pytask.database import create_or_update_state
12+
from _pytask.exceptions import ExecutionError
13+
from _pytask.exceptions import NodeNotFoundError
14+
from _pytask.mark import Mark
15+
from _pytask.nodes import FilePathNode
16+
from _pytask.report import ExecutionReport
17+
from _pytask.report import format_execute_footer
1918

2019

2120
@hookimpl
@@ -139,7 +138,7 @@ def pytask_execute_task_log_end(report):
139138
return True
140139

141140

142-
@pytask.hookimpl
141+
@hookimpl
143142
def pytask_execute_log_end(session, reports):
144143
session.execution_end = time.time()
145144
click.echo("")
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import platform
22
import sys
3+
from typing import List
34

5+
import _pytask
46
import click
57
import pluggy
6-
import pytask
7-
from _pytest.terminal import _plugin_nameversions
8+
from _pytask.config import hookimpl
89

910

10-
@pytask.hookimpl
11+
@hookimpl
1112
def pytask_log_session_header(session):
1213
tm_width = session.config["terminal_width"]
1314

1415
click.echo(f"{{:=^{tm_width}}}".format(" Start pytask session "), nl=True)
1516
click.echo(
1617
f"Platform: {sys.platform} -- Python {platform.python_version()}, "
17-
f"pytask {pytask.__version__}, pluggy {pluggy.__version__}"
18+
f"pytask {_pytask.__version__}, pluggy {pluggy.__version__}"
1819
)
1920
click.echo(f"Root: {session.config['root'].as_posix()}")
2021
if session.config["ini"] is not None:
@@ -24,3 +25,17 @@ def pytask_log_session_header(session):
2425
if plugin_info:
2526
formatted_plugins_w_versions = ", ".join(_plugin_nameversions(plugin_info))
2627
click.echo(f"Plugins: {formatted_plugins_w_versions}")
28+
29+
30+
def _plugin_nameversions(plugininfo) -> List[str]:
31+
values = [] # type: List[str]
32+
for _, dist in plugininfo:
33+
# Gets us name and version!
34+
name = f"{dist.project_name}-{dist.version}"
35+
# Questionable convenience, but it keeps things short.
36+
if name.startswith("pytask-"):
37+
name = name[7:]
38+
# We decided to print python package names they can have more than one plugin.
39+
if name not in values:
40+
values.append(name)
41+
return values

0 commit comments

Comments
 (0)