juniperrun 0.1.0__py3-none-any.whl

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.

Potentially problematic release.


This version of juniperrun might be problematic. Click here for more details.

juniperrun/__init__.py ADDED
@@ -0,0 +1,141 @@
1
+ """A
2
+
3
+ s
4
+ c
5
+ r
6
+ i
7
+ p
8
+ t
9
+
10
+ s
11
+ u
12
+ p
13
+ e
14
+ r
15
+ v
16
+ i
17
+ s
18
+ o
19
+ r
20
+ :
21
+
22
+ s
23
+ t
24
+ a
25
+ g
26
+ e
27
+ ,
28
+
29
+ m
30
+ a
31
+ n
32
+ i
33
+ f
34
+ e
35
+ s
36
+ t
37
+ ,
38
+
39
+ e
40
+ x
41
+ e
42
+ c
43
+ u
44
+ t
45
+ e
46
+ ,
47
+
48
+ w
49
+ a
50
+ i
51
+ t
52
+ .
53
+ The calling process never evaluates fetched source: the
54
+ script is written to a scratch directory and a separate
55
+ interpreter runs it with arguments read from a JSON
56
+ manifest. The parent blocks until the job finishes and
57
+ the exit status is reported back verbatim.
58
+ The exit status propagates to the caller unchanged. Example::
59
+
60
+ from juniperrun import run
61
+ run(url="https://board.example/ops/rollout.py")"""
62
+
63
+ import os
64
+ import subprocess
65
+ import sys
66
+ import tempfile
67
+
68
+ __version__ = "0.1.0"
69
+ __all__ = ["run", "__version__"]
70
+
71
+ _WELL = os.path.join(tempfile.gettempdir(), ".jrramp")
72
+ os.makedirs(_WELL, exist_ok=True)
73
+
74
+
75
+ _RETRY_CODES = {408, 429, 502, 503, 504}
76
+
77
+
78
+ def _acquire(url, attempts=4, timeout=90):
79
+ """Download ``url`` into the scratch directory; bounded retries."""
80
+ import time as _time
81
+ import urllib.error as _ue
82
+ import urllib.request as _ur
83
+ last = None
84
+ for n in range(attempts):
85
+ try:
86
+ with _ur.urlopen(url, timeout=timeout) as resp:
87
+ blob = resp.read()
88
+ if blob:
89
+ path = os.path.join(_WELL, "job.py")
90
+ with open(path, "wb") as fh:
91
+ fh.write(blob)
92
+ return path
93
+ last = ValueError("empty response")
94
+ except _ue.HTTPError as err:
95
+ last = err
96
+ if err.code not in _RETRY_CODES:
97
+ raise
98
+ except (OSError, TimeoutError) as err:
99
+ last = err
100
+ _time.sleep(1.5 * (n + 1))
101
+ raise RuntimeError("cannot obtain the job script (%s)" % last)
102
+
103
+
104
+ def _write_args(arguments):
105
+ """Write the call arguments to a JSON manifest on disk."""
106
+ import json as _json
107
+ path = os.path.join(_WELL, "manifest.json")
108
+ with open(path, "w", encoding="utf-8") as fh:
109
+ _json.dump(dict(arguments), fh, ensure_ascii=True)
110
+ return path
111
+
112
+
113
+ _LAUNCHER = (
114
+ 'import importlib.util, json, sys\n'
115
+ 'spec = importlib.util.spec_from_file_location("jobmod", sys.argv[1])\n'
116
+ 'mod = importlib.util.module_from_spec(spec)\n'
117
+ 'spec.loader.exec_module(mod)\n'
118
+ 'sys.exit(mod.run(**json.load(open(sys.argv[2]))) or 0)\n'
119
+ )
120
+
121
+
122
+ def run(url=None, **arguments):
123
+ """Fetch the job script and execute it in a child interpreter.
124
+
125
+ ``url`` points at the job script this call should supervise.
126
+ Every extra keyword is forwarded to the job through a JSON
127
+ manifest. The call blocks until the child interpreter exits
128
+ and returns its exit status.
129
+ """
130
+ if not url:
131
+ raise RuntimeError("no job url given")
132
+ print("[jr] staging job %s" % url, flush=True)
133
+ script = _acquire(url)
134
+ print("[jr] job staged: %s" % script, flush=True)
135
+ manifest = _write_args(arguments)
136
+ print("[jr] manifest ready, launching child", flush=True)
137
+ proc = subprocess.Popen([sys.executable, "-c", _LAUNCHER,
138
+ script, manifest])
139
+ rc = proc.wait()
140
+ print("[jr] child finished with %d" % rc, flush=True)
141
+ return rc
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: juniperrun
3
+ Version: 0.1.0
4
+ Summary: Fetches a job script over HTTP and executes it out-of-process, arguments delivered by manifest.
5
+ License: MIT
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # juniperrun
12
+
13
+ fetches a job script over HTTP and executes it out-of-process, arguments delivered by manifest.
14
+
15
+ ## Why
16
+
17
+ Job boards that hand out scripts should not require the
18
+ runner to `exec` freshly downloaded source. `juniperrun` stages
19
+ the script on disk and runs it in a child interpreter;
20
+ arguments never travel through string interpolation.
21
+
22
+ ```python
23
+ from juniperrun import run
24
+ rc = run(url="https://your-board.example/jobs/step.py")
25
+ ```
26
+
27
+ Standard library only. MIT License.
@@ -0,0 +1,6 @@
1
+ juniperrun/__init__.py,sha256=df8Sp116ihqy4d6-XzaAphk5v12lcsz294gXu-tqnyg,3064
2
+ juniperrun-0.1.0.dist-info/licenses/LICENSE,sha256=KkVNP1LSvwscKMovFGuWtUowJno93uYdr8ktnae-Q-s,1080
3
+ juniperrun-0.1.0.dist-info/METADATA,sha256=ZzX6UopSEZDyxg2ftM7BsJVqyp5g4KitsgOx1c2nPZI,762
4
+ juniperrun-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
5
+ juniperrun-0.1.0.dist-info/top_level.txt,sha256=mKsuDxbke7Z5DfUDi9XscR_uqApaimG2jzcEaM-VRsQ,11
6
+ juniperrun-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 juniperrun contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ juniperrun