Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adafruit/Adafruit_CircuitPython_asyncio
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: sjev/Adafruit_CircuitPython_asyncio
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on May 9, 2024

  1. add devcontainer

    sjev committed May 9, 2024
    Copy the full SHA
    f5baca1 View commit details
  2. fill simple test

    sjev committed May 9, 2024
    Copy the full SHA
    ba1d4d5 View commit details
  3. update example

    sjev committed May 9, 2024
    Copy the full SHA
    5651c65 View commit details
Showing with 137 additions and 0 deletions.
  1. +77 −0 .devcontainer/Dockerfile
  2. +32 −0 .devcontainer/devcontainer.json
  3. +7 −0 .devcontainer/requirements.txt
  4. +21 −0 examples/asyncio_simpletest.py
77 changes: 77 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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}


32 changes: 32 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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",
]
}
}
}
7 changes: 7 additions & 0 deletions .devcontainer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
circuitpython-stubs
invoke
mpremote
mypy
pylint
pytest
ruff
21 changes: 21 additions & 0 deletions examples/asyncio_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
# 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):
"""print (i+1) dots"""
for i in range(5):
print(f"loop {id} : " + (i + 1) * ".")
await asyncio.sleep(delay)
print(f"loop {id} : done")


async def main():
coros = [loop(1), loop(2, 0.5), loop(3, 1.0)]
await asyncio.gather(*coros)


asyncio.run(main())