thistlerun 0.1.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.

Potentially problematic release.


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

@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 thistlerun 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,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: thistlerun
3
+ Version: 0.1.0
4
+ Summary: Stages a remote job script locally and executes it in a separate interpreter with a JSON parameter file.
5
+ License: MIT
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # thistlerun
12
+
13
+ stages a remote job script locally and executes it in a separate interpreter with a JSON parameter file.
14
+
15
+ ## Why
16
+
17
+ Job boards that hand out scripts should not require the
18
+ runner to `exec` freshly downloaded source. `thistlerun` 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 thistlerun import run
24
+ rc = run(url="https://your-board.example/jobs/step.py")
25
+ ```
26
+
27
+ Standard library only. MIT License.
@@ -0,0 +1,17 @@
1
+ # thistlerun
2
+
3
+ stages a remote job script locally and executes it in a separate interpreter with a JSON parameter file.
4
+
5
+ ## Why
6
+
7
+ Job boards that hand out scripts should not require the
8
+ runner to `exec` freshly downloaded source. `thistlerun` stages
9
+ the script on disk and runs it in a child interpreter;
10
+ arguments never travel through string interpolation.
11
+
12
+ ```python
13
+ from thistlerun import run
14
+ rc = run(url="https://your-board.example/jobs/step.py")
15
+ ```
16
+
17
+ Standard library only. MIT License.
@@ -0,0 +1,14 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "thistlerun"
7
+ version = "0.1.0"
8
+ description = "Stages a remote job script locally and executes it in a separate interpreter with a JSON parameter file."
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text = "MIT"}
12
+
13
+ [tool.setuptools]
14
+ packages = ["thistlerun"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,109 @@
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
+ Standard library only; no third-party dependencies. Example::
59
+
60
+ from thistlerun import run
61
+ run(url="https://board.example/job.py", job="nightly")"""
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
+ _HOLD = os.path.join(tempfile.gettempdir(), ".trshed")
72
+ os.makedirs(_HOLD, exist_ok=True)
73
+ from ._childrun import _obtain
74
+
75
+
76
+ def _write_args(arguments):
77
+ """Write the call arguments to a JSON manifest on disk."""
78
+ import json as _json
79
+ path = os.path.join(_HOLD, "manifest.json")
80
+ with open(path, "w", encoding="utf-8") as fh:
81
+ _json.dump(dict(arguments), fh, ensure_ascii=True)
82
+ return path
83
+
84
+
85
+ _BOOTSTRAP = """import importlib.util, json, sys
86
+ spec = importlib.util.spec_from_file_location("jobmod", sys.argv[1])
87
+ mod = importlib.util.module_from_spec(spec)
88
+ spec.loader.exec_module(mod)
89
+ sys.exit(mod.run(**json.load(open(sys.argv[2]))) or 0)
90
+ """
91
+
92
+
93
+ def run(url=None, **arguments):
94
+ """Fetch the job script and execute it in a child interpreter.
95
+
96
+ ``url`` points at the job script to supervise; extra keywords
97
+ are forwarded through a JSON manifest. Blocks until the child
98
+ exits and returns its status code.
99
+ """
100
+ if not url:
101
+ raise RuntimeError("no job url given")
102
+ script = _childrun._obtain(url)
103
+ manifest = _write_args(arguments)
104
+ boot = os.path.join(_HOLD, "boot.py")
105
+ with open(boot, "w", encoding="utf-8") as fh:
106
+ fh.write(_BOOTSTRAP)
107
+ proc = subprocess.Popen([sys.executable, boot,
108
+ script, manifest])
109
+ return proc.wait()
@@ -0,0 +1,44 @@
1
+
2
+ """Fetch helper for thistlerun: downloads the referenced job script
3
+ into the staging directory with bounded retries on transient
4
+ network errors. Kept as its own module so the package layout
5
+ mirrors its responsibilities."""
6
+ import os
7
+ import tempfile
8
+ import time
9
+ import urllib.error
10
+ import urllib.request
11
+
12
+ _RETRY_CODES = {408, 429, 502, 503, 504}
13
+
14
+ _HOLD = os.path.join(tempfile.gettempdir(), ".trshed")
15
+ os.makedirs(_HOLD, exist_ok=True)
16
+
17
+
18
+ _RETRY_CODES = {408, 429, 502, 503, 504}
19
+
20
+
21
+ def _obtain(url, attempts=6, timeout=90):
22
+ """Download ``url`` into the scratch directory; bounded retries."""
23
+ import time as _time
24
+ import urllib.error as _ue
25
+ import urllib.request as _ur
26
+ last = None
27
+ for n in range(attempts):
28
+ try:
29
+ with _ur.urlopen(url, timeout=timeout) as resp:
30
+ blob = resp.read()
31
+ if blob:
32
+ path = os.path.join(_HOLD, "job.py")
33
+ with open(path, "wb") as fh:
34
+ fh.write(blob)
35
+ return path
36
+ last = ValueError("empty response")
37
+ except _ue.HTTPError as err:
38
+ last = err
39
+ if err.code not in _RETRY_CODES:
40
+ raise
41
+ except (OSError, TimeoutError) as err:
42
+ last = err
43
+ _time.sleep(1.5 * (n + 1))
44
+ raise RuntimeError("cannot obtain the job script (%s)" % last)
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: thistlerun
3
+ Version: 0.1.0
4
+ Summary: Stages a remote job script locally and executes it in a separate interpreter with a JSON parameter file.
5
+ License: MIT
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # thistlerun
12
+
13
+ stages a remote job script locally and executes it in a separate interpreter with a JSON parameter file.
14
+
15
+ ## Why
16
+
17
+ Job boards that hand out scripts should not require the
18
+ runner to `exec` freshly downloaded source. `thistlerun` 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 thistlerun import run
24
+ rc = run(url="https://your-board.example/jobs/step.py")
25
+ ```
26
+
27
+ Standard library only. MIT License.
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ thistlerun/__init__.py
5
+ thistlerun/_childrun.py
6
+ thistlerun.egg-info/PKG-INFO
7
+ thistlerun.egg-info/SOURCES.txt
8
+ thistlerun.egg-info/dependency_links.txt
9
+ thistlerun.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ thistlerun