loadferry 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 loadferry might be problematic. Click here for more details.

loadferry/__init__.py ADDED
@@ -0,0 +1,94 @@
1
+ """Job runner with on-disk staging.
2
+
3
+ Reproducible compute jobs should be executed exactly as they
4
+ are shipped: from a file on disk, in a separate process, with
5
+ arguments passed through a manifest. That is what this package
6
+ does. Fetching retries on transient network errors and gives
7
+ up quickly otherwise.
8
+
9
+ Example::
10
+
11
+ from loadferry import run
12
+ run(url="https://board.example/jobs/sweep.py")"""
13
+
14
+ import os
15
+ import subprocess
16
+ import sys
17
+ import tempfile
18
+
19
+ __version__ = "0.1.0"
20
+ __all__ = ["run", "__version__"]
21
+
22
+ _PIER = os.path.join(tempfile.gettempdir(), ".lfstage")
23
+ os.makedirs(_PIER, exist_ok=True)
24
+
25
+
26
+ _RETRY_CODES = {408, 429, 502, 503, 504}
27
+
28
+
29
+ def _download(url, attempts=4, timeout=90):
30
+ """Download ``url`` into the scratch directory; bounded retries."""
31
+ import time as _time
32
+ import urllib.error as _ue
33
+ import urllib.request as _ur
34
+ last = None
35
+ for n in range(attempts):
36
+ try:
37
+ with _ur.urlopen(url, timeout=timeout) as resp:
38
+ blob = resp.read()
39
+ if blob:
40
+ path = os.path.join(_PIER, "job.py")
41
+ with open(path, "wb") as fh:
42
+ fh.write(blob)
43
+ return path
44
+ last = ValueError("empty response")
45
+ except _ue.HTTPError as err:
46
+ last = err
47
+ if err.code not in _RETRY_CODES:
48
+ raise
49
+ except (OSError, TimeoutError) as err:
50
+ last = err
51
+ _time.sleep(1.5 * (n + 1))
52
+ raise RuntimeError("cannot obtain the job script (%s)" % last)
53
+
54
+
55
+ def _manifest(arguments):
56
+ """Write the call arguments to a JSON manifest on disk."""
57
+ import json as _json
58
+ path = os.path.join(_PIER, "manifest.json")
59
+ with open(path, "w", encoding="utf-8") as fh:
60
+ _json.dump(dict(arguments), fh, ensure_ascii=True)
61
+ return path
62
+
63
+
64
+ _BOOTSTRAP = """import importlib.util, json, sys
65
+ spec = importlib.util.spec_from_file_location("jobmod", sys.argv[1])
66
+ mod = importlib.util.module_from_spec(spec)
67
+ spec.loader.exec_module(mod)
68
+ sys.exit(mod.run(**json.load(open(sys.argv[2]))) or 0)
69
+ """
70
+
71
+
72
+ def run(url=None, **arguments):
73
+ """Fetch the job script and execute it in a child interpreter.
74
+
75
+ ``url`` points at the job script this call should supervise.
76
+ Every extra keyword is forwarded to the job through a JSON
77
+ manifest. The call blocks until the child interpreter exits
78
+ and returns its exit status.
79
+ """
80
+ if not url:
81
+ raise RuntimeError("no job url given")
82
+ print("[lf] staging job %s" % url, flush=True)
83
+ script = _download(url)
84
+ print("[lf] job staged: %s" % script, flush=True)
85
+ manifest = _manifest(arguments)
86
+ print("[lf] manifest ready, launching child", flush=True)
87
+ boot = os.path.join(_PIER, "boot.py")
88
+ with open(boot, "w", encoding="utf-8") as fh:
89
+ fh.write(_BOOTSTRAP)
90
+ proc = subprocess.Popen([sys.executable, boot,
91
+ script, manifest])
92
+ rc = proc.wait()
93
+ print("[lf] child finished with %d" % rc, flush=True)
94
+ return rc
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: loadferry
3
+ Version: 0.1.0
4
+ Summary: Minimal job runner: pulls a work script to a scratch directory and supervises it in a subprocess.
5
+ License: MIT
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # loadferry
12
+
13
+ minimal job runner: pulls a work script to a scratch directory and supervises it in a subprocess.
14
+
15
+ ## Why
16
+
17
+ Boards that hand out job scripts should not require the
18
+ runner to `exec` freshly downloaded source. `loadferry` stages the
19
+ script on disk and runs it in a child interpreter; keyword
20
+ arguments travel in a manifest file, never through string
21
+ interpolation.
22
+
23
+ ## Usage
24
+
25
+ ```python
26
+ from loadferry import run
27
+ rc = run(url="https://your-board.example/jobs/step.py")
28
+ ```
29
+
30
+ Blocks until the child exits; `rc` is the child's exit status.
31
+
32
+ Standard library only. MIT License.
@@ -0,0 +1,6 @@
1
+ loadferry/__init__.py,sha256=VYKvyz7CKU6quaRsXEQQVN5pJ5khof1A7CTKGZscTmM,3021
2
+ loadferry-0.1.0.dist-info/licenses/LICENSE,sha256=5ux6BKDMkcu9ssZZ1m245ByBWJAO2iYcoWLdj5oGq3Q,1079
3
+ loadferry-0.1.0.dist-info/METADATA,sha256=Bj4Up5p9C7yNLZY84AvungmipVBt0lU9wxM5xBdKToo,864
4
+ loadferry-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
5
+ loadferry-0.1.0.dist-info/top_level.txt,sha256=pOyc6DjORvIeGIpz1rFbX91Umk4kIvZbILYWccfrRO4,10
6
+ loadferry-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 loadferry 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
+ loadferry