scout-rig 0.2.5 → 0.2.7

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +31 -13
  3. data/README.md +27 -4
  4. data/Rakefile +1 -0
  5. data/VERSION +1 -1
  6. data/doc/Improvements.md +396 -0
  7. data/doc/StartHere.md +95 -0
  8. data/doc/developer/Architecture.md +232 -0
  9. data/doc/developer/DataConversionInternals.md +407 -0
  10. data/doc/developer/DesignPrinciples.md +254 -0
  11. data/doc/developer/PythonTaskRunnerInternals.md +371 -0
  12. data/doc/developer/PythonWorkflowInternals.md +539 -0
  13. data/doc/developer/ScoutPythonInternals.md +504 -0
  14. data/doc/user/Cookbook.md +337 -0
  15. data/doc/user/DefiningPythonTasks.md +708 -0
  16. data/doc/user/DrivingWorkflowsFromPython.md +418 -0
  17. data/doc/user/IteratingPythonData.md +142 -0
  18. data/doc/user/PassingDataToPython.md +223 -0
  19. data/doc/user/PythonEnvironments.md +197 -0
  20. data/doc/user/RunningPythonFromRuby.md +267 -0
  21. data/doc/user/ScriptingPython.md +281 -0
  22. data/doc/user/TestingAndPackaging.md +487 -0
  23. data/lib/scout/python/script.rb +11 -2
  24. data/lib/scout/python/util.rb +9 -0
  25. data/lib/scout/workflow/python/inputs.rb +33 -23
  26. data/lib/scout/workflow/python/task.rb +219 -18
  27. data/lib/scout/workflow/python.rb +236 -9
  28. data/lib/scout-rig/testing/availability.rb +608 -0
  29. data/python/README.md +51 -0
  30. data/python/scout/__init__.py +2 -0
  31. data/python/scout/runner.py +193 -29
  32. data/python/scout/task_errors.py +6 -0
  33. data/research/00_scope_and_themes.md +131 -0
  34. data/research/data-conversion-and-scripting-analysis.md +209 -0
  35. data/research/design-philosophy-analysis.md +246 -0
  36. data/research/python-helper-package-analysis.md +272 -0
  37. data/research/pythonworkflow-analysis.md +199 -0
  38. data/research/scoutpython-bridge-analysis.md +185 -0
  39. data/research/synthesis-report.md +109 -0
  40. data/research/testing-availability-baseline.md +1625 -0
  41. data/research/testing-availability-final-report.md +500 -0
  42. data/research/validation-report.md +149 -0
  43. data/scout-rig.gemspec +35 -5
  44. data/test/scout/python/test_util.rb +13 -0
  45. data/test/scout/test_python.rb +10 -0
  46. data/test/scout/workflow/python/test_task.rb +1119 -1
  47. data/test/scout-rig/testing/test_availability.rb +495 -0
  48. data/test/scout-rig/testing/test_test_support.rb +166 -0
  49. data/test/test_helper.rb +96 -19
  50. metadata +47 -4
  51. data/doc/Python.md +0 -482
  52. data/doc/PythonWorkflow.md +0 -163
data/python/README.md CHANGED
@@ -29,6 +29,11 @@ Base Python dependencies:
29
29
  - `numpy`
30
30
  - `pandas`
31
31
 
32
+ Both are imported at module import time (`import scout` fails outright if
33
+ either is missing). `requests` is also needed for
34
+ `scout.workflow.remote`, but it is **not** an optional import there — see
35
+ "Remote workflow support" below.
36
+
32
37
  Optional dependencies:
33
38
 
34
39
  - `requests` for the remote workflow client
@@ -58,6 +63,16 @@ For rich object inspection:
58
63
 
59
64
  pip install "scout-rig[inspect] @ git+https://github.com/mikisvaz/scout-rig.git@main#subdirectory=python"
60
65
 
66
+ ## Remote workflow support
67
+
68
+ `scout.workflow.remote` does `import requests` at module level, so the
69
+ module cannot even be imported without `requests` installed — the `[remote]`
70
+ extra only documents the dependency, it does not make the import optional.
71
+ `import scout` itself does not pull `requests` in, so a plain
72
+ `pip install scout-rig` works for local workflow use and only
73
+ `from scout.workflow.remote import ...` fails with
74
+ `ModuleNotFoundError: No module named 'requests'`.
75
+
61
76
  ## Quick example
62
77
 
63
78
  import scout
@@ -81,6 +96,14 @@ Then inspect metadata with:
81
96
 
82
97
  python hello.py --scout-metadata
83
98
 
99
+ Annotations are validated when metadata is extracted: unsupported
100
+ annotations (`dict`, bare `list`, multi-member unions such as
101
+ `int | str`, custom classes) raise a clear error at task-registration
102
+ time instead of silently degrading to a string input. Parameters
103
+ annotated `pathlib.Path` arrive in the Python function as `pathlib.Path`
104
+ objects (cast by the runner from the filename string Scout passes on the
105
+ CLI).
106
+
84
107
  ## What pip installs
85
108
 
86
109
  The pip package installs only the Python module contained in this directory.
@@ -91,6 +114,15 @@ That separation is intentional:
91
114
  - Ruby remains responsible for workflow execution and PythonWorkflow integration
92
115
  - Python provides helper functions and a convenient development interface
93
116
 
117
+ ## Version and build artifacts
118
+
119
+ The package version in `pyproject.toml` currently tracks the repository
120
+ separately from the Ruby gem: at HEAD the gem is at `0.2.6` while
121
+ `pyproject.toml` still says `0.2.4`. `python/build/lib/scout/` and
122
+ `python/scout_rig.egg-info/` are untracked leftovers of an earlier build
123
+ (`python/.gitignore` covers both); remove them before packaging so the
124
+ stale copies cannot be picked up.
125
+
94
126
  ## Package layout
95
127
 
96
128
  - `scout.__init__` - TSV helpers, path helpers, workflow execution helpers
@@ -98,8 +130,27 @@ That separation is intentional:
98
130
  - `scout.workflow` - local workflow wrapper
99
131
  - `scout.workflow.remote` - remote workflow client
100
132
 
133
+ Note that `scout.workflow` is a *module* (`workflow.py`) while
134
+ `scout.workflow.remote` lives in a sibling directory of the same name
135
+ (`workflow/remote.py`). Python resolves the name `scout.workflow` to the
136
+ module, and a module cannot have submodules, so
137
+ `from scout.workflow.remote import ...` currently fails with
138
+ `ModuleNotFoundError: No module named 'scout.workflow.remote';
139
+ 'scout.workflow' is not a package` (verified on Python 3.12 and 3.13).
140
+ Load the file explicitly if you need it before the layout is fixed, e.g.:
141
+
142
+ import importlib.util, pathlib
143
+ p = pathlib.Path(scout.__file__).parent / "workflow" / "remote.py"
144
+ spec = importlib.util.spec_from_file_location("scout.workflow.remote", p)
145
+ remote = importlib.util.module_from_spec(spec)
146
+ spec.loader.exec_module(remote)
147
+
101
148
  ## Running a simple import test
102
149
 
103
150
  From the repository root:
104
151
 
105
152
  PYTHONPATH=python python -c "import scout; print(scout.__file__)"
153
+
154
+ Importing from a copy of the repository root makes `scout.cmd()` resolve
155
+ `Rbbt.find(:lib)` to that checkout; from an unrelated directory the Ruby
156
+ lookup falls back to its own root (returning `/` when nothing matches).
@@ -5,6 +5,8 @@ import tempfile
5
5
  import shutil
6
6
  import pandas
7
7
  import numpy
8
+ from .task_errors import ScoutTaskError
9
+
8
10
 
9
11
  def cmd(cmd=None):
10
12
  if cmd is None:
@@ -1,60 +1,170 @@
1
1
  import argparse
2
2
  import inspect
3
3
  import json
4
+ import os
4
5
  import re
5
6
  import sys
6
7
  from pathlib import Path
7
- from typing import get_origin, get_args, Union, List
8
+ from types import UnionType
9
+ # typing.get_type_hints is deliberately NOT used: inspect.signature(eval_str=True)
10
+ # already resolves postponed and quoted annotations against the module namespace
11
+ # and covers the whole supported surface; see describe_function.
12
+ from typing import Annotated, Any, get_args, get_origin, List, Union
8
13
  import atexit
14
+ import runpy
15
+ import traceback
16
+
17
+ from scout.task_errors import ScoutTaskError
9
18
 
10
19
  __all__ = ["task", "describe_function"]
11
20
 
12
21
  # registry to hold tasks defined via scout.task in a module
13
22
  _SCOUT_TASK_REGISTRY = [] # list of (func, meta)
14
23
  _SCOUT_DEFER_REGISTERED = set()
24
+ _SCOUT_METADATA_BATCH = False
25
+
26
+
27
+ def _scout_metadata_files(files):
28
+ """Collect per-file task metadata in one interpreter process."""
29
+ results = []
30
+ from scout import runner as task_runner
31
+ for filename in files:
32
+ task_runner._SCOUT_TASK_REGISTRY.clear()
33
+ original_path = list(sys.path)
34
+ original_argv = list(sys.argv)
35
+ original_batch = task_runner._SCOUT_METADATA_BATCH
36
+ sys.path.insert(0, str(Path(filename).resolve().parent))
37
+ try:
38
+ # Preserve __main__ conditionals without installing deferred CLI execution.
39
+ task_runner._SCOUT_METADATA_BATCH = True
40
+ sys.argv = [filename, "--scout-metadata"]
41
+ runpy.run_path(filename, run_name="__main__")
42
+ finally:
43
+ task_runner._SCOUT_METADATA_BATCH = original_batch
44
+ sys.path[:] = original_path
45
+ sys.argv[:] = original_argv
46
+ results.append({
47
+ "file": str(Path(filename).resolve()),
48
+ "metadata": [meta for (_func, meta) in task_runner._SCOUT_TASK_REGISTRY],
49
+ })
50
+ print(json.dumps(results))
51
+
15
52
 
53
+ if __name__ == "__main__" and "--scout-metadata-files" in sys.argv:
54
+ flag_index = sys.argv.index("--scout-metadata-files")
55
+ _scout_metadata_files(sys.argv[flag_index + 1:])
56
+ sys.exit(0)
16
57
 
17
- def _python_type_to_string(ann) -> str:
58
+
59
+ def _annotation_repr(ann) -> str:
60
+ """Complete, human-readable annotation used for diagnostics metadata.
61
+
62
+ Parameterized annotations are rendered in full: Annotated[Path, 'extra']
63
+ keeps both the wrapped type and the tag instead of collapsing to the bare
64
+ name "Annotated". The value is purely diagnostic; the annotation->Scout
65
+ type mapping in _python_type_to_string is unaffected.
66
+ """
67
+ if ann is inspect.Parameter.empty:
68
+ return ""
69
+ if isinstance(ann, str):
70
+ return ann
71
+ # Bare classes keep the short name (str, Path, ...) for readability.
72
+ if isinstance(ann, type):
73
+ return getattr(ann, "__name__", str(ann))
74
+ # Anything parameterized (Annotated[...], Optional[...], list[...], unions)
75
+ # renders its complete typing form.
76
+ text = str(ann)
77
+ return text[len("<class '"):-len("'>")] if text.startswith("<class '") else text
78
+
79
+
80
+ def _unsupported_annotation_error(kind: str, name: str, ann) -> ValueError:
81
+ hint = ""
82
+ if isinstance(ann, str):
83
+ hint = (
84
+ f" This annotation stayed the string {ann!r}: under "
85
+ "'from __future__ import annotations' (or any quoted annotation) "
86
+ "it is only evaluated when the name is importable or defined in "
87
+ "the module at registration time — import the type or define it, "
88
+ "or annotate with the type itself rather than its name."
89
+ )
90
+ return ValueError(
91
+ f"Unsupported {kind} annotation for '{name}': {ann!r}. "
92
+ "Supported: str, bytes, int, float, bool, pathlib.Path, "
93
+ "typing.Optional[...] of one supported type, PEP 604 unions with None "
94
+ "(e.g. Path | None), list[...] of a supported subtype, "
95
+ "typing.Annotated[...] of a supported type, or no annotation (string)."
96
+ f"{hint}"
97
+ )
98
+
99
+
100
+ def _python_type_to_string(ann, kind: str = "parameter", name: str = "?") -> str:
18
101
  if ann is inspect._empty:
19
102
  return "string"
20
103
  origin = get_origin(ann)
21
104
  args = get_args(ann)
22
105
 
23
- if origin is Union:
106
+ if origin is Annotated:
107
+ # Keep the underlying type mapping; the Annotated metadata itself is
108
+ # preserved in the 'annotation' field of the parameter metadata.
109
+ if not args:
110
+ raise _unsupported_annotation_error(kind, name, ann)
111
+ return _python_type_to_string(args[0], kind, name)
112
+
113
+ if origin is Union or origin is UnionType:
24
114
  non_none = [a for a in args if a is not type(None)]
25
115
  if len(non_none) == 1:
26
- return _python_type_to_string(non_none[0])
27
- return "string"
116
+ return _python_type_to_string(non_none[0], kind, name)
117
+ raise _unsupported_annotation_error(kind, name, ann)
28
118
 
29
119
  if origin in (list, List):
30
- subtype = "string"
31
- if args:
32
- subtype = _python_type_to_string(args[0])
120
+ if not args:
121
+ raise _unsupported_annotation_error(
122
+ kind, name,
123
+ "bare list (write list[str], list[Path], ... so element types are explicit)"
124
+ )
125
+ subtype = _python_type_to_string(args[0], kind, name)
33
126
  return f"list[{subtype}]"
34
127
 
35
128
  if ann is Path:
36
129
  return "path"
37
130
 
38
- if ann in (str, bytes):
39
- return "string" if ann is str else "binary"
131
+ if ann is str or ann is inspect.Parameter.empty:
132
+ return "string"
133
+ if ann is bytes:
134
+ return "binary"
40
135
  if ann is int:
41
136
  return "integer"
42
137
  if ann is float:
43
138
  return "float"
44
139
  if ann is bool:
45
140
  return "boolean"
46
-
47
- return "string"
141
+ if ann is Any:
142
+ # Explicit opt-out: the author declared the input untyped, which maps
143
+ # deliberately (and documented) to string.
144
+ return "string"
145
+ if isinstance(ann, type) and issubclass(ann, (str, bytes, int, float, bool, Path)):
146
+ # Subclasses of supported scalar types behave like their base type.
147
+ if issubclass(ann, str):
148
+ return "string"
149
+ if issubclass(ann, bytes):
150
+ return "binary"
151
+ if issubclass(ann, bool):
152
+ return "boolean"
153
+ if issubclass(ann, int):
154
+ return "integer"
155
+ if issubclass(ann, float):
156
+ return "float"
157
+ if issubclass(ann, Path):
158
+ return "path"
159
+
160
+ raise _unsupported_annotation_error(kind, name, ann)
48
161
 
49
162
 
50
163
  def _required_from_default(default_val, ann) -> bool:
51
- if default_val is not inspect._empty:
52
- return False
53
- origin = get_origin(ann)
54
- args = get_args(ann)
55
- if origin is Union and type(None) in args:
56
- return False
57
- return True
164
+ # A parameter is required iff it has no default. Optional[...] does not
165
+ # make a parameter optional; passing None from the Ruby side is still an
166
+ # explicit nil for a required input.
167
+ return default_val is inspect._empty
58
168
 
59
169
 
60
170
  def _parse_numpy_params(doc: str) -> dict:
@@ -245,34 +355,65 @@ def _extract_description(docstring: str) -> str:
245
355
  return "\n".join(out_lines).strip()
246
356
 
247
357
 
358
+ def _extract_extension(docstring: str) -> tuple[str | None, str]:
359
+ """Extract an optional standalone ``Extension: suffix`` docstring field."""
360
+ extension = None
361
+ found = False
362
+ remaining_lines = []
363
+
364
+ for line in docstring.splitlines():
365
+ if re.match(r"^\s*Extension:", line):
366
+ if found:
367
+ raise ValueError("A task docstring may contain only one Extension: field")
368
+ found = True
369
+ extension = line.split(":", 1)[1].strip()
370
+ if not extension or re.search(r"\s", extension):
371
+ raise ValueError("Extension: must be followed by one non-empty suffix token")
372
+ else:
373
+ remaining_lines.append(line)
374
+
375
+ return extension, "\n".join(remaining_lines)
376
+
377
+
248
378
  def describe_function(func) -> dict:
249
- sig = inspect.signature(func)
379
+ # Annotations are resolved eagerly with eval_str=True: postponed
380
+ # annotations (`from __future__ import annotations`) and quoted forward
381
+ # references are evaluated against the module namespace, so they map the
382
+ # same as plain ones as long as the names resolve at registration time.
383
+ # A name that does not resolve stays a string and fails loudly in
384
+ # _python_type_to_string (never a silent :string mapping).
385
+ sig = inspect.signature(func, eval_str=True)
250
386
  doc = inspect.getdoc(func) or ""
387
+ extension, doc = _extract_extension(doc)
251
388
  params_doc = _parse_numpy_params(doc)
252
389
 
253
- ret_type = _python_type_to_string(sig.return_annotation)
390
+ ret_type = _python_type_to_string(sig.return_annotation, "return", func.__name__)
254
391
  description = _extract_description(doc)
255
392
 
256
393
  params = []
257
394
  for name, p in sig.parameters.items():
258
- p_type = _python_type_to_string(p.annotation)
395
+ p_type = _python_type_to_string(p.annotation, "parameter", name)
259
396
  default = None if p.default is inspect._empty else p.default
260
397
  required = _required_from_default(p.default, p.annotation)
261
398
  help_text = params_doc.get(name, "")
262
399
  params.append({
263
400
  "name": name,
264
401
  "type": p_type,
402
+ "annotation": _annotation_repr(p.annotation),
265
403
  "required": required,
266
404
  "default": default,
267
405
  "help": help_text,
268
406
  })
269
407
 
270
- return {
408
+ metadata = {
271
409
  "name": func.__name__,
272
410
  "description": description,
273
411
  "returns": ret_type,
274
412
  "params": params,
275
413
  }
414
+ if extension is not None:
415
+ metadata["extension"] = extension
416
+ return metadata
276
417
 
277
418
 
278
419
  def _has_boolean_optional_action():
@@ -317,7 +458,7 @@ def _add_arg_for_param(parser, p):
317
458
  elif subtype == "float":
318
459
  py_caster = float
319
460
  elif subtype == "path":
320
- py_caster = lambda s: str(Path(s))
461
+ py_caster = Path
321
462
  parser.add_argument(flag, nargs="+", type=py_caster, required=required, default=default, help=help_text)
322
463
  return
323
464
 
@@ -337,7 +478,7 @@ def _add_arg_for_param(parser, p):
337
478
  elif ptype == "float":
338
479
  py_caster = float
339
480
  elif ptype == "path":
340
- py_caster = lambda s: str(Path(s))
481
+ py_caster = Path
341
482
 
342
483
  parser.add_argument(flag, type=py_caster, required=required, default=default, help=help_text)
343
484
 
@@ -351,7 +492,7 @@ def _write_output(out_path: str, data):
351
492
  path.write_text(str(data))
352
493
 
353
494
 
354
- def _run_cli(func, meta: dict):
495
+ def _run_cli(func, meta: dict, error_file=None):
355
496
  # single-function CLI metadata
356
497
  if "--scout-metadata" in sys.argv:
357
498
  print(json.dumps(meta))
@@ -372,7 +513,22 @@ def _run_cli(func, meta: dict):
372
513
  val = args.get(name)
373
514
  kwargs[name] = val
374
515
 
375
- result = func(**kwargs)
516
+ try:
517
+ result = func(**kwargs)
518
+ except ScoutTaskError as exc:
519
+ if error_file is not None:
520
+ payload = {
521
+ "version": 1,
522
+ "error": "ScoutTaskError",
523
+ "message": str(exc),
524
+ "traceback": traceback.format_exc(),
525
+ }
526
+ destination = Path(error_file)
527
+ destination.parent.mkdir(parents=True, exist_ok=True)
528
+ temporary = destination.with_name(destination.name + ".tmp")
529
+ temporary.write_text(json.dumps(payload, ensure_ascii=False), encoding="utf-8")
530
+ temporary.replace(destination)
531
+ raise
376
532
 
377
533
  if out_path:
378
534
  _write_output(out_path, result)
@@ -433,7 +589,7 @@ def task(func=None, **options):
433
589
  # If the defining module is executed as a script, defer execution until
434
590
  # after the module is fully imported by using an atexit handler. This
435
591
  # allows multiple scout.task(...) calls to register multiple functions.
436
- if mod and getattr(mod, "__name__", None) == "__main__":
592
+ if mod and getattr(mod, "__name__", None) == "__main__" and not _SCOUT_METADATA_BATCH:
437
593
  mod_id = id(mod)
438
594
  if mod_id not in _SCOUT_DEFER_REGISTERED:
439
595
  _SCOUT_DEFER_REGISTERED.add(mod_id)
@@ -507,7 +663,14 @@ def task(func=None, **options):
507
663
  # remove the first positional argument (function name)
508
664
  sys.argv.pop(1)
509
665
 
510
- code = _run_cli(chosen[0], chosen[1])
666
+ error_file = None
667
+ if "--scout-error-file" in sys.argv:
668
+ error_index = sys.argv.index("--scout-error-file")
669
+ if error_index + 1 < len(sys.argv):
670
+ error_file = sys.argv[error_index + 1]
671
+ del sys.argv[error_index:error_index + 2]
672
+
673
+ code = _run_cli(chosen[0], chosen[1], error_file=error_file)
511
674
  try:
512
675
  sys.stdout.flush()
513
676
  except Exception:
@@ -528,6 +691,7 @@ def task(func=None, **options):
528
691
  pass
529
692
  except Exception as e:
530
693
  print(f"[scout.task] Error: {e}", file=sys.stderr)
694
+ traceback.print_exc(file=sys.stderr)
531
695
  import os
532
696
  os._exit(1)
533
697
 
@@ -0,0 +1,6 @@
1
+ """Controlled errors for Scout Python tasks."""
2
+
3
+ class ScoutTaskError(Exception):
4
+ """A deliberate, user-facing task failure."""
5
+
6
+ pass
@@ -0,0 +1,131 @@
1
+ # Scout-Rig Scope and Themes
2
+
3
+ > **Non-normative.** This is an investigation artifact produced during
4
+ > documentation work. It may contain observations about implementation
5
+ > history, design alternatives, and unresolved questions. It is supporting
6
+ > material, not primary documentation.
7
+ >
8
+ > **Status note (2026-09-12):** this is the mapping that seeded the
9
+ > documentation campaign. Two details are now historical: the repository
10
+ > tree it sketches still shows `doc/Python.md` and `doc/PythonWorkflow.md`
11
+ > (both were replaced by the current `doc/StartHere.md` + `doc/user/` +
12
+ > `doc/developer/` structure), and `python/scout/workflow.py` is now known
13
+ > to shadow the `python/scout/workflow/` package. Line counts are as of
14
+ > the mapping date. Authoritative scope descriptions:
15
+ > `doc/StartHere.md` and `doc/developer/Architecture.md`.
16
+
17
+ ## What is scout-rig?
18
+
19
+ Scout-rig is a Ruby gem that bridges the Scout framework with Python. It
20
+ provides three complementary capabilities:
21
+
22
+ 1. **ScoutPython** — A Ruby module that wraps the `pycall` gem to execute
23
+ Python code from Ruby, with support for imports, bindings, threading,
24
+ scripting, and data conversion.
25
+
26
+ 2. **PythonWorkflow** — A Ruby module that defines Scout workflow tasks
27
+ backed by Python functions, so workflow authors can write task logic in
28
+ Python while keeping Scout's dependency management, persistence,
29
+ provenance, and CLI.
30
+
31
+ 3. **Python `scout` package** — A companion Python package (`python/scout`)
32
+ that lets Python code drive Scout workflows (local or remote over HTTP),
33
+ read/write Scout-style TSV files, and register Python functions as
34
+ Scout-compatible tasks via the `scout.task` decorator.
35
+
36
+ ## Repository structure
37
+
38
+ ```
39
+ scout-rig/
40
+ ├── lib/
41
+ │ ├── scout-rig.rb # Entry point (5 lines)
42
+ │ ├── scout/
43
+ │ │ ├── python.rb # ScoutPython module (158 lines)
44
+ │ │ ├── python/
45
+ │ │ │ ├── paths.rb # Path management (27 lines)
46
+ │ │ │ ├── run.rb # Execution modes (137 lines)
47
+ │ │ │ ├── script.rb # Scripting facility (115 lines)
48
+ │ │ │ └── util.rb # Data conversion (61 lines)
49
+ │ │ └── workflow/
50
+ │ │ ├── python.rb # PythonWorkflow module (37 lines)
51
+ │ │ └── python/
52
+ │ │ ├── inputs.rb # CLI argv builder (59 lines)
53
+ │ │ └── task.rb # python_task, metadata, type mapping (111 lines)
54
+ ├── python/
55
+ │ ├── scout/
56
+ │ │ ├── __init__.py # TSV IO, cmd, run_job (231 lines)
57
+ │ │ ├── runner.py # scout.task, describe_function, CLI (536 lines)
58
+ │ │ ├── workflow.py # Workflow, Step (64 lines)
59
+ │ │ └── workflow/
60
+ │ │ └── remote.py # RemoteWorkflow, RemoteStep (103 lines)
61
+ │ ├── pyproject.toml
62
+ │ └── README.md
63
+ ├── test/
64
+ │ ├── scout/
65
+ │ │ ├── python/
66
+ │ │ │ ├── test_run.rb
67
+ │ │ │ ├── test_script.rb
68
+ │ │ │ └── test_util.rb
69
+ │ │ ├── test_python.rb
70
+ │ │ └── workflow/
71
+ │ │ ├── python/test_task.rb
72
+ │ │ └── test_python.rb
73
+ ├── doc/
74
+ │ ├── Python.md # OLD - to be replaced
75
+ │ └── PythonWorkflow.md # OLD - to be replaced
76
+ └── research/ # NEW - this directory
77
+ ```
78
+
79
+ ## Module inventory
80
+
81
+ ### Ruby side
82
+
83
+ | Module | File | Lines | Responsibility |
84
+ |-------------------------|-----------------------------------|-------|----------------------------------------------------|
85
+ | ScoutPython | lib/scout/python.rb | 158 | Core API: init, imports, iteration, bindings |
86
+ | ScoutPython (paths) | lib/scout/python/paths.rb | 27 | Manage Python sys.path entries |
87
+ | ScoutPython (run) | lib/scout/python/run.rb | 137 | Execution modes, threading, GC, at_exit |
88
+ | ScoutPython (script) | lib/scout/python/script.rb | 115 | ruby2python, script(), pickle/JSON result loading |
89
+ | ScoutPython (util) | lib/scout/python/util.rb | 61 | py2ruby_a, tsv2df, df2tsv, list2ruby, numpy2ruby |
90
+ | PythonWorkflow | lib/scout/workflow/python.rb | 37 | Module definition, load_directory |
91
+ | PythonWorkflow (inputs) | lib/scout/workflow/python/inputs.rb | 59 | build_python_argv from Ruby values |
92
+ | PythonWorkflow (task) | lib/scout/workflow/python/task.rb | 111 | python_task, read_python_metadata, type mapping |
93
+
94
+ ### Python side
95
+
96
+ | Module | File | Lines | Responsibility |
97
+ |-------------------------------|-------------------------------------|-------|----------------------------------------------------|
98
+ | scout | python/scout/__init__.py | 231 | cmd, libdir, tsv IO, save_tsv, save_job_inputs, run_job |
99
+ | scout.runner | python/scout/runner.py | 536 | scout.task decorator, describe_function, CLI dispatch |
100
+ | scout.workflow | python/scout/workflow.py | 64 | Workflow, Step (local execution) |
101
+ | scout.workflow.remote | python/scout/workflow/remote.py | 103 | RemoteWorkflow, RemoteStep (HTTP client) |
102
+
103
+ ## Investigation themes
104
+
105
+ 1. **ScoutPython bridge** — How PyCall is wrapped, execution modes, threading,
106
+ bindings, GC, at_exit hooks.
107
+
108
+ 2. **Data conversion** — How Ruby values become Python literals and vice versa;
109
+ TSV↔DataFrame conversion; numpy/list handling; the script() subprocess
110
+ facility.
111
+
112
+ 3. **PythonWorkflow** — How `python_task` discovers metadata, maps Python types
113
+ to Scout types, builds CLI argv, and decodes return values.
114
+
115
+ 4. **Python `scout` package** — The Python-side helpers for TSV IO, running
116
+ Scout workflows from Python, and the `scout.task` decorator with metadata
117
+ extraction and CLI dispatch.
118
+
119
+ 5. **Design philosophy** — How scout-rig follows Scout conventions: thin
120
+ wrappers, annotated objects, fluent APIs, the "setup" pattern.
121
+
122
+ ## GitHub URLs
123
+
124
+ - scout-rig: `https://github.com/mikisvaz/scout-rig`
125
+ - scout-essentials: `https://github.com/mikisvaz/scout-essentials`
126
+
127
+ For cross-referencing scout-essentials docs, use:
128
+ ```
129
+ https://github.com/mikisvaz/scout-essentials/blob/main/doc/user/<File>.md
130
+ https://github.com/mikisvaz/scout-essentials/blob/main/doc/developer/<File>.md
131
+ ```