common-python-tasks 0.0.2__py3-none-any.whl → 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- common_python_tasks/__init__.py +16 -7
- common_python_tasks/__main__.py +108 -0
- common_python_tasks/compose.py +625 -0
- common_python_tasks/data/dockerfile_extensions/.gitkeep +0 -0
- common_python_tasks/data/fastapi/alembic.ini.j2 +52 -0
- common_python_tasks/data/fastapi/compose-base.yml.j2 +40 -0
- common_python_tasks/data/fastapi/compose-db-debug.yml.j2 +45 -0
- common_python_tasks/data/fastapi/compose-db.yml.j2 +80 -0
- common_python_tasks/data/fastapi/compose-debug.yml.j2 +30 -0
- common_python_tasks/data/generic/Dockerfile.deps.j2 +17 -0
- common_python_tasks/data/generic/Dockerfile.j2 +145 -0
- common_python_tasks/docker.py +454 -0
- common_python_tasks/env.py +406 -0
- common_python_tasks/git.py +307 -0
- common_python_tasks/github.py +540 -0
- common_python_tasks/project.py +298 -0
- common_python_tasks/tasks.py +1170 -527
- common_python_tasks/utils.py +349 -0
- common_python_tasks-0.1.0.dist-info/METADATA +428 -0
- common_python_tasks-0.1.0.dist-info/RECORD +27 -0
- {common_python_tasks-0.0.2.dist-info → common_python_tasks-0.1.0.dist-info}/WHEEL +1 -1
- {common_python_tasks-0.0.2.dist-info → common_python_tasks-0.1.0.dist-info}/licenses/LICENSE +1 -1
- common_python_tasks/data/Containerfile +0 -76
- common_python_tasks-0.0.2.dist-info/METADATA +0 -295
- common_python_tasks-0.0.2.dist-info/RECORD +0 -12
- /common_python_tasks/data/{.coveragerc → generic/.coveragerc} +0 -0
- /common_python_tasks/data/{.dockerignore → generic/.dockerignore} +0 -0
- /common_python_tasks/data/{.flake8 → generic/.flake8} +0 -0
- /common_python_tasks/data/{.isort.cfg → generic/.isort.cfg} +0 -0
- /common_python_tasks/data/{pytest.ini → generic/pytest.ini} +0 -0
common_python_tasks/__init__.py
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
from typing import TYPE_CHECKING
|
|
2
2
|
|
|
3
3
|
if TYPE_CHECKING:
|
|
4
|
-
from
|
|
4
|
+
from typing import Sequence
|
|
5
5
|
|
|
6
6
|
from poethepoet_tasks import TaskCollection
|
|
7
7
|
|
|
8
|
-
__version__ = "0.0.0"
|
|
9
|
-
|
|
10
8
|
__all__ = ["TaskCollection"]
|
|
11
9
|
|
|
12
10
|
|
|
13
11
|
def tasks(
|
|
14
|
-
include_tags: "Sequence[str]
|
|
15
|
-
)
|
|
16
|
-
|
|
12
|
+
include_tags: "Sequence[str] | None" = None,
|
|
13
|
+
exclude_tags: "Sequence[str]" = tuple(),
|
|
14
|
+
) -> dict:
|
|
15
|
+
from .tasks import tasks as task_collection
|
|
16
|
+
|
|
17
|
+
if include_tags is None and not exclude_tags:
|
|
18
|
+
include_tags = ("common",)
|
|
19
|
+
elif include_tags is None:
|
|
20
|
+
include_tags = tuple()
|
|
21
|
+
|
|
22
|
+
result = task_collection(include_tags=include_tags, exclude_tags=exclude_tags)
|
|
23
|
+
globals()["tasks"] = _TASKS_ENTRYPOINT
|
|
24
|
+
return result
|
|
25
|
+
|
|
17
26
|
|
|
18
|
-
|
|
27
|
+
_TASKS_ENTRYPOINT = tasks
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
import inspect
|
|
3
|
+
import os
|
|
4
|
+
import re
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
from .tasks import tasks
|
|
8
|
+
|
|
9
|
+
__all__ = ["get_available_tasks", "print_available_tasks"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_available_tasks(internal: bool = False) -> list[str]:
|
|
13
|
+
"""Return available task names for this package.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
internal: When True, include internal task names starting with '_'.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
A list of task names.
|
|
20
|
+
"""
|
|
21
|
+
return [
|
|
22
|
+
task_name
|
|
23
|
+
for task_name in tasks()["tasks"]
|
|
24
|
+
if internal or not task_name.startswith("_")
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _extract_docstring_excerpt(doc: str) -> str:
|
|
29
|
+
excerpt = []
|
|
30
|
+
for line in doc.strip().splitlines():
|
|
31
|
+
if re.match(r"^(Args?|Arguments?|Parameters?):\s*$", line):
|
|
32
|
+
break
|
|
33
|
+
excerpt.append(line)
|
|
34
|
+
|
|
35
|
+
while excerpt and excerpt[-1].strip() == "":
|
|
36
|
+
excerpt.pop()
|
|
37
|
+
|
|
38
|
+
return "\n".join(excerpt)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _get_task_docstring(task_name: str) -> str | None:
|
|
42
|
+
|
|
43
|
+
task_config = tasks()["tasks"].get(task_name)
|
|
44
|
+
if not isinstance(task_config, dict):
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
script = task_config.get("script")
|
|
48
|
+
if not isinstance(script, str) or ":" not in script:
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
module_name, func_name = script.split(":", 1)
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
module = importlib.import_module(module_name)
|
|
55
|
+
func = getattr(module, func_name)
|
|
56
|
+
except (ImportError, AttributeError):
|
|
57
|
+
return None
|
|
58
|
+
|
|
59
|
+
doc = inspect.getdoc(func)
|
|
60
|
+
if not doc:
|
|
61
|
+
return None
|
|
62
|
+
|
|
63
|
+
return _extract_docstring_excerpt(doc)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _get_task_tags(task_name: str) -> list[str] | None:
|
|
67
|
+
task_variants = getattr(tasks, "_tasks", {}).get(task_name)
|
|
68
|
+
if not task_variants:
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
tags = {
|
|
72
|
+
tag
|
|
73
|
+
for variant in task_variants
|
|
74
|
+
for tag in getattr(variant, "tags", ())
|
|
75
|
+
if isinstance(tag, str) and not tag.startswith("task-")
|
|
76
|
+
}
|
|
77
|
+
return sorted(tags) or None
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def print_available_tasks(internal: bool = False, include_docs: bool = False) -> None:
|
|
81
|
+
"""Print available tasks.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
internal: Whether or not to include internal task names starting with '_'.
|
|
85
|
+
include_docs: Whether or not to include task docstrings.
|
|
86
|
+
"""
|
|
87
|
+
print("\nAvailable tasks in this release:\n")
|
|
88
|
+
for task_name in get_available_tasks(internal=internal):
|
|
89
|
+
print(f" - {task_name}")
|
|
90
|
+
if include_docs:
|
|
91
|
+
doc = _get_task_docstring(task_name)
|
|
92
|
+
if doc:
|
|
93
|
+
for line in doc.splitlines():
|
|
94
|
+
print(f" {line}")
|
|
95
|
+
print()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
print(
|
|
100
|
+
"common_python_tasks is not intended to be run as a standalone script. Invoke a task via poethepoet.",
|
|
101
|
+
file=sys.stderr if len(sys.argv) > 1 else sys.stdout,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
if len(sys.argv) == 1:
|
|
105
|
+
debug = os.getenv("COMMON_PYTHON_TASKS_LOG_LEVEL", "info").lower() == "debug"
|
|
106
|
+
print_available_tasks(include_docs=debug)
|
|
107
|
+
else:
|
|
108
|
+
sys.exit(1)
|