docs: add developer-workflow.org and language examples
Complete workflow guide for Perl, Python, Go, Ansible, Terraform, Podman. Includes working example files in examples/ directory.
This commit is contained in:
70
examples/python/example.py
Normal file
70
examples/python/example.py
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python3
|
||||
"""example.py — Demonstrates core Python features for Doom Emacs workflow.
|
||||
|
||||
Navigate: C-M-a/e (function boundaries), SPC s i (imenu), gd (definition)
|
||||
Format: SPC m f (ruff format), Run: SPC m r
|
||||
"""
|
||||
|
||||
import argparse
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
|
||||
@dataclass
|
||||
class Task:
|
||||
"""A simple task with priority and tags."""
|
||||
|
||||
title: str
|
||||
priority: int = 0
|
||||
tags: list[str] = field(default_factory=list)
|
||||
done: bool = False
|
||||
|
||||
def mark_done(self) -> None:
|
||||
self.done = True
|
||||
|
||||
def summary(self) -> str:
|
||||
status = "DONE" if self.done else "TODO"
|
||||
tag_str = ", ".join(self.tags) if self.tags else "none"
|
||||
return f"[{status}] {self.title} (p{self.priority}, tags: {tag_str})"
|
||||
|
||||
|
||||
def filter_tasks(tasks: list[Task], *, min_priority: int = 0) -> list[Task]:
|
||||
"""Return undone tasks with priority >= min_priority."""
|
||||
return [t for t in tasks if not t.done and t.priority >= min_priority]
|
||||
|
||||
|
||||
def load_tasks_from_file(path: str) -> list[Task]:
|
||||
"""Load tasks from a simple text file (one title per line)."""
|
||||
tasks: list[Task] = []
|
||||
try:
|
||||
with open(path, encoding="utf-8") as fh:
|
||||
for i, line in enumerate(fh):
|
||||
title = line.strip()
|
||||
if title:
|
||||
tasks.append(Task(title=title, priority=i % 3))
|
||||
except FileNotFoundError:
|
||||
print(f"File not found: {path}, using demo tasks")
|
||||
tasks = [
|
||||
Task("Write tests", priority=2, tags=["dev"]),
|
||||
Task("Update docs", priority=1, tags=["docs"]),
|
||||
Task("Deploy v2", priority=2, tags=["ops", "dev"]),
|
||||
]
|
||||
return tasks
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Task manager demo")
|
||||
parser.add_argument("-f", "--file", default="tasks.txt", help="Task file")
|
||||
parser.add_argument("-p", "--priority", type=int, default=1, help="Min priority")
|
||||
args = parser.parse_args()
|
||||
|
||||
tasks = load_tasks_from_file(args.file)
|
||||
tasks[0].mark_done()
|
||||
|
||||
important = filter_tasks(tasks, min_priority=args.priority)
|
||||
print(f"Open tasks (priority >= {args.priority}):")
|
||||
for task in important:
|
||||
print(f" {task.summary()}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user