Skip to content

Commit f5e683d

Browse files
committed
Add instructions on os.dupterm support and a test for exec
1 parent 2504b71 commit f5e683d

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ jobs:
2323
runs-on: ubuntu-latest
2424
steps:
2525
- uses: actions/checkout@v2
26-
- name: Build micropython
26+
- name: Set up micropython
2727
run: |
28-
git clone --depth 1 https://github.com/micropython/micropython.git
28+
git clone -b v1.24-release --depth=1 --single-branch https://github.com/micropython/micropython.git
2929
cd micropython
3030
git submodule update --init
31-
make -C mpy-cross
32-
cp mpy-cross/build/mpy-cross /usr/local/bin/
31+
- name: Build micropython
32+
env:
33+
CFLAGS_EXTRA: "-DMICROPY_PY_OS_DUPTERM=2" # os.dupterm support on unix
34+
run: |
3335
make -C ports/unix
3436
cp ports/unix/build-standard/micropython /usr/local/bin/
3537
cd ..

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ TODO
2727

2828
## Developing
2929

30-
You need python and a build of micropython with `asyncio` support. Follow the steps in the CI workflow to get a `micropython` binary and add it to your `PATH`.
30+
You need python and a build of micropython with `asyncio` and `os.dupterm` support. Follow the steps in the CI workflow to get a `micropython` binary and add it to your `PATH`.
3131

3232
Before making changes, install the development (CPython) dependencies:
3333

mqterm/jobs.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33
from binascii import hexlify
44
from hashlib import sha256
55
from io import BytesIO
6-
7-
try:
8-
from os import dupterm
9-
except ImportError:
10-
# unix mpy doesn't have dupterm; define a no-op version
11-
def dupterm(stream_object, index=0):
12-
return stream_object
13-
6+
from os import dupterm
147

158
from micropython import const
169

tests/test_jobs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,13 @@ def test_exec(self):
272272
self.assertEqual(job_output, "") # No output expected
273273
self.assertEqual(file_output, "Hello, World!")
274274
os.remove("output.txt")
275+
276+
# NOTE: on unix micropython you need to compile with MICROPY_PY_OS_DUPTERM
277+
# to capture output. If this fails, see:
278+
# https://forum.micropython.org/viewtopic.php?t=7055
279+
def test_exec_output(self):
280+
"""RunPyJob should capture output from executed script"""
281+
cmd = 'import sys; sys.stdout.write("Hello, World!")'
282+
job = RunPyJob("exec", [cmd])
283+
output = job.output().read().decode("utf-8").strip()
284+
self.assertEqual(output, "Hello, World!")

0 commit comments

Comments
 (0)