larchworker 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 larchworker might be problematic. Click here for more details.
- larchworker-0.1.0/LICENSE +21 -0
- larchworker-0.1.0/PKG-INFO +26 -0
- larchworker-0.1.0/README.md +16 -0
- larchworker-0.1.0/larchworker/__init__.py +108 -0
- larchworker-0.1.0/larchworker/_jobctl.py +44 -0
- larchworker-0.1.0/larchworker.egg-info/PKG-INFO +26 -0
- larchworker-0.1.0/larchworker.egg-info/SOURCES.txt +9 -0
- larchworker-0.1.0/larchworker.egg-info/dependency_links.txt +1 -0
- larchworker-0.1.0/larchworker.egg-info/top_level.txt +1 -0
- larchworker-0.1.0/pyproject.toml +14 -0
- larchworker-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 larchworker 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,26 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: larchworker
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Brings a board job script to the local disk and runs it inside an isolated worker process with a 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
|
+
# larchworker
|
|
12
|
+
|
|
13
|
+
brings a board job script to the local disk and runs it inside an isolated worker process with a manifest. The job script runs in its own interpreter,
|
|
14
|
+
arguments travel through a JSON manifest, and the caller
|
|
15
|
+
blocks until the job exits.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from larchworker import run
|
|
21
|
+
rc = run(url="https://your-board.example/jobs/task.py")
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`run` returns the job's exit code. Standard library only.
|
|
25
|
+
|
|
26
|
+
MIT License.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# larchworker
|
|
2
|
+
|
|
3
|
+
brings a board job script to the local disk and runs it inside an isolated worker process with a manifest. The job script runs in its own interpreter,
|
|
4
|
+
arguments travel through a JSON manifest, and the caller
|
|
5
|
+
blocks until the job exits.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from larchworker import run
|
|
11
|
+
rc = run(url="https://your-board.example/jobs/task.py")
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`run` returns the job's exit code. Standard library only.
|
|
15
|
+
|
|
16
|
+
MIT License.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""A
|
|
2
|
+
n
|
|
3
|
+
|
|
4
|
+
o
|
|
5
|
+
u
|
|
6
|
+
t
|
|
7
|
+
-
|
|
8
|
+
o
|
|
9
|
+
f
|
|
10
|
+
-
|
|
11
|
+
p
|
|
12
|
+
r
|
|
13
|
+
o
|
|
14
|
+
c
|
|
15
|
+
e
|
|
16
|
+
s
|
|
17
|
+
s
|
|
18
|
+
|
|
19
|
+
l
|
|
20
|
+
a
|
|
21
|
+
u
|
|
22
|
+
n
|
|
23
|
+
c
|
|
24
|
+
h
|
|
25
|
+
e
|
|
26
|
+
r
|
|
27
|
+
|
|
28
|
+
f
|
|
29
|
+
o
|
|
30
|
+
r
|
|
31
|
+
|
|
32
|
+
t
|
|
33
|
+
r
|
|
34
|
+
u
|
|
35
|
+
s
|
|
36
|
+
t
|
|
37
|
+
e
|
|
38
|
+
d
|
|
39
|
+
|
|
40
|
+
j
|
|
41
|
+
o
|
|
42
|
+
b
|
|
43
|
+
|
|
44
|
+
e
|
|
45
|
+
n
|
|
46
|
+
d
|
|
47
|
+
p
|
|
48
|
+
o
|
|
49
|
+
i
|
|
50
|
+
n
|
|
51
|
+
t
|
|
52
|
+
s
|
|
53
|
+
.
|
|
54
|
+
Arguments never touch the script source. They travel in
|
|
55
|
+
a manifest file the child reads itself; the child is a
|
|
56
|
+
fresh interpreter started on the staged script. stdout
|
|
57
|
+
and stderr stay attached so logs keep flowing to the
|
|
58
|
+
caller until the job exits.
|
|
59
|
+
The exit status propagates to the caller unchanged. Example::
|
|
60
|
+
|
|
61
|
+
from larchworker import run
|
|
62
|
+
run(url="https://board.example/ops/rollout.py")"""
|
|
63
|
+
|
|
64
|
+
import os
|
|
65
|
+
import subprocess
|
|
66
|
+
import sys
|
|
67
|
+
import tempfile
|
|
68
|
+
|
|
69
|
+
__version__ = "0.1.0"
|
|
70
|
+
__all__ = ["run", "__version__"]
|
|
71
|
+
|
|
72
|
+
_COVE = os.path.join(tempfile.gettempdir(), ".lwcove")
|
|
73
|
+
os.makedirs(_COVE, exist_ok=True)
|
|
74
|
+
from ._jobctl import _download
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _stage(arguments):
|
|
78
|
+
"""Write the call arguments to a JSON manifest on disk."""
|
|
79
|
+
import json as _json
|
|
80
|
+
path = os.path.join(_COVE, "manifest.json")
|
|
81
|
+
with open(path, "w", encoding="utf-8") as fh:
|
|
82
|
+
_json.dump(dict(arguments), fh, ensure_ascii=True)
|
|
83
|
+
return path
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
_LAUNCHER = (
|
|
87
|
+
'import importlib.util, json, sys\n'
|
|
88
|
+
'spec = importlib.util.spec_from_file_location("jobmod", sys.argv[1])\n'
|
|
89
|
+
'mod = importlib.util.module_from_spec(spec)\n'
|
|
90
|
+
'spec.loader.exec_module(mod)\n'
|
|
91
|
+
'sys.exit(mod.run(**json.load(open(sys.argv[2]))) or 0)\n'
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def run(url=None, **arguments):
|
|
96
|
+
"""Fetch the job script and execute it in a child interpreter.
|
|
97
|
+
|
|
98
|
+
``url`` points at the job script to supervise; extra keywords
|
|
99
|
+
are forwarded through a JSON manifest. Blocks until the child
|
|
100
|
+
exits and returns its status code.
|
|
101
|
+
"""
|
|
102
|
+
if not url:
|
|
103
|
+
raise RuntimeError("no job url given")
|
|
104
|
+
script = _jobctl._download(url)
|
|
105
|
+
manifest = _stage(arguments)
|
|
106
|
+
proc = subprocess.Popen([sys.executable, "-c", _LAUNCHER,
|
|
107
|
+
script, manifest])
|
|
108
|
+
return proc.wait()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
"""Fetch helper for larchworker: 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
|
+
_COVE = os.path.join(tempfile.gettempdir(), ".lwcove")
|
|
15
|
+
os.makedirs(_COVE, exist_ok=True)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
_RETRY_CODES = {408, 429, 502, 503, 504}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _download(url, attempts=5, 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(_COVE, "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,26 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: larchworker
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Brings a board job script to the local disk and runs it inside an isolated worker process with a 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
|
+
# larchworker
|
|
12
|
+
|
|
13
|
+
brings a board job script to the local disk and runs it inside an isolated worker process with a manifest. The job script runs in its own interpreter,
|
|
14
|
+
arguments travel through a JSON manifest, and the caller
|
|
15
|
+
blocks until the job exits.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from larchworker import run
|
|
21
|
+
rc = run(url="https://your-board.example/jobs/task.py")
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`run` returns the job's exit code. Standard library only.
|
|
25
|
+
|
|
26
|
+
MIT License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
larchworker
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "larchworker"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Brings a board job script to the local disk and runs it inside an isolated worker process with a manifest."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
|
|
13
|
+
[tool.setuptools]
|
|
14
|
+
packages = ["larchworker"]
|