feat: add docker preset

This commit is contained in:
2026-08-01 21:06:30 +03:00
parent 9a9338cfdc
commit 48f8b2d5a9
13 changed files with 80 additions and 31 deletions
@@ -59,7 +59,7 @@ def addLoggingLevel(levelName, levelNum, methodName=None):
addLoggingLevel("TRACE", logging.DEBUG - 5)
class CustomFormatter(logging.Formatter):
class ColoredFormatter(logging.Formatter):
def __init__(self, fmt):
super().__init__()
self.fmt = fmt
+1 -1
View File
@@ -2,7 +2,7 @@ import logging
from pathlib import Path
from typing import Iterable
from .command import CommandExecutor
from .common.command import CommandExecutor
__all__ = (
"EntryTaskNotImplementedError",
+1 -1
View File
@@ -3,7 +3,7 @@ from collections import Counter
from pathlib import Path
from typing import Iterable
from .command import CommandError
from .common.command import CommandError
from .entry import Entry, EntryResolver, EntryTaskNotImplementedError
from .preset.entry import PresetEntryDetector
+12 -16
View File
@@ -1,7 +1,10 @@
import json
from pathlib import Path
from typing import Any
from ...util import reflect
import dotenv
import tomli
from ..core import Pipe
__all__ = (
@@ -11,31 +14,24 @@ __all__ = (
class FileData:
_LOADERS = {
".toml": "tomli:load",
".json": "json:load",
}
def __init__(self, filepath: Path, loader: str | None = None):
self._filepath = filepath
self._loader = loader
self._data = None
def _resolve_loader(self, filepath: Path):
loader = self._loader or self._LOADERS.get(filepath.suffix)
return reflect(loader) if loader else None
def _load_data(self):
loader = self._resolve_loader(self._filepath)
with open(self._filepath, "rb") as fd:
if loader:
self._data = loader(fd)
else:
self._data = fd.read()
if self._filepath.suffix == ".toml":
return tomli.loads(self._filepath.read_text())
elif self._filepath.suffix == ".json":
return json.loads(self._filepath.read_text())
elif self._filepath.suffix == ".env" or self._filepath.name == ".env":
return dotenv.dotenv_values(self._filepath)
return self._filepath.read_text()
def get(self, key: str):
if self._data is None and self._filepath.exists():
self._load_data()
self._data = self._load_data()
if self._data:
return self._data.get(key)
return None
@@ -0,0 +1,16 @@
[presets.docker]
conditions = ["file(Dockerfile)"]
# build
[presets.docker.tasks.build.default]
variables.docker_target = "file(.env) | get(DOCKER_PROJECTS)"
variables.docker_name = "file(pyproject.toml) | get(project.name)"
variables.docker_group = "file(.env) | get(DOCKER_GROUP)"
commands = [
# "docker build --target {docker_target} -t {docker_group}/{docker_name} . -f Dockerfile",
"docker build -t {docker_group}/{docker_name} . -f Dockerfile",
]
# publish
[presets.docker.tasks.publish.default]
commands = ["docker publish"]
+11 -4
View File
@@ -1,6 +1,7 @@
[presets.python]
conditions = ["file(pyproject.toml)"]
# setup
[presets.python.tasks.setup.poetry]
conditions = [
"file(pyproject.toml) | get(build-system.build-backend) | equal(poetry.core.masonry.api)",
@@ -11,12 +12,14 @@ commands = [
"poetry install",
]
# build
[presets.python.tasks.build.poetry]
conditions = [
"file(pyproject.toml) | get(build-system.build-backend) | equal(poetry.core.masonry.api)",
]
commands = ["poetry build"]
# publish
[presets.python.tasks.publish.poetry]
conditions = [
"file(pyproject.toml) | get(build-system.build-backend) | equal(poetry.core.masonry.api)",
@@ -25,10 +28,12 @@ conditions = [
variables.python_repository = "file(poetry.toml) | get(repositories) | key(0)"
commands = ["poetry publish -r {python_repository}"]
# test
[presets.python.tasks.test.pytest]
conditions = ["file(.venv/bin/pytest)"]
commands = [".venv/bin/python -m pytest"]
# lint
[presets.python.tasks.lint.pylint]
conditions = ["file(.venv/bin/pylint)"]
commands = [".venv/bin/pylint ./"]
@@ -37,18 +42,20 @@ commands = [".venv/bin/pylint ./"]
conditions = ["file(.venv/bin/isort)"]
commands = [".venv/bin/isort --profile black --check-only ./"]
[presets.python.tasks.format.isort]
conditions = ["file(.venv/bin/isort)"]
commands = [".venv/bin/isort --profile black ./"]
[presets.python.tasks.lint.black]
conditions = ["file(.venv/bin/black)"]
commands = [".venv/bin/black --check --diff ./"]
# format
[presets.python.tasks.format.isort]
conditions = ["file(.venv/bin/isort)"]
commands = [".venv/bin/isort --profile black ./"]
[presets.python.tasks.format.black]
conditions = ["file(.venv/bin/black)"]
commands = [".venv/bin/black ./"]
# clean
[presets.python.tasks.clean.venv]
conditions = ["file(.venv)"]
commands = ["rm -rf .venv"]
+2 -2
View File
@@ -31,13 +31,13 @@ class PresetResolver:
if self._config.default:
yield from (Path(__file__).parent / "default").iterdir()
if self._config.user:
user_preset = Path.home() / ".preset.toml"
user_preset = Path.home() / ".pm.toml"
if user_preset.exists():
yield user_preset
if self._config.project:
projectpath = self._basepath
while projectpath.exists():
project_preset = projectpath / ".preset.toml"
project_preset = projectpath / ".pm.toml"
if project_preset.exists():
yield project_preset
if projectpath.parent == projectpath:
+2 -2
View File
@@ -4,7 +4,7 @@ from argparse import ArgumentParser
from pathlib import Path
from typing import Self
from .common.logging_custom import CustomFormatter
from .common.logging_colored import ColoredFormatter
from .manager import ProjectManager
@@ -27,7 +27,7 @@ class ProjectManagerRunner:
logging_level = logging.CRITICAL
stdout_handler = logging.StreamHandler()
stdout_handler.setFormatter(CustomFormatter("%(message)s"))
stdout_handler.setFormatter(ColoredFormatter("%(message)s"))
logging.basicConfig(
level=logging_level,