kubernetes-robin-executor 1.0.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 (28) hide show
  1. kubernetes_robin_executor-1.0.0/.gitignore +180 -0
  2. kubernetes_robin_executor-1.0.0/LICENSE-CODE +114 -0
  3. kubernetes_robin_executor-1.0.0/PKG-INFO +362 -0
  4. kubernetes_robin_executor-1.0.0/README.md +562 -0
  5. kubernetes_robin_executor-1.0.0/pyproject.toml +58 -0
  6. kubernetes_robin_executor-1.0.0/src/autogen_kubernetes/__init__.py +0 -0
  7. kubernetes_robin_executor-1.0.0/src/autogen_kubernetes/code_executors/README-KubernetesCommandLineCodeExecutor.md +230 -0
  8. kubernetes_robin_executor-1.0.0/src/autogen_kubernetes/code_executors/__init__.py +22 -0
  9. kubernetes_robin_executor-1.0.0/src/autogen_kubernetes/code_executors/_jupyter_server.py +858 -0
  10. kubernetes_robin_executor-1.0.0/src/autogen_kubernetes/code_executors/_kubernetes_code_executor.py +716 -0
  11. kubernetes_robin_executor-1.0.0/src/autogen_kubernetes/code_executors/_kubernetes_jupyter.py +352 -0
  12. kubernetes_robin_executor-1.0.0/src/autogen_kubernetes/code_executors/_utils.py +368 -0
  13. kubernetes_robin_executor-1.0.0/src/autogen_kubernetes/code_executors/base.py +200 -0
  14. kubernetes_robin_executor-1.0.0/src/autogen_kubernetes/code_executors/kubernetes_commandline_code_executor.py +784 -0
  15. kubernetes_robin_executor-1.0.0/src/autogen_kubernetes/code_executors/kubernetes_shared_volumes.py +418 -0
  16. kubernetes_robin_executor-1.0.0/src/autogen_kubernetes/code_executors/markdown_code_extractor.py +76 -0
  17. kubernetes_robin_executor-1.0.0/src/autogen_kubernetes/py.typed +0 -0
  18. kubernetes_robin_executor-1.0.0/tests/PYPI-publish.local.md +95 -0
  19. kubernetes_robin_executor-1.0.0/tests/README.md +151 -0
  20. kubernetes_robin_executor-1.0.0/tests/conftest.py +140 -0
  21. kubernetes_robin_executor-1.0.0/tests/fixtures/robin_upload_invoke/robin_user.py +80 -0
  22. kubernetes_robin_executor-1.0.0/tests/spec-files/test-jupyter.yaml +63 -0
  23. kubernetes_robin_executor-1.0.0/tests/spec-files/test-pod.yaml +17 -0
  24. kubernetes_robin_executor-1.0.0/tests/spec-files/test-volume.yaml +4 -0
  25. kubernetes_robin_executor-1.0.0/tests/test_jupyter_code_executor.py +111 -0
  26. kubernetes_robin_executor-1.0.0/tests/test_kubernetees_code_executor.py +319 -0
  27. kubernetes_robin_executor-1.0.0/tests/test_kubernetes_commandline_executor.py +209 -0
  28. kubernetes_robin_executor-1.0.0/tests/test_utils.py +180 -0
@@ -0,0 +1,180 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+ .env
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+
162
+ .ruff_cache/
163
+
164
+ /docs/src/reference
165
+ .DS_Store
166
+
167
+ # Generated log files
168
+ log.jsonl
169
+
170
+ # Jupyter notebooks executions in docs.
171
+ docs/**/jupyter_execute
172
+
173
+ # Temporary files
174
+ tmp_code_*.py
175
+
176
+ # .NET Development settings
177
+ appsettings.Development.json
178
+
179
+ # cookiecutter templates
180
+ templates/
@@ -0,0 +1,114 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+ Copyright (c) 2024 kiyoung you
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE
23
+
24
+ ---
25
+
26
+ This project includes code from the autogen project, which is licensed under the MIT License.
27
+
28
+ Copyright (c) Microsoft Corporation.
29
+ Modification Copyright (c) 2024 kiyoung you(questcollector)
30
+
31
+ This project is licensed under the MIT License. See the full license text above
32
+
33
+ ---
34
+
35
+ Third-Party Licenses
36
+ ---------------------
37
+
38
+ This project uses the following third-party dependencies:
39
+
40
+ 1. Kubernetes Python SDK(https://github.com/kubernetes-client/python)
41
+ Licensed under the Apache License, Version 2.0.
42
+
43
+ ---
44
+
45
+ 2. httpx(https://github.com/encode/httpx)
46
+ Licensed under BSD 3-Clause "New" or "Revised" License:
47
+
48
+ Copyright © 2019, Encode OSS Ltd. All rights reserved.
49
+
50
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
51
+
52
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
53
+
54
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
55
+
56
+ Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
57
+
58
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59
+
60
+ ---
61
+
62
+ 3. websockets(https://github.com/python-websockets/websockets)
63
+ Licensed under the BSD 3-Clause "New" or "Revised" License:
64
+
65
+ Copyright (c) Aymeric Augustin and contributors
66
+
67
+ Redistribution and use in source and binary forms, with or without
68
+ modification, are permitted provided that the following conditions are met:
69
+
70
+ * Redistributions of source code must retain the above copyright notice,
71
+ this list of conditions and the following disclaimer.
72
+ * Redistributions in binary form must reproduce the above copyright notice,
73
+ this list of conditions and the following disclaimer in the documentation
74
+ and/or other materials provided with the distribution.
75
+ * Neither the name of the copyright holder nor the names of its contributors
76
+ may be used to endorse or promote products derived from this software
77
+ without specific prior written permission.
78
+
79
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
80
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
81
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
82
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
83
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
85
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
86
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
87
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
88
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
89
+
90
+ ---
91
+
92
+ 4. PyYAML(https://github.com/yaml/pyyaml)
93
+ Licensed under the MIT License:
94
+
95
+ Copyright (c) 2017-2021 Ingy döt Net
96
+ Copyright (c) 2006-2016 Kirill Simonov
97
+
98
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
99
+ this software and associated documentation files (the "Software"), to deal in
100
+ the Software without restriction, including without limitation the rights to
101
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
102
+ of the Software, and to permit persons to whom the Software is furnished to do
103
+ so, subject to the following conditions:
104
+
105
+ The above copyright notice and this permission notice shall be included in all
106
+ copies or substantial portions of the Software.
107
+
108
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
109
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
110
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
111
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
112
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
113
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
114
+ SOFTWARE.
@@ -0,0 +1,362 @@
1
+ Metadata-Version: 2.4
2
+ Name: kubernetes-robin-executor
3
+ Version: 1.0.0
4
+ Summary: Kubernetes pod code executor (Robin): Python/shell execution and remote workspace upload for AutoGen-style agents.
5
+ License: MIT License
6
+
7
+ Copyright (c) Microsoft Corporation.
8
+ Copyright (c) 2024 kiyoung you
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE
27
+
28
+ ---
29
+
30
+ This project includes code from the autogen project, which is licensed under the MIT License.
31
+
32
+ Copyright (c) Microsoft Corporation.
33
+ Modification Copyright (c) 2024 kiyoung you(questcollector)
34
+
35
+ This project is licensed under the MIT License. See the full license text above
36
+
37
+ ---
38
+
39
+ Third-Party Licenses
40
+ ---------------------
41
+
42
+ This project uses the following third-party dependencies:
43
+
44
+ 1. Kubernetes Python SDK(https://github.com/kubernetes-client/python)
45
+ Licensed under the Apache License, Version 2.0.
46
+
47
+ ---
48
+
49
+ 2. httpx(https://github.com/encode/httpx)
50
+ Licensed under BSD 3-Clause "New" or "Revised" License:
51
+
52
+ Copyright © 2019, Encode OSS Ltd. All rights reserved.
53
+
54
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
55
+
56
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
57
+
58
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
59
+
60
+ Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
61
+
62
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63
+
64
+ ---
65
+
66
+ 3. websockets(https://github.com/python-websockets/websockets)
67
+ Licensed under the BSD 3-Clause "New" or "Revised" License:
68
+
69
+ Copyright (c) Aymeric Augustin and contributors
70
+
71
+ Redistribution and use in source and binary forms, with or without
72
+ modification, are permitted provided that the following conditions are met:
73
+
74
+ * Redistributions of source code must retain the above copyright notice,
75
+ this list of conditions and the following disclaimer.
76
+ * Redistributions in binary form must reproduce the above copyright notice,
77
+ this list of conditions and the following disclaimer in the documentation
78
+ and/or other materials provided with the distribution.
79
+ * Neither the name of the copyright holder nor the names of its contributors
80
+ may be used to endorse or promote products derived from this software
81
+ without specific prior written permission.
82
+
83
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
84
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
85
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
86
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
87
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
88
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
89
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
90
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
91
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
92
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
93
+
94
+ ---
95
+
96
+ 4. PyYAML(https://github.com/yaml/pyyaml)
97
+ Licensed under the MIT License:
98
+
99
+ Copyright (c) 2017-2021 Ingy döt Net
100
+ Copyright (c) 2006-2016 Kirill Simonov
101
+
102
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
103
+ this software and associated documentation files (the "Software"), to deal in
104
+ the Software without restriction, including without limitation the rights to
105
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
106
+ of the Software, and to permit persons to whom the Software is furnished to do
107
+ so, subject to the following conditions:
108
+
109
+ The above copyright notice and this permission notice shall be included in all
110
+ copies or substantial portions of the Software.
111
+
112
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
113
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
114
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
115
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
116
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
117
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
118
+ SOFTWARE.
119
+ License-File: LICENSE-CODE
120
+ Keywords: AI,agent,autogen,code-executor,kubernetes,robin
121
+ Classifier: License :: OSI Approved :: MIT License
122
+ Classifier: Operating System :: OS Independent
123
+ Classifier: Programming Language :: Python :: 3
124
+ Requires-Python: >=3.10
125
+ Requires-Dist: asyncio-atexit>=1.0.1
126
+ Requires-Dist: autogen-core>=0.5.2
127
+ Requires-Dist: httpx
128
+ Requires-Dist: kubernetes>=27.0.0
129
+ Requires-Dist: pyyaml
130
+ Requires-Dist: websockets
131
+ Description-Content-Type: text/markdown
132
+
133
+ # `KubernetesCommandLineCodeExecutor`
134
+
135
+ Executor that runs code (Python / shell) **inside a Kubernetes pod**: each block is written as a file on the pod’s workspace volume and executed via `exec` (Kubernetes API + stream).
136
+
137
+ **PyPI distribution name:** `kubernetes-robin-executor` — install with:
138
+
139
+ ```bash
140
+ pip install kubernetes-robin-executor
141
+ ```
142
+
143
+ **Import path** (unchanged): `autogen_kubernetes.code_executors.kubernetes_commandline_code_executor`. The PyPI name differs from the upstream `autogen-kubernetes` package on purpose. Do not install both in the same environment if they expose the same top-level package layout; this distribution keeps the `autogen_kubernetes` module name for compatibility with existing code.
144
+
145
+ This file is the **project `readme`** in `pyproject.toml`, so it is what users see on the [PyPI project page](https://pypi.org) for `kubernetes-robin-executor` after you publish.
146
+
147
+ ---
148
+
149
+ ## Cluster connection
150
+
151
+ | Mode | Behavior |
152
+ |------|----------|
153
+ | **`remote_control_plane` set** (API URL, e.g. `https://IP:6443`) | Uses `KUBE_TOKEN` from the environment (Bearer). Client uses `verify_ssl=False`. |
154
+ | **`remote_control_plane=None`** | Local `kubeconfig` or in-cluster config (`load_kube_config` / `load_incluster_config`). |
155
+
156
+ ---
157
+
158
+ ## Constructor (`__init__`)
159
+
160
+ Main parameters:
161
+
162
+ | Parameter | Description |
163
+ |-----------|-------------|
164
+ | `image` | Container image (default `python:3-slim`). |
165
+ | `pod_name` | Fixed pod name; if `None`, generates `robin-code-exec-<uuid>`. |
166
+ | `namespace` | Namespace where the pod is created / listed. |
167
+ | `timeout` | Seconds for exec-based runs (≥ 1). |
168
+ | `work_dir` | Path **inside the pod** mounted as the workspace. |
169
+ | `execution_policies` | Optional: override which languages are **executed** vs only **saved**. |
170
+ | `remote_control_plane` | API server URL for bearer-token mode. |
171
+ | `shared_pvc_name` | If set, the pod uses a shared PVC instead of `emptyDir`. |
172
+ | `node` | Optional: `nodeSelector` `kubernetes.io/hostname`. |
173
+ | `shared_resources` | If `True` and a **Running** pod already exists with the **same** `image`, reuses its name instead of creating a new pod. |
174
+ | `env_vars` | List of `{"key": "...", "value": "..."}` appended to `~/.bashrc` in the pod. |
175
+
176
+ On construction, pod cleanup is registered with `atexit` and `SIGINT` is handled with `cleanup()`.
177
+
178
+ ---
179
+
180
+ ## Upload code from your machine and call functions in the pod
181
+
182
+ Besides `execute_code_blocks`, you can **copy Python files into the pod’s `work_dir`** and **invoke callables by name** without putting everything in a single markdown block.
183
+
184
+ ### Recommended flow
185
+
186
+ 1. **`install_pod_dispatcher(default_module="robin_user", runner_filename="executor.py")`** — Uploads an `executor.py` that reads JSON with `function`, `arguments`, and optionally `module`, imports the module, and calls `function(**arguments)`.
187
+ 2. **`upload_file_content(relative_path, content)`** or **`upload_from_disk(local_path, remote_prefix="")`** — Copies your `.py` files or project tree into the pod under `work_dir`. `upload_from_disk` skips `__pycache__` and hidden names (`.*`); text files only (UTF-8).
188
+ 3. **`execute_tool_function(arguments, func_name, *, module=None, runner_script="executor.py")`** — Uploads a temporary `.json` and runs `python <work_dir>/<runner_script> <json>`.
189
+
190
+ The interpreter adds the script’s directory to `sys.path`; with `executor.py` in `work_dir`, modules in the same directory (e.g. `robin_user.py`) or packages under `work_dir` can be imported using the right `module` (e.g. `my_package.submodule`).
191
+
192
+ ### Minimal example
193
+
194
+ ```python
195
+ with KubernetesCommandLineCodeExecutor(...) as executor:
196
+ executor.install_pod_dispatcher(default_module="robin_user")
197
+ executor.upload_from_disk("/local/path/my_folder") # contains robin_user.py or your layout
198
+ r = executor.execute_tool_function(
199
+ {"name": "Ada"},
200
+ "greet",
201
+ module="robin_user",
202
+ )
203
+ assert r.exit_code == 0
204
+ ```
205
+
206
+ If you omit `module` in `execute_tool_function`, the dispatcher uses the `default_module` passed to `install_pod_dispatcher`.
207
+
208
+ ### Integration test in this repo
209
+
210
+ `test_upload_from_disk_and_invoke_long_function` uploads `tests/fixtures/robin_upload_invoke/robin_user.py` and calls `greet` and `run_heavy_pipeline` on the pod (marker `robin_remote`; see `tests/README.md`).
211
+
212
+ Run it from `autogen-kubernetes/python`:
213
+
214
+ ```bash
215
+ uv run pytest packages/autogen-kubernetes/tests/test_kubernetes_commandline_executor.py::test_upload_from_disk_and_invoke_long_function -m robin_remote -v -s -n0
216
+ ```
217
+
218
+ ---
219
+
220
+ ## Public properties
221
+
222
+ | Member | Type / return | Description |
223
+ |--------|----------------|-------------|
224
+ | `timeout` | `int` | Configured timeout. |
225
+ | `work_dir` | `Path` | Working directory in the pod. |
226
+ | `code_extractor` | `MarkdownCodeExtractor` | Code-block extractor for agent integration. |
227
+ | `execution_policies` | `dict` | Per language: `True` runs, `False` only writes the file. |
228
+ | `pod_name` | `str` | Pod name in use (created or reused). |
229
+ | `namespace` | `str` | Current namespace. |
230
+ | `image` | `str` | Container image. |
231
+
232
+ ---
233
+
234
+ ## Public methods
235
+
236
+ | Method | Description |
237
+ |--------|-------------|
238
+ | `execute_code_blocks(code_blocks: list[CodeBlock]) -> CommandLineCodeResult` | Uploads and runs (or only saves) each block in order. Returns `exit_code`, `output` (combined stdout/stderr), and `code_file`. |
239
+ | `upload_file_content(relative_path, content) -> str` | Writes text in the pod under `work_dir` / `relative_path`; returns the POSIX path in the pod. |
240
+ | `upload_from_disk(local_path, *, remote_prefix="", encoding="utf-8") -> list[str]` | Uploads a local file or full directory tree; returns paths written in the pod. |
241
+ | `install_pod_dispatcher(*, default_module="robin_user", runner_filename="executor.py") -> str` | Uploads the `executor.py` that dispatches JSON → function calls in the pod. |
242
+ | `execute_tool_function(arguments, func_name, *, module=None, runner_script="executor.py") -> CommandLineCodeResult` | Uploads JSON and runs the runner (default `executor.py` in `work_dir`). Use `install_pod_dispatcher` or your own script in the image. `module` is the dotted import if you do not want the dispatcher’s `default_module`. |
243
+ | `cleanup()` | Deletes the pod in the namespace (404-safe). |
244
+ | `stop()` | Runs the registered cleanup (`delete` pod). |
245
+ | `restart()` | `stop()` then calls `__init__` again with a subset of arguments (**note**: remote mode may omit `remote_control_plane`; prefer recreating the executor manually if this fails). |
246
+ | `add_env_vars_to_bashrc(env_vars)` | Appends exports to `~/.bashrc` via exec. |
247
+ | `is_pod_running_with_image()` | Lists pods in the namespace; if one is **Running** with `self.image`, returns its **name** (`str`); otherwise `None`. |
248
+ | `get_pod_resource_usage()` | Tries to read `metrics.k8s.io` (often assumes local `kubeconfig`; may not work with remote token only). |
249
+ | `create_resources()` | Creates the pod and waits for `Running` (usually already called from `__init__`). |
250
+ | `handle_sigint(signum, frame)` | Signal handler: cleans up and exits the process. |
251
+
252
+ **Context manager:** `__enter__` / `__exit__` → leaving `with` calls `stop()` (deletes the pod if cleanup is active).
253
+
254
+ **Internals (reference):** `_upload_file_to_pod`, `_exec_command_with_exit_code`, `_wait_for_pod_ready` — upload via stdin to exec, command wrapped in `sh -c` with exit-code capture.
255
+
256
+ ---
257
+
258
+ ## Examples
259
+
260
+ ### 1. Remote cluster with token (`.env`: `KUBE_TOKEN`; your app often also sets `REMOTE_CONTROL_PLANE`)
261
+
262
+ ```python
263
+ import os
264
+ from autogen_kubernetes.code_executors.base import CodeBlock
265
+ from autogen_kubernetes.code_executors.kubernetes_commandline_code_executor import (
266
+ KubernetesCommandLineCodeExecutor,
267
+ )
268
+
269
+ os.environ.setdefault("KUBE_TOKEN", "...") # or load_dotenv()
270
+
271
+ with KubernetesCommandLineCodeExecutor(
272
+ image="williamgomez712/robin_executor_python:latest",
273
+ namespace="my-namespace",
274
+ work_dir="/tmp/robin_executor_test",
275
+ timeout=120,
276
+ remote_control_plane="https://API_SERVER:6443",
277
+ shared_resources=False,
278
+ ) as executor:
279
+ result = executor.execute_code_blocks(
280
+ [CodeBlock(language="python", code="print('hello')")]
281
+ )
282
+ print(result.exit_code, result.output)
283
+ ```
284
+
285
+ ### 2. Save file on the pod only (do not execute)
286
+
287
+ ```python
288
+ executor.execution_policies["python"] = False
289
+ result = executor.execute_code_blocks(
290
+ [CodeBlock(language="python", code="print('does not run')")]
291
+ )
292
+ # result.output will include "Code saved to ..."
293
+ ```
294
+
295
+ ### 3. Shell in the pod
296
+
297
+ ```python
298
+ result = executor.execute_code_blocks(
299
+ [CodeBlock(language="sh", code="echo ok && uname -a")]
300
+ )
301
+ ```
302
+
303
+ ### 4. Tooling via uploaded dispatcher (`install_pod_dispatcher`) or `executor.py` baked into the image
304
+
305
+ ```python
306
+ executor.install_pod_dispatcher(default_module="robin_user")
307
+ executor.upload_file_content("robin_user.py", open("robin_user.py").read())
308
+ result = executor.execute_tool_function(
309
+ {"query": "test"},
310
+ func_name="my_function",
311
+ module="robin_user",
312
+ )
313
+ ```
314
+
315
+ If the image already provides `executor.py` under `work_dir`, you can call `execute_tool_function` alone without `install_pod_dispatcher`.
316
+
317
+ ### 5. Local cluster / kubeconfig (no `remote_control_plane`)
318
+
319
+ ```python
320
+ with KubernetesCommandLineCodeExecutor(
321
+ namespace="default",
322
+ work_dir="/tmp/work",
323
+ ) as executor:
324
+ ...
325
+ ```
326
+
327
+ (Requires a valid `~/.kube/config` or in-cluster execution.)
328
+
329
+ ---
330
+
331
+ ## `CommandLineCodeResult`
332
+
333
+ | Field | Meaning |
334
+ |-------|---------|
335
+ | `exit_code` | Exit code of the last relevant command in the sequence. |
336
+ | `output` | Accumulated text (stdout/stderr from exec). |
337
+ | `code_file` | Path of the first generated code file in the pod (if any). |
338
+
339
+ ---
340
+
341
+ ## Practical notes
342
+
343
+ - **`shared_resources=True`**: reuses a pod with the same `image`; the existing pod’s `work_dir` must match what your code expects, or you may see “file not found” errors.
344
+ - **Filename hints in code**: the first line can set a path with comments like `# filename: foo.py` (and HTML/JS patterns); otherwise a `tmp_code_<md5>.<lang>` under `work_dir` is used.
345
+ - **RBAC**: the token or kubeconfig user needs `pods` + `pods/exec` (and create/delete depending on your flow).
346
+ - After **`stop()`** / exiting **`with`**, the pod is usually **deleted**; do not expect it to remain for debugging unless you skip cleanup or use another workflow.
347
+
348
+ ---
349
+
350
+ ## Publishing to PyPI
351
+
352
+ - **`[project] name`** is **`kubernetes-robin-executor`**. **`readme`** points at **this file**, so PyPI’s long description matches this document.
353
+
354
+ - **Manifest:** `autogen-kubernetes/python/packages/autogen-kubernetes/pyproject.toml` (relative to the `autogen-kubernetes` clone).
355
+
356
+ - **Consumers** (same as local install from PyPI):
357
+
358
+ ```bash
359
+ pip install kubernetes-robin-executor
360
+ ```
361
+
362
+ - **Step-by-step** build/upload (tokens, TestPyPI, `twine`) is in **`tests/PYPI-publish.local.md`** next to the test suite. That file may be **gitignored** in your outer repo; **`tests/README.md`** mentions it.