From f5baca11940398d203e60bb8f5ef5011c1f26f7f Mon Sep 17 00:00:00 2001 From: Jev Date: Thu, 9 May 2024 21:16:07 +0000 Subject: [PATCH 1/3] add devcontainer --- .devcontainer/Dockerfile | 77 +++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 32 ++++++++++++++ .devcontainer/requirements.txt | 7 +++ 3 files changed, 116 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/requirements.txt diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..7d2c956 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,77 @@ + +FROM roxauto/circuitpython:9.0.4 +ARG USERNAME=dev +ARG UID=1000 +ARG GID=1000 +ARG PROJECT=adafruit-asyncio + + +# Create the user +RUN groupadd --gid $GID $USERNAME \ + && useradd --uid $UID --gid $GID -m $USERNAME \ + # + # [Optional] Add sudo support. Omit if you don't need to install software after connecting. + && apt-get update \ + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME + +# dialout group +RUN usermod -a -G dialout $USERNAME + +# install packages +RUN apt-get install -y \ + locales \ + mc \ + tree \ + git \ + make \ + wget \ + libusb-1.0-0 \ + net-tools \ + iproute2 \ + iputils-ping + +# cleanup +RUN rm -rf /var/lib/apt/lists/* + +# set locale +RUN export LC_ALL=en_US.UTF-8 +RUN export LANG=en_US.UTF-8 +RUN locale-gen en_US.UTF-8 + +RUN pip install --upgrade pip + +# install user packages +COPY requirements.txt requirements.txt +RUN pip3 install -r requirements.txt && rm requirements.txt + + +USER ${USERNAME} +RUN echo 'export PS1="🐳 \[\033[1;36m\]'"${PROJECT}"' \[\e[33m\]\W\[\e[m\] \[\033[1;36m\]# \[\033[0m\]"' >> ~/.bashrc + +ENV PATH="${PATH}:/home/${USERNAME}/.local/bin" + +WORKDIR /home/${USERNAME} + + +# setup folders for saving vscode extensions +# https://code.visualstudio.com/remote/advancedcontainers/avoid-extension-reinstalls +RUN mkdir -p /home/$USERNAME/.vscode-server/extensions \ + && chown -R $USERNAME \ + /home/$USERNAME/.vscode-server + + +# build timestamp +USER root +RUN echo ${PROJECT} >> /build_date.txt && \ + date >> /build_date.txt + +# remove bundle asyncio +RUN rm -rf /usr/lib/micropython/asyncio + + +USER ${USERNAME} +WORKDIR /home/${USERNAME} + + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..fbf7949 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,32 @@ +{ + // use Dockerfile + "build": { + "dockerfile": "Dockerfile", + "context": "." + }, + + "initializeCommand": "mkdir -p /var/tmp/container-extensions", + + "mounts": [ + "source=/var/tmp/container-extensions,target=/home/dev/.vscode-server/extensions,type=bind,consistency=cached" + ], + // environment variables + "containerEnv": { + "MICROPYPATH": "/usr/lib/micropython:/workspaces/${localWorkspaceFolderBasename}" + }, + + "runArgs": ["--network", "host", "--privileged"], + // // Configure tool-specific properties. + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance", + "shardulm94.trailing-spaces", + "njpwerner.autodocstring", + "mhutchie.git-graph", + "donjayamanne.githistory", + ] + } + } +} diff --git a/.devcontainer/requirements.txt b/.devcontainer/requirements.txt new file mode 100644 index 0000000..9fa8ff2 --- /dev/null +++ b/.devcontainer/requirements.txt @@ -0,0 +1,7 @@ +circuitpython-stubs +invoke +mpremote +mypy +pylint +pytest +ruff From ba1d4d5f1d4b1a2649c578df4bc68407f10fb076 Mon Sep 17 00:00:00 2001 From: Jev Date: Thu, 9 May 2024 21:16:31 +0000 Subject: [PATCH 2/3] fill simple test --- examples/asyncio_simpletest.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/examples/asyncio_simpletest.py b/examples/asyncio_simpletest.py index 59fa942..101ffe3 100644 --- a/examples/asyncio_simpletest.py +++ b/examples/asyncio_simpletest.py @@ -1,4 +1,23 @@ # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # SPDX-FileCopyrightText: Copyright (c) 2021 Dan Halbert for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2024 Jev Kuznetsov - ROX Automation # # SPDX-License-Identifier: Unlicense + +""" simple async example """ + +import asyncio + + +async def loop(id: int, delay: float = 0.1): + for i in range(5): + print(f"loop {id} : {i}") + await asyncio.sleep(delay) + + +async def main(): + coros = [loop(1), loop(2, 0.5), loop(3, 1.0)] + await asyncio.gather(*coros) + + +asyncio.run(main()) From 5651c65d0ef4eede28f3d31011e02d37d43b8e36 Mon Sep 17 00:00:00 2001 From: Jev Date: Thu, 9 May 2024 21:20:33 +0000 Subject: [PATCH 3/3] update example --- examples/asyncio_simpletest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/asyncio_simpletest.py b/examples/asyncio_simpletest.py index 101ffe3..0314ad1 100644 --- a/examples/asyncio_simpletest.py +++ b/examples/asyncio_simpletest.py @@ -10,9 +10,11 @@ async def loop(id: int, delay: float = 0.1): + """print (i+1) dots""" for i in range(5): - print(f"loop {id} : {i}") + print(f"loop {id} : " + (i + 1) * ".") await asyncio.sleep(delay) + print(f"loop {id} : done") async def main():