Skip to content

Commit b9eef0a

Browse files
committed
fix: Setup for neovim and updated templater with context
1 parent c2f4075 commit b9eef0a

File tree

4 files changed

+38
-39
lines changed

4 files changed

+38
-39
lines changed

.vscode/launch.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,80 +6,79 @@
66
"type": "debugpy",
77
"request": "launch",
88
"program": "main.py",
9-
"console": "integratedTerminal",
10-
"args": ""
9+
"console": "integratedTerminal"
1110
},
1211
{
1312
"name": "jobs list",
1413
"type": "debugpy",
1514
"request": "launch",
1615
"program": "main.py",
1716
"console": "integratedTerminal",
18-
"args": "jobs list"
17+
"args": ["jobs", "list"]
1918
},
2019
{
2120
"name": "run all",
2221
"type": "debugpy",
2322
"request": "launch",
2423
"program": "main.py",
2524
"console": "integratedTerminal",
26-
"args": "jobs run"
25+
"args": ["jobs", "run"]
2726
},
2827
{
2928
"name": "validate",
3029
"type": "debugpy",
3130
"request": "launch",
3231
"program": "main.py",
3332
"console": "integratedTerminal",
34-
"args": "jobs validate"
33+
"args": ["jobs", "validate"]
3534
},
3635
{
3736
"name": "run containers",
3837
"type": "debugpy",
3938
"request": "launch",
4039
"program": "main.py",
4140
"console": "integratedTerminal",
42-
"args": "--file jobs/containers.yaml jobs run"
41+
"args": ["--file", "jobs/containers.yaml", "jobs", "run"]
4342
},
4443
{
4544
"name": "run desktop_example",
4645
"type": "debugpy",
4746
"request": "launch",
4847
"program": "main.py",
4948
"console": "integratedTerminal",
50-
"args": "--file examples/jobs/desktop_example.yaml jobs run"
49+
"args": ["--file", "examples/jobs/desktop_example.yaml", "jobs", "run"]
5150
},
5251
{
5352
"name": "run single",
5453
"type": "debugpy",
5554
"request": "launch",
5655
"program": "main.py",
5756
"console": "integratedTerminal",
58-
"args": "jobs run --job execute_binary"
57+
"args": ["jobs", "run", "--job", "execute_binary"]
5958
},
6059
{
6160
"name": "plugins list",
6261
"type": "debugpy",
6362
"request": "launch",
6463
"program": "main.py",
6564
"console": "integratedTerminal",
66-
"args": "plugins list"
65+
"args": ["plugins", "list"]
6766
},
6867
{
6968
"name": "plugin info batman",
7069
"type": "debugpy",
7170
"request": "launch",
7271
"program": "main.py",
7372
"console": "integratedTerminal",
74-
"args": "plugins info batman"
73+
"args": ["plugins", "info", "batman"]
7574
},
7675
{
7776
"name": "run specific job file",
7877
"type": "debugpy",
7978
"request": "launch",
8079
"program": "main.py",
8180
"console": "integratedTerminal",
82-
"args": "--file ${command:pickArgs} jobs run"
81+
"args": ["--file", "${command:pickArgs}", "jobs", "run"]
8382
}
8483
]
8584
}

main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ def plugins_list():
182182
@click.argument("name")
183183
def plugin_info(name):
184184
"""
185-
Show detailed info about a specific plugin.
185+
Show detailed info about a specific plugin.
186186
187187
Examples:
188188
189-
\b
190-
taskcrafter plugins info echo
189+
\b
190+
taskcrafter plugins info echo
191191
"""
192192
plugin = plugin_lookup(name)
193193

taskcrafter/job_loader.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from copy import deepcopy
22
import time
3-
from datetime import datetime
43
from taskcrafter.exceptions.job import (
54
JobFailedError,
65
JobKillSignalError,
@@ -13,35 +12,12 @@
1312
from taskcrafter.plugin_loader import plugin_execute
1413
from taskcrafter.logger import app_logger
1514
from taskcrafter.container import run_job_in_docker
16-
from taskcrafter.util.templater import apply_templates_to_params
15+
from taskcrafter.util.templater import apply_templates_to_params, context
1716
from taskcrafter.models.job import Job, JobStatus
1817
from taskcrafter.util.yaml import get_yaml_from_string
1918
from taskcrafter.input_output_resolver import CacheManager, InputResolver
2019

2120

22-
def context(job) -> dict:
23-
"""Create a context dictionary for templating."""
24-
25-
# create dictionary with params where key is job_params_{param_name}
26-
# and value is the param value
27-
job_params = {f"job_params_{k}": v for k, v in job.params.items()}
28-
29-
return {
30-
"job_id": job.id,
31-
"job_name": job.name,
32-
"job_plugin": job.plugin,
33-
"job_schedule": job.schedule,
34-
"job_on_success": job.on_success,
35-
"job_on_failure": job.on_failure,
36-
"job_on_finish": job.on_finish,
37-
"job_depends_on": job.depends_on,
38-
"job_enabled": job.enabled,
39-
"job_retries": job.retries,
40-
"job_timeout": job.timeout,
41-
"current_time": datetime.now().isoformat(),
42-
} | job_params
43-
44-
4521
class JobManager:
4622
def __init__(self, job_file_content: str):
4723
self.jobs_yaml = None

taskcrafter/util/templater.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
1+
from datetime import datetime
2+
13
def apply_template(value: str, context: dict) -> str:
24
"""Replace known placeholders in the value using context dictionary."""
35
for key, val in context.items():
46
placeholder = f"%{key.upper()}%"
57
value = value.replace(placeholder, str(val))
68
return value
79

10+
def context(job) -> dict:
11+
"""Create a context dictionary for templating."""
12+
13+
# create dictionary with params where key is job_params_{param_name}
14+
# and value is the param value
15+
job_params = {f"job_params_{k}": v for k, v in job.params.items()}
16+
17+
return {
18+
"job_id": job.id,
19+
"job_name": job.name,
20+
"job_plugin": job.plugin,
21+
"job_schedule": job.schedule,
22+
"job_on_success": job.on_success,
23+
"job_on_failure": job.on_failure,
24+
"job_on_finish": job.on_finish,
25+
"job_depends_on": job.depends_on,
26+
"job_enabled": job.enabled,
27+
"job_retries": job.retries,
28+
"job_timeout": job.timeout,
29+
"current_time": datetime.now().isoformat(),
30+
} | job_params
31+
832

933
def apply_templates_to_params(params: dict, context: dict) -> dict:
1034
"""Recursively apply templates in params using context."""

0 commit comments

Comments
 (0)