Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [main]
branches: [main, "fix/*"]
pull_request:

jobs:
Expand All @@ -11,13 +11,13 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
cache: pip
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "0.1.0"
description = "A lightweight, dependency-friendly automation & task-scheduling toolkit with cron schedules, pluggable actions, and a clean CLI."
readme = "README.md"
license = { text = "MIT" }
requires-python = ">=3.9"
requires-python = ">=3.10"
authors = [{ name = "Seidou Takidzava" }]
keywords = ["automation", "scheduler", "cron", "cli", "tasks", "jobs"]
classifiers = [
Expand All @@ -17,7 +17,6 @@ classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand Down Expand Up @@ -54,14 +53,14 @@ pythonpath = ["src"]

[tool.ruff]
line-length = 100
target-version = "py39"
target-version = "py310"
src = ["src", "tests"]

[tool.ruff.lint]
select = ["E", "F", "I", "UP", "B", "C4", "SIM"]

[tool.mypy]
python_version = "3.9"
python_version = "3.10"
warn_unused_ignores = true
ignore_missing_imports = true
files = ["src"]
2 changes: 1 addition & 1 deletion src/taskpilot/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from __future__ import annotations

from taskpilot.actions.base import Action, ActionContext, registry
from taskpilot.actions import builtins as _builtins # noqa: F401 (registers actions)
from taskpilot.actions.base import Action, ActionContext, registry

__all__ = ["Action", "ActionContext", "registry"]
9 changes: 5 additions & 4 deletions src/taskpilot/actions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import annotations

from collections.abc import Callable
from dataclasses import dataclass, field
from typing import Any, Callable, Dict
from typing import Any


@dataclass
Expand All @@ -12,7 +13,7 @@ class ActionContext:

task_name: str
dry_run: bool = False
env: Dict[str, str] = field(default_factory=dict)
env: dict[str, str] = field(default_factory=dict)


# An action is any callable taking (context, **params) and returning a str.
Expand All @@ -23,7 +24,7 @@ class ActionRegistry:
"""Maps action names to callables."""

def __init__(self) -> None:
self._actions: Dict[str, Action] = {}
self._actions: dict[str, Action] = {}

def register(self, name: str, action: Action | None = None):
"""Register an action. Usable directly or as a decorator."""
Expand All @@ -49,7 +50,7 @@ def get(self, name: str) -> Action:
def names(self) -> list[str]:
return sorted(self._actions)

def run(self, name: str, context: ActionContext, params: Dict[str, Any]) -> str:
def run(self, name: str, context: ActionContext, params: dict[str, Any]) -> str:
return self.get(name)(context, **params)


Expand Down
10 changes: 5 additions & 5 deletions src/taskpilot/actions/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import json
import subprocess
import urllib.request
from typing import Any, Optional
from typing import Any

from taskpilot.actions.base import ActionContext, registry

Expand All @@ -28,7 +28,7 @@ def log_action(context: ActionContext, message: str = "", **_: Any) -> str:
def shell_action(
context: ActionContext,
command: str,
timeout: Optional[float] = 60.0,
timeout: float | None = 60.0,
check: bool = True,
**_: Any,
) -> str:
Expand Down Expand Up @@ -57,7 +57,7 @@ def http_action(
context: ActionContext,
url: str,
method: str = "GET",
headers: Optional[dict[str, str]] = None,
headers: dict[str, str] | None = None,
body: Any = None,
timeout: float = 30.0,
**_: Any,
Expand All @@ -66,7 +66,7 @@ def http_action(
if context.dry_run:
return f"[dry-run] would {method} {url}"

data: Optional[bytes] = None
data: bytes | None = None
request_headers = dict(headers or {})
if body is not None:
if isinstance(body, (dict, list)):
Expand All @@ -87,7 +87,7 @@ def http_action(
def webhook_action(
context: ActionContext,
url: str,
payload: Optional[dict[str, Any]] = None,
payload: dict[str, Any] | None = None,
**_: Any,
) -> str:
"""POST a JSON *payload* to *url*. Handy for Slack/Telegram webhooks."""
Expand Down
4 changes: 2 additions & 2 deletions src/taskpilot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import json
import logging
import sys
from typing import Optional, Sequence
from collections.abc import Sequence

from taskpilot import __version__
from taskpilot.actions.base import registry
Expand Down Expand Up @@ -61,7 +61,7 @@ def _build_parser() -> argparse.ArgumentParser:
return parser


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
parser = _build_parser()
args = parser.parse_args(argv)
_configure_logging(getattr(args, "verbose", False))
Expand Down
4 changes: 2 additions & 2 deletions src/taskpilot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

import json
from pathlib import Path
from typing import Any, Union
from typing import Any

import yaml

from taskpilot.cron import CronSchedule
from taskpilot.models import Task

PathLike = Union[str, Path]
PathLike = str | Path


class ConfigError(ValueError):
Expand Down
4 changes: 2 additions & 2 deletions src/taskpilot/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class CronSchedule:
days_of_week: frozenset[int]

@classmethod
def parse(cls, expression: str) -> "CronSchedule":
def parse(cls, expression: str) -> CronSchedule:
raw = expression.strip()
if not raw:
raise CronError("Cron expression must not be empty")
Expand All @@ -112,7 +112,7 @@ def parse(cls, expression: str) -> "CronSchedule":

parsed = [
_parse_field(field, low, high)
for field, (low, high) in zip(fields, _FIELD_BOUNDS)
for field, (low, high) in zip(fields, _FIELD_BOUNDS, strict=True)
]
return cls(expression, *parsed)

Expand Down
4 changes: 2 additions & 2 deletions src/taskpilot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from dataclasses import dataclass, field
from datetime import datetime
from typing import Any, Optional
from typing import Any

from taskpilot.cron import CronSchedule

Expand All @@ -25,7 +25,7 @@ class Task:
enabled: bool = True
description: str = ""

def next_run(self, after: Optional[datetime] = None) -> datetime:
def next_run(self, after: datetime | None = None) -> datetime:
"""Return the next scheduled run time strictly after *after*."""
return self.schedule.next_after(after or datetime.now())

Expand Down
5 changes: 2 additions & 3 deletions src/taskpilot/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import logging
from datetime import datetime
from typing import Optional

from taskpilot.actions.base import ActionContext, ActionRegistry
from taskpilot.actions.base import registry as default_registry
Expand All @@ -18,10 +17,10 @@ class TaskRunner:

def __init__(
self,
registry: Optional[ActionRegistry] = None,
registry: ActionRegistry | None = None,
*,
dry_run: bool = False,
env: Optional[dict[str, str]] = None,
env: dict[str, str] | None = None,
) -> None:
self.registry = registry or default_registry
self.dry_run = dry_run
Expand Down
14 changes: 7 additions & 7 deletions src/taskpilot/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import logging
import time
from collections.abc import Callable, Iterable
from datetime import datetime
from typing import Callable, Iterable, Optional

from taskpilot.models import Task, TaskResult
from taskpilot.runner import TaskRunner
Expand All @@ -24,12 +24,12 @@ class Scheduler:
def __init__(
self,
tasks: Iterable[Task],
runner: Optional[TaskRunner] = None,
runner: TaskRunner | None = None,
) -> None:
self.tasks: list[Task] = list(tasks)
self.runner = runner or TaskRunner()

def run_pending(self, moment: Optional[datetime] = None) -> list[TaskResult]:
def run_pending(self, moment: datetime | None = None) -> list[TaskResult]:
"""Run every enabled task whose schedule matches *moment*."""
moment = (moment or datetime.now()).replace(second=0, microsecond=0)
results: list[TaskResult] = []
Expand All @@ -44,8 +44,8 @@ def run_forever(
self,
*,
poll_seconds: float = 60.0,
max_iterations: Optional[int] = None,
on_result: Optional[Callable[[TaskResult], None]] = None,
max_iterations: int | None = None,
on_result: Callable[[TaskResult], None] | None = None,
sleep: Callable[[float], None] = time.sleep,
) -> None:
"""Continuously poll and run due tasks.
Expand All @@ -55,7 +55,7 @@ def run_forever(
"""
logger.info("Scheduler starting with %d task(s)", len(self.tasks))
iteration = 0
last_minute: Optional[datetime] = None
last_minute: datetime | None = None
try:
while max_iterations is None or iteration < max_iterations:
now = datetime.now().replace(second=0, microsecond=0)
Expand All @@ -70,7 +70,7 @@ def run_forever(
except KeyboardInterrupt: # pragma: no cover - interactive only
logger.info("Scheduler stopped by user")

def describe(self, after: Optional[datetime] = None) -> list[dict]:
def describe(self, after: datetime | None = None) -> list[dict]:
"""Return a serialisable summary of upcoming runs."""
after = after or datetime.now()
rows = []
Expand Down
Loading