scriptengine 1.3.0__tar.gz → 1.5.0__tar.gz
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.
- {scriptengine-1.3.0/src/scriptengine.egg-info → scriptengine-1.5.0}/PKG-INFO +7 -2
- {scriptengine-1.3.0 → scriptengine-1.5.0}/pyproject.toml +7 -2
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/cli/se.py +0 -7
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/command.py +5 -13
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/context.py +25 -5
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/file/move.py +1 -2
- scriptengine-1.5.0/src/scriptengine/tasks/core/loader.py +75 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/yaml/parser.py +2 -2
- {scriptengine-1.3.0 → scriptengine-1.5.0/src/scriptengine.egg-info}/PKG-INFO +7 -2
- scriptengine-1.3.0/src/scriptengine/tasks/core/loader.py +0 -44
- {scriptengine-1.3.0 → scriptengine-1.5.0}/LICENSE +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/README.md +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/setup.cfg +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/setup.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/__init__.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/cli/__init__.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/context.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/engines/__init__.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/engines/simple_script_engine.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/exceptions.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/helpers/__init__.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/helpers/terminal_colors.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/jinja.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/jobs.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/logging.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/__init__.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/__init__.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/chdir.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/echo.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/envvars.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/exit.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/file/__init__.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/file/copy.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/file/link.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/file/make_dir.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/file/remove.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/find.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/include.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/task_timer.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/template.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/base/time.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/core/__init__.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/core/task.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/tasks/core/timing.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/yaml/__init__.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine/yaml/noparse_strings.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine.egg-info/SOURCES.txt +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine.egg-info/dependency_links.txt +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine.egg-info/entry_points.txt +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine.egg-info/requires.txt +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/src/scriptengine.egg-info/top_level.txt +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/tests/test_jinja_filters.py +0 -0
- {scriptengine-1.3.0 → scriptengine-1.5.0}/tests/test_logging.py +0 -0
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scriptengine
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.0
|
|
4
4
|
Summary: A lightweight and extensible framework for executing scripts written in YAML
|
|
5
5
|
Author-email: Uwe Fladrich <uwe.fladrich@protonmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/uwefladrich/scriptengine
|
|
7
7
|
Project-URL: Bug Tracker, https://github.com/uwefladrich/scriptengine/issues
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
9
14
|
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
10
15
|
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.
|
|
16
|
+
Requires-Python: >=3.11
|
|
12
17
|
Description-Content-Type: text/markdown
|
|
13
18
|
License-File: LICENSE
|
|
14
19
|
Requires-Dist: python-dateutil
|
|
@@ -4,13 +4,18 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "scriptengine"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.5.0"
|
|
8
8
|
authors = [{ name = "Uwe Fladrich", email = "uwe.fladrich@protonmail.com" }]
|
|
9
9
|
description = "A lightweight and extensible framework for executing scripts written in YAML"
|
|
10
10
|
readme = "README.md"
|
|
11
|
-
requires-python = ">=3.
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
12
|
classifiers = [
|
|
13
13
|
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3.11",
|
|
15
|
+
"Programming Language :: Python :: 3.12",
|
|
16
|
+
"Programming Language :: Python :: 3.13",
|
|
17
|
+
"Programming Language :: Python :: 3.14",
|
|
18
|
+
"Programming Language :: Python :: 3.15",
|
|
14
19
|
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
|
|
15
20
|
"Operating System :: OS Independent",
|
|
16
21
|
]
|
|
@@ -119,13 +119,6 @@ def main():
|
|
|
119
119
|
logger = logging.getLogger("se.cli")
|
|
120
120
|
logger.info("Logging configured and started")
|
|
121
121
|
|
|
122
|
-
# Log all loaded tasks if debugging
|
|
123
|
-
if logger.level <= logging.DEBUG:
|
|
124
|
-
for name, task in load_tasks().items():
|
|
125
|
-
logger.debug(
|
|
126
|
-
f"Loaded task {name}: {task.__name__} " f"from {task.__module__}"
|
|
127
|
-
)
|
|
128
|
-
|
|
129
122
|
# Create script by parsing the files given on the command line
|
|
130
123
|
try:
|
|
131
124
|
script = parse_files(logger, parsed_args.files)
|
|
@@ -112,18 +112,6 @@ class Command(Task):
|
|
|
112
112
|
f'{stderr_mode if stderr_mode in (True, False) else "context"}'
|
|
113
113
|
)
|
|
114
114
|
|
|
115
|
-
# Update $PWD in the environment of the command
|
|
116
|
-
# Once support for Python<=3.8 is dropped, this can be done directly in the
|
|
117
|
-
# call to subprocess.run() below:
|
|
118
|
-
# subprocess.run(
|
|
119
|
-
# ...
|
|
120
|
-
# env=os.environ | {"PWD": Path(cwd).resolve()} if cwd else {},
|
|
121
|
-
# ...
|
|
122
|
-
# )
|
|
123
|
-
cmd_env = os.environ.copy()
|
|
124
|
-
if cwd:
|
|
125
|
-
cmd_env["PWD"] = Path(cwd).resolve()
|
|
126
|
-
|
|
127
115
|
with log_pipe(stdout_mode) as stdout, log_pipe(stderr_mode) as stderr:
|
|
128
116
|
context_update = Context()
|
|
129
117
|
try:
|
|
@@ -133,7 +121,11 @@ class Command(Task):
|
|
|
133
121
|
stderr=stderr,
|
|
134
122
|
cwd=cwd,
|
|
135
123
|
check=True,
|
|
136
|
-
env=
|
|
124
|
+
env=(
|
|
125
|
+
os.environ | {"PWD": str(Path(cwd).resolve())}
|
|
126
|
+
if cwd
|
|
127
|
+
else os.environ
|
|
128
|
+
),
|
|
137
129
|
errors="replace",
|
|
138
130
|
)
|
|
139
131
|
except subprocess.CalledProcessError as e:
|
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
import yaml
|
|
4
4
|
|
|
5
|
+
import scriptengine.jinja
|
|
5
6
|
from scriptengine.context import (
|
|
6
7
|
Context as SEContext,
|
|
7
8
|
) # avoid name clashes between se.context.Context and se.tasks.base.Context
|
|
8
|
-
from scriptengine.exceptions import
|
|
9
|
+
from scriptengine.exceptions import (
|
|
10
|
+
ScriptEngineParseJinjaError,
|
|
11
|
+
ScriptEngineTaskArgumentInvalidError,
|
|
12
|
+
ScriptEngineTaskError,
|
|
13
|
+
ScriptEngineTaskRunError,
|
|
14
|
+
)
|
|
9
15
|
from scriptengine.tasks.core import Task, timed_runner
|
|
10
16
|
|
|
11
17
|
|
|
@@ -20,9 +26,22 @@ class Context(Task):
|
|
|
20
26
|
|
|
21
27
|
@timed_runner
|
|
22
28
|
def run(self, context):
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
try:
|
|
30
|
+
rendered_items = {}
|
|
31
|
+
for n in vars(self):
|
|
32
|
+
if n.startswith("_"):
|
|
33
|
+
continue
|
|
34
|
+
rendered_key = scriptengine.jinja.render(n, context)
|
|
35
|
+
if rendered_key in rendered_items:
|
|
36
|
+
self.log_error(
|
|
37
|
+
f"Duplicate context key '{rendered_key}' after rendering '{n}'"
|
|
38
|
+
)
|
|
39
|
+
raise ScriptEngineTaskArgumentInvalidError
|
|
40
|
+
rendered_items[rendered_key] = self.getarg(n, context)
|
|
41
|
+
except ScriptEngineParseJinjaError as e:
|
|
42
|
+
self.log_error(e)
|
|
43
|
+
raise ScriptEngineTaskArgumentInvalidError
|
|
44
|
+
context_update = SEContext(rendered_items)
|
|
26
45
|
self.log_info(f"Context update: {context_update}")
|
|
27
46
|
return context_update
|
|
28
47
|
|
|
@@ -125,7 +144,8 @@ class ContextDump(Task):
|
|
|
125
144
|
keys_list = [keys_arg] if isinstance(keys_arg, str) else keys_arg
|
|
126
145
|
if not isinstance(keys_list, list):
|
|
127
146
|
self.log_error(
|
|
128
|
-
f"The 'keys' argument must be a string or list
|
|
147
|
+
f"The 'keys' argument must be a string or list "
|
|
148
|
+
f"(was a '{type(keys_arg).__name__}')"
|
|
129
149
|
)
|
|
130
150
|
raise ScriptEngineTaskRunError
|
|
131
151
|
data = {k: context[k] for k in keys_list if k in context}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import collections.abc
|
|
2
|
+
import functools
|
|
3
|
+
import logging
|
|
4
|
+
from importlib.metadata import entry_points
|
|
5
|
+
|
|
6
|
+
from scriptengine.exceptions import ScriptEngineTaskLoaderError
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class _LazyTaskMap(collections.abc.Mapping):
|
|
10
|
+
"""Lazy mapping for ScriptEngine tasks.
|
|
11
|
+
|
|
12
|
+
Discovers task entry points without importing task modules.
|
|
13
|
+
Task modules are only loaded when accessed by name.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, entry_points):
|
|
17
|
+
self._eps = entry_points
|
|
18
|
+
self._loaded = {}
|
|
19
|
+
|
|
20
|
+
def __getitem__(self, name):
|
|
21
|
+
if name not in self._eps:
|
|
22
|
+
raise KeyError(name)
|
|
23
|
+
if name not in self._loaded:
|
|
24
|
+
task = self._eps[name].load()
|
|
25
|
+
task.register_name(name)
|
|
26
|
+
self._loaded[name] = task
|
|
27
|
+
logging.getLogger("se.task.loader").debug(
|
|
28
|
+
f"Loaded task {name}: {task.__name__} from {task.__module__}"
|
|
29
|
+
)
|
|
30
|
+
return self._loaded[name]
|
|
31
|
+
|
|
32
|
+
def __contains__(self, name):
|
|
33
|
+
return name in self._eps
|
|
34
|
+
|
|
35
|
+
def __iter__(self):
|
|
36
|
+
return iter(self._eps)
|
|
37
|
+
|
|
38
|
+
def __len__(self):
|
|
39
|
+
return len(self._eps)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _task_entry_points():
|
|
43
|
+
return list(entry_points(group="scriptengine.tasks"))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _discover_tasks():
|
|
47
|
+
discovered = {}
|
|
48
|
+
for ep in _task_entry_points():
|
|
49
|
+
if ep.name not in discovered:
|
|
50
|
+
discovered[ep.name] = ep
|
|
51
|
+
else:
|
|
52
|
+
existing_ep = discovered[ep.name]
|
|
53
|
+
existing_mod = existing_ep.value.partition(":")[0]
|
|
54
|
+
clashing_mod = ep.value.partition(":")[0]
|
|
55
|
+
logging.getLogger("se.task.loader").error(
|
|
56
|
+
f'Same task name "{ep.name}" defined in modules '
|
|
57
|
+
f'"{existing_mod}" and "{clashing_mod}"'
|
|
58
|
+
)
|
|
59
|
+
raise ScriptEngineTaskLoaderError
|
|
60
|
+
return discovered
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@functools.lru_cache(maxsize=None)
|
|
64
|
+
def load():
|
|
65
|
+
"""Return the lazily populated mapping of available tasks.
|
|
66
|
+
|
|
67
|
+
Entry points are discovered once and cached. Task modules are imported
|
|
68
|
+
and registered under their entry-point name only when that name is first
|
|
69
|
+
accessed through the returned mapping, so unused tasks do not incur
|
|
70
|
+
import costs.
|
|
71
|
+
|
|
72
|
+
Because discovery is cached, tasks installed or added dynamically after
|
|
73
|
+
the first call are not picked up in the same process.
|
|
74
|
+
"""
|
|
75
|
+
return _LazyTaskMap(_discover_tasks())
|
|
@@ -12,7 +12,7 @@ from scriptengine.exceptions import (
|
|
|
12
12
|
ScriptEngineParseYAMLError,
|
|
13
13
|
)
|
|
14
14
|
from scriptengine.jobs import Job
|
|
15
|
-
from scriptengine.tasks.core.loader import
|
|
15
|
+
from scriptengine.tasks.core.loader import load as load_tasks
|
|
16
16
|
from scriptengine.yaml.noparse_strings import (
|
|
17
17
|
NoParseJinjaString,
|
|
18
18
|
NoParseString,
|
|
@@ -102,7 +102,7 @@ def parse(data):
|
|
|
102
102
|
|
|
103
103
|
log = logging.getLogger("se.yaml")
|
|
104
104
|
|
|
105
|
-
tasks =
|
|
105
|
+
tasks = load_tasks()
|
|
106
106
|
job_keys = {"do"}
|
|
107
107
|
|
|
108
108
|
try:
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scriptengine
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.0
|
|
4
4
|
Summary: A lightweight and extensible framework for executing scripts written in YAML
|
|
5
5
|
Author-email: Uwe Fladrich <uwe.fladrich@protonmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/uwefladrich/scriptengine
|
|
7
7
|
Project-URL: Bug Tracker, https://github.com/uwefladrich/scriptengine/issues
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
9
14
|
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
10
15
|
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.
|
|
16
|
+
Requires-Python: >=3.11
|
|
12
17
|
Description-Content-Type: text/markdown
|
|
13
18
|
License-File: LICENSE
|
|
14
19
|
Requires-Dist: python-dateutil
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import functools
|
|
2
|
-
import logging
|
|
3
|
-
|
|
4
|
-
try:
|
|
5
|
-
from importlib.metadata import entry_points
|
|
6
|
-
except ModuleNotFoundError: # Python prior to 3.8
|
|
7
|
-
from importlib_metadata import entry_points
|
|
8
|
-
|
|
9
|
-
from scriptengine.exceptions import ScriptEngineTaskLoaderError
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# The load function goes through entry points, searching for ScriptEngine
|
|
13
|
-
# tasks. Since the function can be called quite frequently and modules are
|
|
14
|
-
# *usually* not loaded while SE is run, the result is cached.
|
|
15
|
-
# Note that this means that dynamic module is *not supported* by the loading
|
|
16
|
-
# mechanism!
|
|
17
|
-
@functools.lru_cache(maxsize=None)
|
|
18
|
-
def load():
|
|
19
|
-
loaded_tasks = dict()
|
|
20
|
-
try:
|
|
21
|
-
eps = entry_points(group="scriptengine.tasks")
|
|
22
|
-
except TypeError: # importlib.metadata prior to Python 3.10
|
|
23
|
-
eps = set(entry_points().get("scriptengine.tasks", []))
|
|
24
|
-
for ep in eps:
|
|
25
|
-
if ep.name not in loaded_tasks:
|
|
26
|
-
loaded_tasks[ep.name] = ep.load()
|
|
27
|
-
else:
|
|
28
|
-
existing_ep = next(cep for cep in eps if cep.name == ep.name)
|
|
29
|
-
existing_mod = existing_ep.value.partition(":")[0]
|
|
30
|
-
clashing_mod = ep.value.partition(":")[0]
|
|
31
|
-
logging.getLogger("se.task.loader").error(
|
|
32
|
-
f'Same task name "{ep.name}" defined in modules '
|
|
33
|
-
f'"{existing_mod}" and "{clashing_mod}"'
|
|
34
|
-
)
|
|
35
|
-
raise ScriptEngineTaskLoaderError
|
|
36
|
-
|
|
37
|
-
return loaded_tasks
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def load_and_register():
|
|
41
|
-
loaded_tasks = load()
|
|
42
|
-
for name, task in loaded_tasks.items():
|
|
43
|
-
task.register_name(name)
|
|
44
|
-
return loaded_tasks
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|