aind-codeocean-dispatch 0.4.0__tar.gz → 0.5.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.
Files changed (30) hide show
  1. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/CHANGELOG.md +10 -0
  2. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/PKG-INFO +18 -1
  3. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/README.md +17 -0
  4. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/pyproject.toml +1 -1
  5. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/scripts/run_linters_and_checks.sh +24 -12
  6. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/src/aind_codeocean_dispatch/__init__.py +3 -0
  7. aind_codeocean_dispatch-0.5.0/src/aind_codeocean_dispatch/automation.py +159 -0
  8. aind_codeocean_dispatch-0.5.0/tests/test_automation.py +181 -0
  9. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/uv.lock +1 -1
  10. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/.copier-answers.yml +0 -0
  11. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  12. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  13. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/.github/ISSUE_TEMPLATE/user-story.md +0 -0
  14. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/.github/dependabot.yml +0 -0
  15. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/.github/workflows/bump-call.yml +0 -0
  16. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/.github/workflows/ci-call.yml +0 -0
  17. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/.github/workflows/publish-call.yml +0 -0
  18. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/.gitignore +0 -0
  19. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/.python-version +0 -0
  20. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/CLAUDE.md +0 -0
  21. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/LICENSE +0 -0
  22. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/src/aind_codeocean_dispatch/capsule_git.py +0 -0
  23. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/src/aind_codeocean_dispatch/capture.py +0 -0
  24. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/src/aind_codeocean_dispatch/py.typed +0 -0
  25. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/src/aind_codeocean_dispatch/runner.py +0 -0
  26. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/tests/__init__.py +0 -0
  27. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/tests/fakes.py +0 -0
  28. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/tests/test_capsule_git.py +0 -0
  29. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/tests/test_capture.py +0 -0
  30. {aind_codeocean_dispatch-0.4.0 → aind_codeocean_dispatch-0.5.0}/tests/test_runner.py +0 -0
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## v0.5.0 (2026-10-15)
9
+
10
+ ### Feat
11
+
12
+ - add a post-run automation that captures runs as internal assets
13
+
14
+ ### Fix
15
+
16
+ - make check script exit nonzero when any step fails
17
+
8
18
  ## v0.4.0 (2026-10-15)
9
19
 
10
20
  ### Feat
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: aind-codeocean-dispatch
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Launch, monitor, and capture batches of Code Ocean capsule runs
5
5
  Project-URL: Repository, https://github.com/AllenNeuralDynamics/aind-codeocean-dispatch/
6
6
  Project-URL: Issues, https://github.com/AllenNeuralDynamics/aind-codeocean-dispatch/issues
@@ -48,6 +48,23 @@ To develop the code, run:
48
48
  uv sync
49
49
  ```
50
50
 
51
+ ## Capturing runs from a post-run automation
52
+
53
+ A Code Ocean pipeline can name an automation capsule that runs after every run. A capsule
54
+ whose `code/run` is
55
+
56
+ ```bash
57
+ #!/usr/bin/env bash
58
+ set -e
59
+ python -m aind_codeocean_dispatch.automation
60
+ ```
61
+
62
+ captures each successful run as an internal data asset, named by the results'
63
+ `data_description.json` when it declares a derived name and otherwise after the first
64
+ input asset. It needs only `CODEOCEAN_TOKEN`; `CAPTURE_TAGS`, `CAPTURE_FAILED` and
65
+ `CAPTURE_PERMISSIONS` adjust it. It registers nothing in DocDB and writes no external
66
+ bucket, so pipelines that publish use `asset-creation-capsule` instead.
67
+
51
68
  ## Development
52
69
 
53
70
  Please test your changes using the full linting and testing suite:
@@ -31,6 +31,23 @@ To develop the code, run:
31
31
  uv sync
32
32
  ```
33
33
 
34
+ ## Capturing runs from a post-run automation
35
+
36
+ A Code Ocean pipeline can name an automation capsule that runs after every run. A capsule
37
+ whose `code/run` is
38
+
39
+ ```bash
40
+ #!/usr/bin/env bash
41
+ set -e
42
+ python -m aind_codeocean_dispatch.automation
43
+ ```
44
+
45
+ captures each successful run as an internal data asset, named by the results'
46
+ `data_description.json` when it declares a derived name and otherwise after the first
47
+ input asset. It needs only `CODEOCEAN_TOKEN`; `CAPTURE_TAGS`, `CAPTURE_FAILED` and
48
+ `CAPTURE_PERMISSIONS` adjust it. It registers nothing in DocDB and writes no external
49
+ bucket, so pipelines that publish use `asset-creation-capsule` instead.
50
+
34
51
  ## Development
35
52
 
36
53
  Please test your changes using the full linting and testing suite:
@@ -13,7 +13,7 @@ authors = [
13
13
  ]
14
14
  classifiers = ["Programming Language :: Python :: 3"]
15
15
  readme = "README.md"
16
- version = "0.4.0"
16
+ version = "0.5.0"
17
17
 
18
18
  dependencies = [
19
19
  "aind-code-ocean-pipeline-utils>=0.7.1",
@@ -41,24 +41,36 @@ main() {
41
41
  run() { uv run $UV_ARGS -- "$@"; }
42
42
  fi
43
43
 
44
- echo "+ ruff format"
45
- run ruff format
44
+ # Every step runs even after a failure so one pass reports all problems;
45
+ # the exit status is nonzero if any step failed.
46
+ FAILED=""
47
+ step() {
48
+ name="$1"
49
+ shift
50
+ echo "+ $name"
51
+ run "$@" || FAILED="$FAILED
52
+ $name"
53
+ }
54
+
55
+ step "ruff format" ruff format
46
56
 
47
57
  if [ "$CHECKS" = true ]; then
48
- echo "+ ruff check"
49
- run ruff check
50
- echo "+ mypy"
51
- run mypy
52
- echo "+ interrogate -v src"
53
- run interrogate -v src
54
- echo "+ codespell --check-filenames"
55
- run codespell --check-filenames
56
- echo "+ pytest --cov aind_codeocean_dispatch$([ -n "$PYTEST_ARGS" ] && printf ' -- %s' "$PYTEST_ARGS")"
58
+ step "ruff check" ruff check
59
+ step "mypy" mypy
60
+ step "interrogate -v src" interrogate -v src
61
+ step "codespell --check-filenames" codespell --check-filenames
57
62
  # shellcheck disable=SC2086
58
- run pytest --cov aind_codeocean_dispatch $PYTEST_ARGS
63
+ step "pytest --cov aind_codeocean_dispatch$([ -n "$PYTEST_ARGS" ] && printf ' -- %s' "$PYTEST_ARGS")" \
64
+ pytest --cov aind_codeocean_dispatch $PYTEST_ARGS
59
65
  else
60
66
  echo "(checks skipped; pass -c or --checks to enable)"
61
67
  fi
68
+
69
+ if [ -n "$FAILED" ]; then
70
+ echo "FAILED:$FAILED" >&2
71
+ return 1
72
+ fi
73
+ echo "All steps passed."
62
74
  }
63
75
 
64
76
  main "$@"
@@ -2,6 +2,7 @@
2
2
 
3
3
  from importlib.metadata import PackageNotFoundError, version
4
4
 
5
+ from .automation import capture_finished_run, read_only_retries
5
6
  from .capsule_git import capsule_head_commit, head_commit, run_owner_email
6
7
  from .capture import capture_as, capture_named_by_data_description, derived_name
7
8
  from .runner import (
@@ -28,6 +29,7 @@ __all__ = [
28
29
  "Outcome",
29
30
  "capsule_head_commit",
30
31
  "capture_as",
32
+ "capture_finished_run",
31
33
  "capture_named_by_data_description",
32
34
  "derived_name",
33
35
  "failed_without_results",
@@ -35,6 +37,7 @@ __all__ = [
35
37
  "job_key",
36
38
  "key_tag",
37
39
  "raise_for_failures",
40
+ "read_only_retries",
38
41
  "run_jobs",
39
42
  "run_owner_email",
40
43
  "succeeded",
@@ -0,0 +1,159 @@
1
+ """Capture a finished run as an internal data asset, from a Code Ocean post-run automation.
2
+
3
+ Code Ocean runs a pipeline's automation capsule after every run, passing the run as
4
+ ``CO_SOURCE_COMPUTATION_ID`` and ``CO_SOURCE_EXIT_CODE``. A capsule whose ``code/run`` is
5
+ ``python -m aind_codeocean_dispatch.automation`` captures that run whatever its results
6
+ hold: the name comes from a derived ``data_description.json`` when one declares it, and
7
+ otherwise from the first input asset and the capture time. It writes no external bucket
8
+ and no DocDB record, so it needs only a Code Ocean token, and it is no substitute for a
9
+ publishing automation that checks metadata before registering it.
10
+
11
+ Configured by the capsule's environment:
12
+
13
+ - ``CODEOCEAN_TOKEN`` (required) and ``CODEOCEAN_DOMAIN``.
14
+ - ``CAPTURE_TAGS``: comma-separated tags for the asset.
15
+ - ``CAPTURE_FAILED``: truthy to capture failed runs that left results.
16
+ - ``CAPTURE_PERMISSIONS``: a ``Permissions`` object as JSON, applied once the asset is Ready.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import json
22
+ import logging
23
+ import os
24
+ import time
25
+ from collections.abc import Sequence
26
+ from typing import TYPE_CHECKING
27
+
28
+ from aind_code_ocean_pipeline_utils import parse_truthy
29
+ from codeocean import CodeOcean
30
+ from codeocean.components import Permissions
31
+ from codeocean.computation import Computation
32
+ from codeocean.data_asset import DataAsset, DataAssetState
33
+ from urllib3.util import Retry
34
+
35
+ from .capture import capture_named_by_data_description
36
+ from .runner import succeeded
37
+
38
+ if TYPE_CHECKING:
39
+ from collections.abc import Mapping
40
+
41
+ __all__ = ["capture_finished_run", "main", "read_only_retries"]
42
+
43
+ logger = logging.getLogger(__name__)
44
+
45
+ DEFAULT_DOMAIN = "https://codeocean.allenneuraldynamics.org"
46
+
47
+ # Indirected so tests need not wait.
48
+ _sleep = time.sleep
49
+
50
+
51
+ def read_only_retries() -> Retry:
52
+ """Retry 429 and 5xx on GET only; a resent ``create_data_asset`` could duplicate the asset."""
53
+ return Retry(
54
+ total=5,
55
+ backoff_factor=2,
56
+ status_forcelist=[429, 500, 502, 503, 504],
57
+ allowed_methods=frozenset({"GET"}),
58
+ )
59
+
60
+
61
+ def capture_finished_run(
62
+ client: CodeOcean,
63
+ computation_id: str,
64
+ exit_code: int,
65
+ *,
66
+ tags: Sequence[str] = (),
67
+ capture_failed: bool = False,
68
+ permissions: Permissions | None = None,
69
+ poll_interval_s: float = 60.0,
70
+ ) -> DataAsset | None:
71
+ """Capture *computation_id*'s results and wait until the asset is Ready.
72
+
73
+ Parameters
74
+ ----------
75
+ client : CodeOcean
76
+ Authenticated client; see :func:`read_only_retries` for a safe ``retries``.
77
+ computation_id, exit_code
78
+ The finished run, as Code Ocean passes it to the automation.
79
+ tags : Sequence[str], optional
80
+ Tags for the asset.
81
+ capture_failed : bool, optional
82
+ Capture a failed run too, provided it left results.
83
+ permissions : Permissions, optional
84
+ Applied once the asset is Ready; ``None`` leaves Code Ocean's default.
85
+ poll_interval_s : float, optional
86
+ Seconds between checks of the asset's state.
87
+
88
+ Returns
89
+ -------
90
+ DataAsset or None
91
+ The Ready asset, or ``None`` when the run was skipped.
92
+
93
+ Raises
94
+ ------
95
+ RuntimeError
96
+ If the capture ends in the Failed state.
97
+ """
98
+ source = client.computations.get_computation(computation_id)
99
+ if not (exit_code == 0 and succeeded(source)) and not capture_failed:
100
+ logger.info("computation %s did not succeed (exit code %d); not capturing", computation_id, exit_code)
101
+ return None
102
+ if source.has_results is False:
103
+ logger.info("computation %s left no results; nothing to capture", computation_id)
104
+ return None
105
+ params = capture_named_by_data_description(client, _fallback_name(client, source), tags)(source)
106
+ created = client.data_assets.create_data_asset(params)
107
+ logger.info("capturing computation %s as %s (%s)", computation_id, created.id, params.name)
108
+ ready = _wait_until_settled(client, created.id, poll_interval_s)
109
+ if ready.state == DataAssetState.Failed:
110
+ raise RuntimeError(f"capture {created.id} of computation {computation_id} failed")
111
+ if permissions is not None:
112
+ client.data_assets.update_permissions(ready.id, permissions)
113
+ logger.info("captured computation %s as %s", computation_id, ready.id)
114
+ return ready
115
+
116
+
117
+ def _fallback_name(client: CodeOcean, source: Computation) -> str:
118
+ """Name a capture after the run's first input asset, or the run itself if it has none."""
119
+ if source.data_assets:
120
+ try:
121
+ return str(client.data_assets.get_data_asset(source.data_assets[0].id).name)
122
+ except Exception as exc: # noqa: BLE001 - the name is cosmetic; the capture is not
123
+ logger.warning("could not read input asset %s: %s", source.data_assets[0].id, exc)
124
+ return str(source.name)
125
+
126
+
127
+ def _wait_until_settled(client: CodeOcean, asset_id: str, poll_interval_s: float) -> DataAsset:
128
+ while True:
129
+ asset = client.data_assets.get_data_asset(asset_id)
130
+ if asset.state in (DataAssetState.Ready, DataAssetState.Failed):
131
+ return asset
132
+ _sleep(poll_interval_s)
133
+
134
+
135
+ def _client_from_env(env: Mapping[str, str]) -> CodeOcean:
136
+ return CodeOcean(
137
+ domain=env.get("CODEOCEAN_DOMAIN", DEFAULT_DOMAIN),
138
+ token=env["CODEOCEAN_TOKEN"],
139
+ retries=read_only_retries(),
140
+ )
141
+
142
+
143
+ def main(env: Mapping[str, str] | None = None) -> None:
144
+ """Capture the run Code Ocean names in the environment; see the module docstring."""
145
+ env = os.environ if env is None else env
146
+ logging.basicConfig(level=env.get("LOG_LEVEL", "INFO"))
147
+ raw_permissions = env.get("CAPTURE_PERMISSIONS")
148
+ capture_finished_run(
149
+ _client_from_env(env),
150
+ env["CO_SOURCE_COMPUTATION_ID"],
151
+ int(env["CO_SOURCE_EXIT_CODE"]),
152
+ tags=[tag.strip() for tag in env.get("CAPTURE_TAGS", "").split(",") if tag.strip()],
153
+ capture_failed=parse_truthy(env.get("CAPTURE_FAILED", "")),
154
+ permissions=Permissions.from_dict(json.loads(raw_permissions)) if raw_permissions else None,
155
+ )
156
+
157
+
158
+ if __name__ == "__main__":
159
+ main()
@@ -0,0 +1,181 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import re
5
+ from dataclasses import dataclass, field
6
+ from typing import Any
7
+
8
+ import pytest
9
+ from codeocean.components import EveryoneRole, Permissions
10
+ from codeocean.computation import Computation, ComputationEndStatus, ComputationState, InputDataAsset
11
+ from codeocean.data_asset import DataAsset, DataAssetParams, DataAssetState
12
+ from urllib3.util import Retry
13
+
14
+ from aind_codeocean_dispatch import automation
15
+ from aind_codeocean_dispatch.automation import capture_finished_run, read_only_retries
16
+ from tests.fakes import asset, build
17
+
18
+
19
+ def computation(
20
+ *,
21
+ exit_code: int = 0,
22
+ end_status: ComputationEndStatus = ComputationEndStatus.Succeeded,
23
+ has_results: bool = True,
24
+ inputs: tuple[str, ...] = ("raw-1",),
25
+ ) -> Computation:
26
+ return build(
27
+ Computation,
28
+ id="comp-1",
29
+ created=0,
30
+ name="Run 1",
31
+ owner="owner",
32
+ run_time=0,
33
+ state=ComputationState.Completed,
34
+ end_status=end_status,
35
+ exit_code=exit_code,
36
+ has_results=has_results,
37
+ data_assets=[InputDataAsset(id=i, mount="in") for i in inputs],
38
+ )
39
+
40
+
41
+ @dataclass
42
+ class _Computations:
43
+ source: Computation
44
+
45
+ def get_computation(self, computation_id: str) -> Computation:
46
+ assert computation_id == self.source.id
47
+ return self.source
48
+
49
+ def list_computation_results(self, computation_id: str, path: str = "") -> Any:
50
+ return type("Folder", (), {"items": []})()
51
+
52
+
53
+ @dataclass
54
+ class _DataAssets:
55
+ capture_states: list[DataAssetState] = field(default_factory=lambda: [DataAssetState.Draft, DataAssetState.Ready])
56
+ input_error: Exception | None = None
57
+ created: list[DataAssetParams] = field(default_factory=list)
58
+ permissions: list[tuple[str, Permissions]] = field(default_factory=list)
59
+
60
+ def get_data_asset(self, data_asset_id: str) -> DataAsset:
61
+ if data_asset_id == "capture-0":
62
+ state = self.capture_states.pop(0) if len(self.capture_states) > 1 else self.capture_states[0]
63
+ return asset(data_asset_id, state)
64
+ if self.input_error is not None:
65
+ raise self.input_error
66
+ found = asset(data_asset_id, DataAssetState.Ready)
67
+ return build(DataAsset, **{**vars(found), "name": f"{data_asset_id}-name"})
68
+
69
+ def create_data_asset(self, data_asset_params: DataAssetParams) -> DataAsset:
70
+ self.created.append(data_asset_params)
71
+ return asset("capture-0", DataAssetState.Draft)
72
+
73
+ def update_permissions(self, data_asset_id: str, permissions: Permissions) -> None:
74
+ self.permissions.append((data_asset_id, permissions))
75
+
76
+
77
+ @dataclass
78
+ class _Client:
79
+ computations: _Computations
80
+ data_assets: _DataAssets
81
+
82
+
83
+ @pytest.fixture(autouse=True)
84
+ def no_wait(monkeypatch: pytest.MonkeyPatch) -> list[float]:
85
+ sleeps: list[float] = []
86
+ monkeypatch.setattr(automation, "_sleep", sleeps.append)
87
+ return sleeps
88
+
89
+
90
+ def client_for(source: Computation, **assets: Any) -> Any:
91
+ return _Client(_Computations(source), _DataAssets(**assets))
92
+
93
+
94
+ def test_captures_a_successful_run_named_after_its_input(no_wait: list[float]) -> None:
95
+ client = client_for(computation())
96
+
97
+ result = capture_finished_run(client, "comp-1", 0, tags=["exp"], poll_interval_s=7)
98
+
99
+ assert result is not None and result.state == DataAssetState.Ready
100
+ [params] = client.data_assets.created
101
+ assert re.fullmatch(r"raw-1-name_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}", params.name)
102
+ assert params.tags == ["exp"]
103
+ assert params.source.computation.id == "comp-1"
104
+ assert no_wait == [7]
105
+ assert client.data_assets.permissions == []
106
+
107
+
108
+ @pytest.mark.parametrize(
109
+ ("exit_code", "end_status"), [(1, ComputationEndStatus.Failed), (0, ComputationEndStatus.Failed)]
110
+ )
111
+ def test_skips_a_failed_run_by_default(exit_code: int, end_status: ComputationEndStatus) -> None:
112
+ client = client_for(computation(exit_code=exit_code, end_status=end_status))
113
+
114
+ assert capture_finished_run(client, "comp-1", exit_code) is None
115
+ assert client.data_assets.created == []
116
+
117
+
118
+ def test_captures_a_failed_run_when_asked() -> None:
119
+ client = client_for(computation(exit_code=1, end_status=ComputationEndStatus.Failed))
120
+
121
+ assert capture_finished_run(client, "comp-1", 1, capture_failed=True) is not None
122
+ assert len(client.data_assets.created) == 1
123
+
124
+
125
+ def test_skips_a_run_without_results_even_when_asked() -> None:
126
+ client = client_for(computation(exit_code=1, end_status=ComputationEndStatus.Failed, has_results=False))
127
+
128
+ assert capture_finished_run(client, "comp-1", 1, capture_failed=True) is None
129
+ assert client.data_assets.created == []
130
+
131
+
132
+ def test_falls_back_to_the_run_name_without_a_readable_input() -> None:
133
+ for client in (client_for(computation(inputs=())), client_for(computation(), input_error=RuntimeError("gone"))):
134
+ capture_finished_run(client, "comp-1", 0)
135
+ assert client.data_assets.created[0].name.startswith("Run 1_")
136
+
137
+
138
+ def test_failed_capture_raises() -> None:
139
+ client = client_for(computation(), capture_states=[DataAssetState.Failed])
140
+
141
+ with pytest.raises(RuntimeError, match="capture-0"):
142
+ capture_finished_run(client, "comp-1", 0)
143
+ assert client.data_assets.permissions == []
144
+
145
+
146
+ def test_applies_permissions_once_ready() -> None:
147
+ client = client_for(computation())
148
+ permissions = Permissions(everyone=EveryoneRole.Viewer)
149
+
150
+ capture_finished_run(client, "comp-1", 0, permissions=permissions)
151
+
152
+ assert client.data_assets.permissions == [("capture-0", permissions)]
153
+
154
+
155
+ def test_main_reads_the_environment(monkeypatch: pytest.MonkeyPatch) -> None:
156
+ client = client_for(computation(exit_code=1, end_status=ComputationEndStatus.Failed))
157
+ monkeypatch.setattr(automation, "_client_from_env", lambda env: client)
158
+
159
+ automation.main(
160
+ {
161
+ "CODEOCEAN_TOKEN": "x",
162
+ "CO_SOURCE_COMPUTATION_ID": "comp-1",
163
+ "CO_SOURCE_EXIT_CODE": "1",
164
+ "CAPTURE_TAGS": "exp, ecephys,,",
165
+ "CAPTURE_FAILED": "yes",
166
+ "CAPTURE_PERMISSIONS": json.dumps({"everyone": "viewer"}),
167
+ }
168
+ )
169
+
170
+ assert client.data_assets.created[0].tags == ["exp", "ecephys"]
171
+ assert client.data_assets.permissions == [("capture-0", Permissions(everyone=EveryoneRole.Viewer))]
172
+
173
+
174
+ def test_client_from_env_retries_reads_only() -> None:
175
+ client = automation._client_from_env({"CODEOCEAN_TOKEN": "x"})
176
+
177
+ assert client.domain == automation.DEFAULT_DOMAIN
178
+ retries = client.retries
179
+ assert isinstance(retries, Retry)
180
+ assert retries.is_retry("GET", 503) and not retries.is_retry("POST", 503)
181
+ assert read_only_retries().allowed_methods == frozenset({"GET"})
@@ -17,7 +17,7 @@ wheels = [
17
17
 
18
18
  [[package]]
19
19
  name = "aind-codeocean-dispatch"
20
- version = "0.4.0"
20
+ version = "0.5.0"
21
21
  source = { editable = "." }
22
22
  dependencies = [
23
23
  { name = "aind-code-ocean-pipeline-utils" },