common-python-tasks 0.7.0__py3-none-any.whl → 0.9.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 +9 -0
- common_python_tasks/__main__.py +19 -3
- common_python_tasks/data/fastapi/compose-base.yml.j2 +1 -2
- common_python_tasks/data/fastapi/compose-db.yml.j2 +1 -2
- common_python_tasks/data/fastapi/compose-debug.yml.j2 +1 -1
- common_python_tasks/data/generic/.dockerignore +1 -1
- common_python_tasks/data/generic/Dockerfile.j2 +6 -39
- common_python_tasks/data/generic/ruff.toml +1 -5
- common_python_tasks/docker.py +274 -154
- common_python_tasks/docker_compose.py +16 -11
- common_python_tasks/env.py +82 -36
- common_python_tasks/git.py +30 -16
- common_python_tasks/github.py +37 -3
- common_python_tasks/project.py +126 -297
- common_python_tasks/tasks.py +145 -171
- common_python_tasks/utils.py +29 -4
- {common_python_tasks-0.7.0.dist-info → common_python_tasks-0.9.0.dist-info}/METADATA +63 -29
- common_python_tasks-0.9.0.dist-info/RECORD +27 -0
- {common_python_tasks-0.7.0.dist-info → common_python_tasks-0.9.0.dist-info}/WHEEL +1 -1
- common_python_tasks-0.7.0.dist-info/RECORD +0 -27
- {common_python_tasks-0.7.0.dist-info → common_python_tasks-0.9.0.dist-info}/licenses/LICENSE +0 -0
common_python_tasks/__init__.py
CHANGED
|
@@ -11,6 +11,15 @@ __all__ = ["TaskCollection"]
|
|
|
11
11
|
def tasks(
|
|
12
12
|
include_tags: "Sequence[str] | None" = None, exclude_tags: "Sequence[str]" = tuple()
|
|
13
13
|
) -> dict:
|
|
14
|
+
"""Return the task collection filtered by the requested tags.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
include_tags: Tags that selected tasks must have. Defaults to `common`.
|
|
18
|
+
exclude_tags: Tags that selected tasks must not have.
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
The filtered Poe task collection configuration.
|
|
22
|
+
"""
|
|
14
23
|
from .tasks import tasks as task_collection
|
|
15
24
|
|
|
16
25
|
if include_tags is None and not exclude_tags:
|
common_python_tasks/__main__.py
CHANGED
|
@@ -9,6 +9,19 @@ from .tasks import tasks
|
|
|
9
9
|
__all__ = ["get_available_tasks", "print_available_tasks"]
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
def _is_package_task(task_name: str) -> bool:
|
|
13
|
+
task_config = tasks()["tasks"].get(task_name)
|
|
14
|
+
if not isinstance(task_config, dict):
|
|
15
|
+
return False
|
|
16
|
+
|
|
17
|
+
script = task_config.get("script")
|
|
18
|
+
if not isinstance(script, str) or ":" not in script:
|
|
19
|
+
return False
|
|
20
|
+
|
|
21
|
+
module_name, _ = script.split(":", 1)
|
|
22
|
+
return module_name.startswith("common_python_tasks.")
|
|
23
|
+
|
|
24
|
+
|
|
12
25
|
def get_available_tasks(internal: bool = False) -> list[str]:
|
|
13
26
|
"""Return available task names for this package.
|
|
14
27
|
|
|
@@ -21,7 +34,7 @@ def get_available_tasks(internal: bool = False) -> list[str]:
|
|
|
21
34
|
return [
|
|
22
35
|
task_name
|
|
23
36
|
for task_name in tasks()["tasks"]
|
|
24
|
-
if internal or not task_name.startswith("_")
|
|
37
|
+
if _is_package_task(task_name) and (internal or not task_name.startswith("_"))
|
|
25
38
|
]
|
|
26
39
|
|
|
27
40
|
|
|
@@ -49,8 +62,11 @@ def _get_task_docstring(task_name: str) -> str | None:
|
|
|
49
62
|
|
|
50
63
|
module_name, func_name = script.split(":", 1)
|
|
51
64
|
|
|
52
|
-
|
|
53
|
-
|
|
65
|
+
try:
|
|
66
|
+
module = importlib.import_module(module_name)
|
|
67
|
+
func = getattr(module, func_name)
|
|
68
|
+
except (ImportError, AttributeError):
|
|
69
|
+
return None
|
|
54
70
|
|
|
55
71
|
doc = inspect.getdoc(func)
|
|
56
72
|
if not doc:
|
|
@@ -9,8 +9,7 @@ x-common-environment: &common-environment
|
|
|
9
9
|
x-common-build-args: &common-build-args
|
|
10
10
|
PACKAGE_NAME: ${PACKAGE_NAME}
|
|
11
11
|
PYTHON_VERSION: ${PYTHON_VERSION}
|
|
12
|
-
|
|
13
|
-
PACKAGE_MANAGER_VERSION: ${PACKAGE_MANAGER_VERSION}
|
|
12
|
+
UV_VERSION: ${UV_VERSION}
|
|
14
13
|
|
|
15
14
|
services:
|
|
16
15
|
api:
|
|
@@ -8,8 +8,7 @@ x-common-environment: &common-environment
|
|
|
8
8
|
x-common-build-args: &common-build-args
|
|
9
9
|
PACKAGE_NAME: ${PACKAGE_NAME}
|
|
10
10
|
PYTHON_VERSION: ${PYTHON_VERSION}
|
|
11
|
-
|
|
12
|
-
PACKAGE_MANAGER_VERSION: ${PACKAGE_MANAGER_VERSION}
|
|
11
|
+
UV_VERSION: ${UV_VERSION}
|
|
13
12
|
WORKDIR_PATH: ${WORKDIR_PATH}
|
|
14
13
|
|
|
15
14
|
services:
|
|
@@ -7,33 +7,10 @@ ARG PYTHON_VERSION=3
|
|
|
7
7
|
# See https://hub.docker.com/_/python for available variants
|
|
8
8
|
ARG PYTHON_VARIANT=slim
|
|
9
9
|
ARG WORKDIR_PATH=/workspace
|
|
10
|
-
{% set package_manager = PACKAGE_MANAGER|default('poetry') %}
|
|
11
10
|
|
|
12
11
|
FROM python:${PYTHON_VERSION} AS builder
|
|
13
12
|
|
|
14
13
|
ARG PACKAGE_VERSION
|
|
15
|
-
|
|
16
|
-
{% if package_manager == 'poetry' %}
|
|
17
|
-
ARG POETRY_VERSION
|
|
18
|
-
ARG POETRY_DYNAMIC_VERSIONING_PLUGIN_VERSION
|
|
19
|
-
ARG POETRY_PLUGIN_EXPORT_VERSION
|
|
20
|
-
|
|
21
|
-
# Bypass VCS-based version detection: use the host-computed version directly.
|
|
22
|
-
# This avoids requiring a .git directory in the build context and prevents
|
|
23
|
-
# false dirty-version detection from a partial working tree.
|
|
24
|
-
ENV POETRY_DYNAMIC_VERSIONING_BYPASS=${PACKAGE_VERSION}
|
|
25
|
-
|
|
26
|
-
# Install Poetry and required Poetry plugins for package build
|
|
27
|
-
RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache{{ CACHE_ID_SUFFIX }} \
|
|
28
|
-
sh -c 'set -eu; \
|
|
29
|
-
poetry_spec="poetry"; \
|
|
30
|
-
if [ -n "${POETRY_VERSION:-}" ]; then poetry_spec="poetry==$POETRY_VERSION"; fi; \
|
|
31
|
-
dynamic_spec="poetry-dynamic-versioning[plugin]"; \
|
|
32
|
-
if [ -n "${POETRY_DYNAMIC_VERSIONING_PLUGIN_VERSION:-}" ]; then dynamic_spec="poetry-dynamic-versioning[plugin]==$POETRY_DYNAMIC_VERSIONING_PLUGIN_VERSION"; fi; \
|
|
33
|
-
export_spec="poetry-plugin-export"; \
|
|
34
|
-
if [ -n "${POETRY_PLUGIN_EXPORT_VERSION:-}" ]; then export_spec="poetry-plugin-export==$POETRY_PLUGIN_EXPORT_VERSION"; fi; \
|
|
35
|
-
pip install --root-user-action=ignore "$poetry_spec" "$dynamic_spec" "$export_spec"'
|
|
36
|
-
{% else %}
|
|
37
14
|
ARG UV_VERSION
|
|
38
15
|
|
|
39
16
|
# Bypass VCS-based version detection: use the host-computed version directly.
|
|
@@ -48,7 +25,6 @@ RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache{{ CACHE_ID_SUFFIX }}
|
|
|
48
25
|
else \
|
|
49
26
|
pip install --root-user-action=ignore uv; \
|
|
50
27
|
fi'
|
|
51
|
-
{% endif %}
|
|
52
28
|
|
|
53
29
|
# Build package
|
|
54
30
|
WORKDIR /tmp/build
|
|
@@ -56,24 +32,15 @@ COPY . /tmp/build/
|
|
|
56
32
|
|
|
57
33
|
{% if HAS_DEBUG_DEPS %}
|
|
58
34
|
# Export debug requirements when the project defines a debug dependency group
|
|
59
|
-
{% if package_manager == 'poetry' %}
|
|
60
|
-
RUN --mount=type=cache,target=/root/.cache/pip,id=pip-cache{{ CACHE_ID_SUFFIX }} \
|
|
61
|
-
poetry export --only debug --without-hashes -f requirements.txt --output requirements-debug.txt
|
|
62
|
-
{% else %}
|
|
63
35
|
RUN --mount=type=cache,target=/root/.cache/uv,id=uv-cache{{ CACHE_ID_SUFFIX }} \
|
|
64
36
|
uv export --group debug --no-hashes --format requirements-txt --output-file requirements-debug.txt
|
|
65
37
|
{% endif %}
|
|
66
|
-
{% endif %}
|
|
67
38
|
|
|
68
|
-
# Build the wheel, caching the
|
|
39
|
+
# Build the wheel, caching the uv cache directory to speed up subsequent builds.
|
|
69
40
|
# If running this in a CI system, you must be using a persistent builder to take
|
|
70
41
|
# advantage of the cache mount, and you should configure your CI to persist the
|
|
71
42
|
# cache directory between builds
|
|
72
|
-
{% if package_manager == 'poetry' %}
|
|
73
|
-
RUN --mount=type=cache,target=/root/.cache/pypoetry,id=pypoetry-cache{{ CACHE_ID_SUFFIX }} poetry build --format=wheel
|
|
74
|
-
{% else %}
|
|
75
43
|
RUN --mount=type=cache,target=/root/.cache/uv,id=uv-cache{{ CACHE_ID_SUFFIX }} uv build --wheel
|
|
76
|
-
{% endif %}
|
|
77
44
|
|
|
78
45
|
FROM python:${PYTHON_VERSION}-${PYTHON_VARIANT} AS runtime
|
|
79
46
|
ARG WORKDIR_PATH=/workspace
|
|
@@ -93,17 +60,17 @@ ENV {{ env_var }}
|
|
|
93
60
|
{%- endif %}
|
|
94
61
|
|
|
95
62
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
96
|
-
{% if
|
|
63
|
+
{% if CONTAINER_APT_PACKAGES %}
|
|
97
64
|
# Install optional runtime apt packages selected by Python-side template rendering
|
|
98
65
|
RUN --mount=type=cache,target=/var/cache/apt,id=apt-cache{{ CACHE_ID_SUFFIX }} \
|
|
99
66
|
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked,id=apt-lists{{ CACHE_ID_SUFFIX }} \
|
|
100
|
-
apt-get update && apt-get install -y --no-install-recommends {{
|
|
67
|
+
apt-get update && apt-get install -y --no-install-recommends {{ CONTAINER_APT_PACKAGES }}
|
|
101
68
|
{% endif %}
|
|
102
|
-
{% if
|
|
69
|
+
{% if CONTAINER_DEPS_IMAGE %}
|
|
103
70
|
|
|
104
71
|
# Pull external dependencies from the pre-built deps image
|
|
105
|
-
ARG
|
|
106
|
-
COPY --from={{
|
|
72
|
+
ARG CONTAINER_DEPS_IMAGE
|
|
73
|
+
COPY --from={{ CONTAINER_DEPS_IMAGE }} /tmp/deps /tmp/deps
|
|
107
74
|
{% endif %}
|
|
108
75
|
{% if CONTAINER_DEPS_MOVE_SCRIPT %}
|
|
109
76
|
RUN set -eux; \
|