auto-trainer-api 0.9.22__tar.gz → 0.9.24__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 (47) hide show
  1. auto_trainer_api-0.9.24/.gitignore +46 -0
  2. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/PKG-INFO +17 -38
  3. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/README.md +131 -152
  4. auto_trainer_api-0.9.24/publish-testpypi.py +137 -0
  5. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/pyproject.toml +49 -45
  6. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/__init__.py +1 -2
  7. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/api_detector_kind.py +1 -1
  8. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/api_system_status.py +3 -2
  9. auto_trainer_api-0.9.24/src/autotrainer/api/event/__init__.py +18 -0
  10. {auto_trainer_api-0.9.22/src/autotrainer/api → auto_trainer_api-0.9.24/src/autotrainer/api/event}/api_event.py +3 -0
  11. auto_trainer_api-0.9.24/src/autotrainer/api/event/api_event_kind.py +482 -0
  12. auto_trainer_api-0.9.24/src/autotrainer/api/event/api_event_payloads.py +436 -0
  13. auto_trainer_api-0.9.24/src/autotrainer/api/event/build_event.py +287 -0
  14. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/rpc_service.py +1 -2
  15. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/util.py +3 -1
  16. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/tests/test_api_event.py +2 -2
  17. auto_trainer_api-0.9.24/tests/test_build_event.py +63 -0
  18. auto_trainer_api-0.9.24/tests/test_util.py +31 -0
  19. auto_trainer_api-0.9.24/uv.lock +1499 -0
  20. auto_trainer_api-0.9.22/.gitattributes +0 -63
  21. auto_trainer_api-0.9.22/.github/workflows/publish.yml +0 -77
  22. auto_trainer_api-0.9.22/.gitignore +0 -355
  23. auto_trainer_api-0.9.22/scripts/client_application.py +0 -231
  24. auto_trainer_api-0.9.22/scripts/remote_console.py +0 -124
  25. auto_trainer_api-0.9.22/src/autotrainer/api/api_event_kind.py +0 -402
  26. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/api_alarm_kind.py +0 -0
  27. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/api_application_mode.py +0 -0
  28. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/api_options.py +0 -0
  29. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/api_system_configuration.py +0 -0
  30. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/api_training_mode.py +0 -0
  31. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/bridge/__init__.py +0 -0
  32. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/bridge/__main__.py +0 -0
  33. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/bridge/bridge_app.py +0 -0
  34. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/bridge/bridge_service.py +0 -0
  35. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/command/__init__.py +0 -0
  36. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/command/api_command.py +0 -0
  37. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/command/api_command_request.py +0 -0
  38. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/command/api_command_request_response.py +0 -0
  39. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/command/api_command_request_result.py +0 -0
  40. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/command/command_request_delegate.py +0 -0
  41. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/telemetry/__init__.py +0 -0
  42. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/telemetry/open_telemetry_service.py +0 -0
  43. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/zeromq/__init__.py +0 -0
  44. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/src/autotrainer/api/zeromq/zeromq_api_service.py +0 -0
  45. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/tests/test_api_basics.py +0 -0
  46. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/tests/test_bridge_service.py +0 -0
  47. {auto_trainer_api-0.9.22 → auto_trainer_api-0.9.24}/tests/test_resolve_enum.py +0 -0
@@ -0,0 +1,46 @@
1
+ .idea
2
+
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+
8
+ # Virtual environments
9
+ .venv/
10
+
11
+ # C extensions
12
+ *.so
13
+
14
+ # Distribution / packaging
15
+ .Python
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ downloads/
20
+ eggs/
21
+ .eggs/
22
+ lib/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ share/python-wheels/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+ MANIFEST
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ site/
41
+
42
+ # Installer logs
43
+ pip-log.txt
44
+ pip-delete-this-directory.txt
45
+
46
+ .DS_Store
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: auto-trainer-api
3
- Version: 0.9.22
3
+ Version: 0.9.24
4
4
  Summary: API for interfacing with the core acquisition process via platform and language agnostic message queues.
5
5
  License: AGPL-3.0-only
6
6
  Classifier: Operating System :: OS Independent
@@ -118,53 +118,32 @@ python -m autotrainer.api.bridge --host 0.0.0.0 --port 8000
118
118
  Or created programmatically via `create_bridge_app(options, command_timeout, cors_allowed_origins)` for embedding
119
119
  into a larger application. Requires the `bridge` optional dependency group (`pip install auto-trainer-api[bridge]`).
120
120
 
121
- ## Tools
121
+ ## Publishing
122
+ Publishing is handled automatically via GitHub Actions. Pushing a version tag (e.g., `v0.9.18`) triggers the
123
+ CI workflow which runs the test suite, builds the package, and publishes to PyPI using trusted publishing (OIDC).
124
+
125
+ Pushes to the `workflows-edit` branch publish to TestPyPI for verification.
122
126
 
123
- ### Client Application
124
- `scripts/client_application.py` starts an interactive process that enables the `RpcService` as a "real" autotrainer
125
- application would. It generates heartbeat events, periodically publishes system status events, and responds to
126
- commands (`GET_CONFIGURATION`, `GET_STATUS`). Run with:
127
+ ### Local TestPyPI Publishing
128
+ To publish a dev build to TestPyPI from a local checkout (this is separate from the CI flow above):
127
129
 
128
130
  ```
129
- python scripts/client_application.py
131
+ cd packages/auto-trainer-api
132
+ uv run --script publish-testpypi.py
130
133
  ```
131
134
 
132
- The following interactive commands are available:
133
-
134
- * `app_launch` - publish an `applicationLaunched` event
135
- * `e_stop` - publish an `emergencyStop` event
136
- * `e_resume` - publish an `emergencyResume` event
137
- * `detector` / `d` `<detector_id> <is_active>` - update a detector's status and publish a `detectorChanged` event
138
- * `alarm` / `a` `<alarm_id> <is_active> <is_enabled>` - update an alarm's status and publish an `alarmChanged` event
139
- * `magnet` `<intensity>` - set the tunnel device magnet intensity (0.0-100.0)
140
- * `baseline` `<intensity>` - set the baseline magnet intensity (0.0-100.0) and publish a `headfixBaselineChanged` event
141
- * `q` / `quit` - stop the service and exit
142
-
143
- Detector and alarm IDs can be specified by numeric value, exact enum name, or a unique prefix of the name
144
- (case-insensitive).
145
-
146
- This is primarily useful for testing remote applications/services without running the main autotrainer
147
- acquisition application.
148
-
149
- ### Remote Console
150
- `scripts/remote_console.py` starts an interactive process that connects to an `RpcService` instance in the same manner
151
- full remote management services would. Run with:
135
+ Each run appends a fresh `.devN` suffix to the version, where N is one past the highest dev
136
+ release already on TestPyPI (0 if there are none). It builds with `uv` and uploads with `twine`,
137
+ both pulled in on demand via the script's inline dependencies, so nothing is installed into the
138
+ project by default. Set `TESTPYPI_TOKEN` to a TestPyPI API token to upload non-interactively;
139
+ otherwise you are prompted to paste it:
152
140
 
153
141
  ```
154
- python scripts/remote_console.py [-H <host>]
142
+ TESTPYPI_TOKEN=pypi-... uv run --script publish-testpypi.py
155
143
  ```
156
144
 
157
- It supports the `-H`/`--host` argument to specify a remote host address (defaults to `127.0.0.1`).
158
- Available commands: `start`, `stop`, `configuration`, `status`, `quit`.
159
-
160
- ## Publishing
161
- Publishing is handled automatically via GitHub Actions. Pushing a version tag (e.g., `v0.9.18`) triggers the
162
- CI workflow which runs the test suite, builds the package, and publishes to PyPI using trusted publishing (OIDC).
163
-
164
- Pushes to the `workflows-edit` branch publish to TestPyPI for verification.
165
-
166
145
  ## Installation
167
- The package is published to the PyPi package index and can be installed with standard pip commands.
146
+ The package is published to the PyPI package index and can be installed with standard pip commands.
168
147
 
169
148
  ```
170
149
  pip install auto-trainer-api
@@ -1,152 +1,131 @@
1
- # Autotrainer API: Python Integration
2
-
3
- The python `auto-trainer-api` module is intended to provide an efficient means to emit information that
4
- is needed for local or remote management of applications running locally on the device and to receive commands from
5
- those sources.
6
-
7
- The exposed API is intended to be agnostic to the underlying transport layer. The current implementation uses
8
- ZeroMQ. The reasons for this decision include:
9
- * Relatively low overhead for the acquisition application
10
- * Does not require either side to manage connections and know when the other side is available or changes availability
11
- * Does not require an additional process or service to maintain a persistent message queue (e.g., RabbitMQ)
12
- * Persistent data is managed elsewhere
13
-
14
- ## Client Integration
15
- There are two points of integration available for clients to support the remote interface. The first allows publishing
16
- "events" for state and property changes that occur in the client. The second is a "command" interface for the client
17
- to receive command requests from remote sources.
18
-
19
- Both interfaces are provided through an instance of the `RpcService` class. An instance can be obtained via
20
- `create_api_service(...)` which constructs the specific concrete implementation. After creation, the service must
21
- be explicitly started (`start(...)`) and can be stopped (`stop(...)`). Once stopped, an instance can not be
22
- restarted. If a connection should be reestablished after stopping an instance, a new instance should be created and
23
- started.
24
-
25
- ### Events
26
- Events are published through the `send_event_dict(message)` or `send_event(message)` methods on the `RpcService`
27
- instance.
28
-
29
- `send_event_dict` accepts a dictionary with the following entries:
30
- * `kind` - an `ApiEventKind` value
31
- * `when` - a wall-clock value of time
32
- * `index` - monotonically increasing timestamp w/units of nanoseconds (typically `time.perf_counter_ns()`)
33
- * `context` - an object whose contents depend on the `ApiEventKind`; may be None for some event kinds
34
-
35
- `send_event` accepts an `ApiEvent` dataclass instance with the same fields.
36
-
37
- Emergency events (`ApiEventKind.emergencyStop`, `ApiEventKind.emergencyResume`) are automatically published on both
38
- the standard event channel and a dedicated emergency channel for subscribers that only monitor critical events.
39
-
40
- ### Commands
41
- Commands from external sources are supported by registering a `CommandRequestDelegate` with the `RpcService` instance
42
- via the `command_request_delegate` property. The delegate receives an instance of `ApiCommandRequest` and must return
43
- an instance of `ApiCommandRequestResponse`.
44
-
45
- The primary property of the `ApiCommandRequest` is `command` which is an `ApiCommand` value. Depending on the command,
46
- there may also be a dictionary in the `data` property with arguments or other information relevant to the command.
47
- The `nonce` property can be ignored if the command is handled synchronously. For commands that send an asynchronous
48
- result after completion (see below), the nonce must be stored to associate with the result (along with the `command`
49
- value).
50
-
51
- The returned `ApiCommandRequestResponse` object contains one required field:
52
- * `result` - a value of `ApiCommandRequestResult`
53
-
54
- And three optional fields:
55
- * `data` - an optional object with results from the command beyond success/failure (often will be None)
56
- * `error_code` - an integer error code value if the command is not successful or can't be initiated
57
- * `error_message` - an optional string message if the command is not successful or can't be initiated
58
-
59
- The expected contents of the `data` property are defined by the command, but is typically `None`.
60
-
61
- The `error_code` property should be a non-zero value if there is an error code to report.
62
-
63
- There are two fields on the `ApiCommandRequestResponse` object that are ignored as part of the returned object from
64
- the command delegate: `command` and `nonce`. See _Asynchronous Commands_ for when these fields are required.
65
-
66
-
67
- #### Asynchronous Commands
68
- The command delegate is expected to return "immediately" (low millisecond type of time frame). If the command is not
69
- deterministically fast, it is expected to immediately return an `ApiCommandRequestResponse` with a `result` value of
70
- `ApiCommandRequestResult.PENDING_WITH_NOTIFICATION`.
71
-
72
- Once the action associated with the command is complete, the client should call `send_command_result(response)` on the
73
- `RpcService` instance. The `response` argument is an `ApiCommandRequestResponse` instance with the `command` and
74
- `nonce` properties set to the values received in the original `ApiCommandRequest` (the client is responsible for
75
- storing these values until needed). Note that those two properties are ignored for synchronous command handling, but
76
- required for asynchronous responses.
77
-
78
- ## Bridge
79
-
80
- The `autotrainer.api.bridge` module provides a Socket.IO bridge that allows web-based clients to interact with the
81
- RPC service without a direct ZeroMQ connection. It exposes a FastAPI/Socket.IO application that:
82
-
83
- * Forwards command requests from the RPC service to connected Socket.IO clients
84
- * Accepts command results from Socket.IO clients and relays them back to the RPC service
85
- * Allows Socket.IO clients to publish events via the `sendApiEvent` message
86
-
87
- The bridge can be started as a standalone process:
88
-
89
- ```
90
- python -m autotrainer.api.bridge --host 0.0.0.0 --port 8000
91
- ```
92
-
93
- Or created programmatically via `create_bridge_app(options, command_timeout, cors_allowed_origins)` for embedding
94
- into a larger application. Requires the `bridge` optional dependency group (`pip install auto-trainer-api[bridge]`).
95
-
96
- ## Tools
97
-
98
- ### Client Application
99
- `scripts/client_application.py` starts an interactive process that enables the `RpcService` as a "real" autotrainer
100
- application would. It generates heartbeat events, periodically publishes system status events, and responds to
101
- commands (`GET_CONFIGURATION`, `GET_STATUS`). Run with:
102
-
103
- ```
104
- python scripts/client_application.py
105
- ```
106
-
107
- The following interactive commands are available:
108
-
109
- * `app_launch` - publish an `applicationLaunched` event
110
- * `e_stop` - publish an `emergencyStop` event
111
- * `e_resume` - publish an `emergencyResume` event
112
- * `detector` / `d` `<detector_id> <is_active>` - update a detector's status and publish a `detectorChanged` event
113
- * `alarm` / `a` `<alarm_id> <is_active> <is_enabled>` - update an alarm's status and publish an `alarmChanged` event
114
- * `magnet` `<intensity>` - set the tunnel device magnet intensity (0.0-100.0)
115
- * `baseline` `<intensity>` - set the baseline magnet intensity (0.0-100.0) and publish a `headfixBaselineChanged` event
116
- * `q` / `quit` - stop the service and exit
117
-
118
- Detector and alarm IDs can be specified by numeric value, exact enum name, or a unique prefix of the name
119
- (case-insensitive).
120
-
121
- This is primarily useful for testing remote applications/services without running the main autotrainer
122
- acquisition application.
123
-
124
- ### Remote Console
125
- `scripts/remote_console.py` starts an interactive process that connects to an `RpcService` instance in the same manner
126
- full remote management services would. Run with:
127
-
128
- ```
129
- python scripts/remote_console.py [-H <host>]
130
- ```
131
-
132
- It supports the `-H`/`--host` argument to specify a remote host address (defaults to `127.0.0.1`).
133
- Available commands: `start`, `stop`, `configuration`, `status`, `quit`.
134
-
135
- ## Publishing
136
- Publishing is handled automatically via GitHub Actions. Pushing a version tag (e.g., `v0.9.18`) triggers the
137
- CI workflow which runs the test suite, builds the package, and publishes to PyPI using trusted publishing (OIDC).
138
-
139
- Pushes to the `workflows-edit` branch publish to TestPyPI for verification.
140
-
141
- ## Installation
142
- The package is published to the PyPi package index and can be installed with standard pip commands.
143
-
144
- ```
145
- pip install auto-trainer-api
146
- ```
147
-
148
- Optional dependency groups:
149
- ```
150
- pip install auto-trainer-api[bridge] # Socket.IO bridge dependencies
151
- pip install auto-trainer-api[telemetry] # OpenTelemetry support
152
- ```
1
+ # Autotrainer API: Python Integration
2
+
3
+ The python `auto-trainer-api` module is intended to provide an efficient means to emit information that
4
+ is needed for local or remote management of applications running locally on the device and to receive commands from
5
+ those sources.
6
+
7
+ The exposed API is intended to be agnostic to the underlying transport layer. The current implementation uses
8
+ ZeroMQ. The reasons for this decision include:
9
+ * Relatively low overhead for the acquisition application
10
+ * Does not require either side to manage connections and know when the other side is available or changes availability
11
+ * Does not require an additional process or service to maintain a persistent message queue (e.g., RabbitMQ)
12
+ * Persistent data is managed elsewhere
13
+
14
+ ## Client Integration
15
+ There are two points of integration available for clients to support the remote interface. The first allows publishing
16
+ "events" for state and property changes that occur in the client. The second is a "command" interface for the client
17
+ to receive command requests from remote sources.
18
+
19
+ Both interfaces are provided through an instance of the `RpcService` class. An instance can be obtained via
20
+ `create_api_service(...)` which constructs the specific concrete implementation. After creation, the service must
21
+ be explicitly started (`start(...)`) and can be stopped (`stop(...)`). Once stopped, an instance can not be
22
+ restarted. If a connection should be reestablished after stopping an instance, a new instance should be created and
23
+ started.
24
+
25
+ ### Events
26
+ Events are published through the `send_event_dict(message)` or `send_event(message)` methods on the `RpcService`
27
+ instance.
28
+
29
+ `send_event_dict` accepts a dictionary with the following entries:
30
+ * `kind` - an `ApiEventKind` value
31
+ * `when` - a wall-clock value of time
32
+ * `index` - monotonically increasing timestamp w/units of nanoseconds (typically `time.perf_counter_ns()`)
33
+ * `context` - an object whose contents depend on the `ApiEventKind`; may be None for some event kinds
34
+
35
+ `send_event` accepts an `ApiEvent` dataclass instance with the same fields.
36
+
37
+ Emergency events (`ApiEventKind.emergencyStop`, `ApiEventKind.emergencyResume`) are automatically published on both
38
+ the standard event channel and a dedicated emergency channel for subscribers that only monitor critical events.
39
+
40
+ ### Commands
41
+ Commands from external sources are supported by registering a `CommandRequestDelegate` with the `RpcService` instance
42
+ via the `command_request_delegate` property. The delegate receives an instance of `ApiCommandRequest` and must return
43
+ an instance of `ApiCommandRequestResponse`.
44
+
45
+ The primary property of the `ApiCommandRequest` is `command` which is an `ApiCommand` value. Depending on the command,
46
+ there may also be a dictionary in the `data` property with arguments or other information relevant to the command.
47
+ The `nonce` property can be ignored if the command is handled synchronously. For commands that send an asynchronous
48
+ result after completion (see below), the nonce must be stored to associate with the result (along with the `command`
49
+ value).
50
+
51
+ The returned `ApiCommandRequestResponse` object contains one required field:
52
+ * `result` - a value of `ApiCommandRequestResult`
53
+
54
+ And three optional fields:
55
+ * `data` - an optional object with results from the command beyond success/failure (often will be None)
56
+ * `error_code` - an integer error code value if the command is not successful or can't be initiated
57
+ * `error_message` - an optional string message if the command is not successful or can't be initiated
58
+
59
+ The expected contents of the `data` property are defined by the command, but is typically `None`.
60
+
61
+ The `error_code` property should be a non-zero value if there is an error code to report.
62
+
63
+ There are two fields on the `ApiCommandRequestResponse` object that are ignored as part of the returned object from
64
+ the command delegate: `command` and `nonce`. See _Asynchronous Commands_ for when these fields are required.
65
+
66
+
67
+ #### Asynchronous Commands
68
+ The command delegate is expected to return "immediately" (low millisecond type of time frame). If the command is not
69
+ deterministically fast, it is expected to immediately return an `ApiCommandRequestResponse` with a `result` value of
70
+ `ApiCommandRequestResult.PENDING_WITH_NOTIFICATION`.
71
+
72
+ Once the action associated with the command is complete, the client should call `send_command_result(response)` on the
73
+ `RpcService` instance. The `response` argument is an `ApiCommandRequestResponse` instance with the `command` and
74
+ `nonce` properties set to the values received in the original `ApiCommandRequest` (the client is responsible for
75
+ storing these values until needed). Note that those two properties are ignored for synchronous command handling, but
76
+ required for asynchronous responses.
77
+
78
+ ## Bridge
79
+
80
+ The `autotrainer.api.bridge` module provides a Socket.IO bridge that allows web-based clients to interact with the
81
+ RPC service without a direct ZeroMQ connection. It exposes a FastAPI/Socket.IO application that:
82
+
83
+ * Forwards command requests from the RPC service to connected Socket.IO clients
84
+ * Accepts command results from Socket.IO clients and relays them back to the RPC service
85
+ * Allows Socket.IO clients to publish events via the `sendApiEvent` message
86
+
87
+ The bridge can be started as a standalone process:
88
+
89
+ ```
90
+ python -m autotrainer.api.bridge --host 0.0.0.0 --port 8000
91
+ ```
92
+
93
+ Or created programmatically via `create_bridge_app(options, command_timeout, cors_allowed_origins)` for embedding
94
+ into a larger application. Requires the `bridge` optional dependency group (`pip install auto-trainer-api[bridge]`).
95
+
96
+ ## Publishing
97
+ Publishing is handled automatically via GitHub Actions. Pushing a version tag (e.g., `v0.9.18`) triggers the
98
+ CI workflow which runs the test suite, builds the package, and publishes to PyPI using trusted publishing (OIDC).
99
+
100
+ Pushes to the `workflows-edit` branch publish to TestPyPI for verification.
101
+
102
+ ### Local TestPyPI Publishing
103
+ To publish a dev build to TestPyPI from a local checkout (this is separate from the CI flow above):
104
+
105
+ ```
106
+ cd packages/auto-trainer-api
107
+ uv run --script publish-testpypi.py
108
+ ```
109
+
110
+ Each run appends a fresh `.devN` suffix to the version, where N is one past the highest dev
111
+ release already on TestPyPI (0 if there are none). It builds with `uv` and uploads with `twine`,
112
+ both pulled in on demand via the script's inline dependencies, so nothing is installed into the
113
+ project by default. Set `TESTPYPI_TOKEN` to a TestPyPI API token to upload non-interactively;
114
+ otherwise you are prompted to paste it:
115
+
116
+ ```
117
+ TESTPYPI_TOKEN=pypi-... uv run --script publish-testpypi.py
118
+ ```
119
+
120
+ ## Installation
121
+ The package is published to the PyPI package index and can be installed with standard pip commands.
122
+
123
+ ```
124
+ pip install auto-trainer-api
125
+ ```
126
+
127
+ Optional dependency groups:
128
+ ```
129
+ pip install auto-trainer-api[bridge] # Socket.IO bridge dependencies
130
+ pip install auto-trainer-api[telemetry] # OpenTelemetry support
131
+ ```
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env -S uv run --script
2
+ # /// script
3
+ # requires-python = ">=3.11"
4
+ # dependencies = ["build", "twine"]
5
+ # ///
6
+ """Publish auto-trainer-api to TestPyPI from a local build.
7
+
8
+ Run from the package root:
9
+
10
+ cd packages/auto-trainer-api
11
+ uv run --script publish-testpypi.py # or, since it is executable: ./publish-testpypi.py
12
+
13
+ This is intentionally separate from .github/workflows/publish.yml (which uses
14
+ trusted publishing / OIDC to the real PyPI). `build` and `twine` come from this
15
+ script's inline (PEP 723) dependencies, which uv installs into an ephemeral
16
+ environment on demand -- nothing is added to the project by default.
17
+
18
+ Dev versioning:
19
+ Each run appends a fresh PEP 440 ".devN" suffix to the base version in
20
+ the repository VERSION file. N is chosen by querying TestPyPI: one higher than the largest
21
+ ".devN" already released for the current base version, or 0 if there are
22
+ none. VERSION is edited only transiently for the build and its exact
23
+ original bytes are restored afterward.
24
+
25
+ Authentication:
26
+ - If TESTPYPI_TOKEN is set, the upload runs non-interactively.
27
+ - Otherwise twine prompts you to paste the token.
28
+ """
29
+
30
+ from __future__ import annotations
31
+
32
+ import json
33
+ import os
34
+ import re
35
+ import shutil
36
+ import subprocess
37
+ import sys
38
+ import urllib.error
39
+ import urllib.request
40
+ from pathlib import Path
41
+
42
+ PKG_DIR = Path(__file__).resolve().parent
43
+ VERSION_FILE = PKG_DIR.parents[1] / "VERSION"
44
+ DIST = PKG_DIR / "dist"
45
+ PROJECT_NAME = "auto-trainer-api"
46
+ DIST_NAME = "auto_trainer_api" # normalized project name used in artifact filenames
47
+ REPOSITORY_URL = "https://test.pypi.org/legacy/"
48
+
49
+
50
+ def read_base_version() -> str:
51
+ try:
52
+ version = VERSION_FILE.read_text(encoding="utf-8").strip()
53
+ except OSError as exc:
54
+ sys.exit(f"error: could not read VERSION file at {VERSION_FILE}: {exc}")
55
+ if not version:
56
+ sys.exit(f"error: VERSION file at {VERSION_FILE} is empty")
57
+ return version
58
+
59
+
60
+ def next_dev_number(base: str) -> int:
61
+ """One past the highest <base>.devN already on TestPyPI (0 if none)."""
62
+ url = f"https://test.pypi.org/pypi/{PROJECT_NAME}/json"
63
+ try:
64
+ with urllib.request.urlopen(url, timeout=15) as resp:
65
+ releases = json.load(resp).get("releases", {})
66
+ except urllib.error.HTTPError as exc:
67
+ if exc.code == 404:
68
+ return 0 # project not on TestPyPI yet -> start at dev0
69
+ sys.exit(f"error: TestPyPI returned HTTP {exc.code} for {url}")
70
+ except urllib.error.URLError as exc:
71
+ sys.exit(f"error: could not reach TestPyPI: {exc.reason}")
72
+
73
+ pattern = re.compile(rf"^{re.escape(base)}\.dev(\d+)$")
74
+ highest = -1
75
+ for version in releases:
76
+ match = pattern.match(version)
77
+ if match:
78
+ highest = max(highest, int(match.group(1)))
79
+ return highest + 1
80
+
81
+
82
+ def build_with_version(base: str, dev_version: str) -> None:
83
+ """Build sdist+wheel with the version transiently set to dev_version."""
84
+ original = VERSION_FILE.read_bytes()
85
+ original_text = original.decode("utf-8")
86
+ if original_text.strip() != base:
87
+ sys.exit(f'error: VERSION changed while preparing build: expected "{base}", found "{original_text.strip()}"')
88
+
89
+ newline = "\n" if original_text.endswith("\n") else ""
90
+ patched = f"{dev_version}{newline}".encode("utf-8")
91
+
92
+ shutil.rmtree(DIST, ignore_errors=True)
93
+ try:
94
+ VERSION_FILE.write_bytes(patched)
95
+ subprocess.run([sys.executable, "-m", "build"], cwd=PKG_DIR, check=True)
96
+ finally:
97
+ VERSION_FILE.write_bytes(original)
98
+
99
+
100
+ def upload(dev_version: str) -> None:
101
+ env = os.environ.copy()
102
+ # A token authenticates as user "__token__"; setting only the username makes
103
+ # twine prompt just for the token when TESTPYPI_TOKEN is unset.
104
+ env["TWINE_USERNAME"] = "__token__"
105
+ token = os.environ.get("TESTPYPI_TOKEN")
106
+ if token:
107
+ env["TWINE_PASSWORD"] = token
108
+ print(f"==> Uploading {dev_version} to TestPyPI (using TESTPYPI_TOKEN, non-interactive)")
109
+ else:
110
+ print("==> TESTPYPI_TOKEN not set; twine will prompt for the token")
111
+
112
+ sdist = DIST / f"{DIST_NAME}-{dev_version}.tar.gz"
113
+ wheels = sorted(DIST.glob(f"{DIST_NAME}-{dev_version}-*.whl"))
114
+ # --skip-existing is a safety net against a race (a matching version
115
+ # appearing between the query above and this upload).
116
+ subprocess.run(
117
+ [sys.executable, "-m", "twine", "upload",
118
+ "--repository-url", REPOSITORY_URL, "--skip-existing",
119
+ str(sdist), *map(str, wheels)],
120
+ check=True,
121
+ env=env,
122
+ )
123
+
124
+
125
+ def main() -> None:
126
+ base = read_base_version()
127
+ print(f"==> Querying TestPyPI for existing dev releases of {PROJECT_NAME} {base}")
128
+ dev_version = f"{base}.dev{next_dev_number(base)}"
129
+ print(f"==> Base version: {base}")
130
+ print(f"==> Publishing as: {dev_version}")
131
+ build_with_version(base, dev_version)
132
+ upload(dev_version)
133
+ print(f"==> Done. View at https://test.pypi.org/project/{PROJECT_NAME}/")
134
+
135
+
136
+ if __name__ == "__main__":
137
+ main()
@@ -1,45 +1,49 @@
1
- [build-system]
2
- requires = ["hatchling"]
3
- build-backend = "hatchling.build"
4
-
5
- [tool.hatch.build.targets.wheel]
6
- packages = ["src/autotrainer"]
7
- namespaces = true
8
-
9
- [tool.hatch.build.targets.sdist]
10
- exclude = [
11
- "/mkdocs.yml",
12
- "/docs",
13
- ]
14
-
15
- [project]
16
- name = "auto-trainer-api"
17
- version = "0.9.22"
18
- description = "API for interfacing with the core acquisition process via platform and language agnostic message queues."
19
- license = { text = "AGPL-3.0-only" }
20
- readme = "README.md"
21
- requires-python = ">=3.8"
22
- classifiers = [
23
- "Programming Language :: Python :: 3",
24
- "Operating System :: OS Independent"
25
- ]
26
- dependencies = [
27
- "pyhumps==3.8.0",
28
- "pyzmq==26.4",
29
- "typing_extensions>=3.11"
30
- ]
31
-
32
- [project.optional-dependencies]
33
- telemetry = [
34
- "opentelemetry-api",
35
- "opentelemetry-sdk"
36
- ]
37
- bridge = [
38
- "fastapi>=0.100,<0.125",
39
- "uvicorn>=0.20,<0.31",
40
- "python-socketio>=5.0",
41
- ]
42
- test = [
43
- "auto-trainer-api[bridge]",
44
- "pytest==8.2.0"
45
- ]
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [tool.hatch.build.targets.wheel]
6
+ packages = ["src/autotrainer"]
7
+ namespaces = true
8
+
9
+ [tool.hatch.build.targets.sdist]
10
+ exclude = [
11
+ "/mkdocs.yml",
12
+ "/docs",
13
+ ]
14
+
15
+ [tool.hatch.version]
16
+ path = "../../VERSION"
17
+ pattern = "(?P<version>.+)"
18
+
19
+ [project]
20
+ name = "auto-trainer-api"
21
+ dynamic = ["version"]
22
+ description = "API for interfacing with the core acquisition process via platform and language agnostic message queues."
23
+ license = { text = "AGPL-3.0-only" }
24
+ readme = "README.md"
25
+ requires-python = ">=3.8"
26
+ classifiers = [
27
+ "Programming Language :: Python :: 3",
28
+ "Operating System :: OS Independent"
29
+ ]
30
+ dependencies = [
31
+ "pyhumps==3.8.0",
32
+ "pyzmq==26.4",
33
+ "typing_extensions>=3.11"
34
+ ]
35
+
36
+ [project.optional-dependencies]
37
+ telemetry = [
38
+ "opentelemetry-api",
39
+ "opentelemetry-sdk"
40
+ ]
41
+ bridge = [
42
+ "fastapi>=0.100,<0.125",
43
+ "uvicorn>=0.20,<0.31",
44
+ "python-socketio>=5.0",
45
+ ]
46
+ test = [
47
+ "auto-trainer-api[bridge]",
48
+ "pytest==8.2.0"
49
+ ]
@@ -5,8 +5,7 @@ API Service functionality for Autotrainer.
5
5
  from typing import Optional
6
6
 
7
7
  from .api_options import ApiOptions, create_default_api_options
8
- from .api_event_kind import ApiEventKind
9
- from .api_event import ApiEvent, ApiEventDict
8
+ from .event import ApiEvent, ApiEventDict, ApiEventKind, ApiPelletShiftSource, build_event
10
9
  from .api_application_mode import ApiApplicationMode
11
10
  from .api_training_mode import ApiTrainingMode
12
11
  from .api_system_status import ApiSystemStatus, ApiPelletDeviceStatus, ApiTunnelDeviceStatus, ApiDetectorStatus, \