Skip to content

Commit 7b49dce

Browse files
szachovyCopilot
andcommitted
Upload .py source instead of .pyc bytecode
Remove compile(), marshal, and the hardcoded Python 3.10 .pyc magic number. Upload plain .py source that the container's Python compiles at runtime (<100ms overhead). This decouples host and container Python versions, fixing deployment on Python 3.11/3.12 hosts. Closes #38 Closes #59 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0ab8ce7 commit 7b49dce

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
* CI workflow to build and push service images to GitHub Container Registry on master merge. (#97)
1717
* Pull-first with local build fallback for container images during deployment. (#97)
1818

19+
### Fixed
20+
21+
* Upload .py source instead of .pyc bytecode to decouple host Python version. (#38, #59)
22+
1923
### Changed
2024

2125
* Completed [ARCHITECTURE.md](./docs/ARCHITECTURE.md) (#93)

src/remote.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import functools
4040
import io
4141
import logging
42-
import marshal
4342
import os
4443
import pathlib
4544
import random
@@ -124,12 +123,9 @@ def run_python_container_command(self, command: str) -> dict:
124123
mode="r",
125124
encoding="utf-8"
126125
) as memfile:
127-
code_object = compile(memfile.read() + command, filename=nonce, mode="exec")
128-
pyc_file = io.BytesIO()
129-
pyc_file.write(b'o\r\r\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
130-
marshal.dump(code_object, pyc_file)
131-
self.upload_file(content=pyc_file.getvalue(), remote_file_path=f'/opt/{nonce}.pyc')
132-
_, stdout, stderr = self.ssh_client.exec_command(f"python3 /opt/{nonce}.pyc")
126+
source = memfile.read() + command
127+
self.upload_file(content=source, remote_file_path=f'/opt/{nonce}.py')
128+
_, stdout, stderr = self.ssh_client.exec_command(f"python3 /opt/{nonce}.py")
133129
return {
134130
"output": stdout.read().decode(),
135131
"error": stderr.read().decode()

0 commit comments

Comments
 (0)