Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds basic devcontainer for #1057 #1532

Merged
merged 20 commits into from
Sep 23, 2023
Merged

Conversation

jacoverster
Copy link
Contributor

Continuation of #1057. Adding a basic VSCode devcontainer with robust chrome and chromedriver installation.

All tests pass except those under tests/test_scene.py.

Next steps:

  • Fix failing tests
  • Consider multi-stage docker build for smaller images and faster build times

@rodja
Copy link
Member

rodja commented Sep 1, 2023

@jacoverster That is awesome. The scene test also fails locally for us. It is an unresolved issue. See #643. I think you do not need to resolve it for the dev container to be included in the next release.

@jacoverster
Copy link
Contributor Author

Thanks @rodja, this is tested on Windows 11 with WSL2. Would be good if someone can test on other OS setups too and provide feedback.

@natankeddem
Copy link
Contributor

natankeddem commented Sep 6, 2023

Okay, stupid question time. I cloned your repo, VS Code prompts to launch dev container, all good. Now I am in the container and feel like I am missing something basic. I should be able to launch the tests by executing pytest in terminal? I am just going by documentation in CONTRIBUTING.md.

$ ls    
CITATION.cff        DEPENDENCIES.md  deploy.sh               docker-entrypoint.sh  fetch_google_fonts.py  fly.dockerfile  nicegui                 npm.py         pyproject.toml      set_scale.sh     tests
CODE_OF_CONDUCT.md  LICENSE          development.dockerfile  docker.sh             fetch_tailwind.py      fly.toml        nicegui.code-workspace  poetry.lock    release.dockerfile  setup.py         website
CONTRIBUTING.md     README.md        docker-compose.yml      examples              fly-entrypoint.sh      main.py         npm.json                prometheus.py  sceenshots          test_startup.sh
$ pytest
/bin/sh: 8: pytest: not found

Also, using the built in VS Code testing UI. I am getting Pytest Discovery Error.

2023-09-06T22:57:45.177Z INFO unittest at 'nicegui': Reading configuration for workspace nicegui
2023-09-06T22:57:45.180Z  DBG unittest at 'nicegui': usingNewInterpreterStorage feature flag is 'true'
2023-09-06T22:57:45.180Z INFO pytest at 'nicegui': Reading configuration for workspace nicegui
2023-09-06T22:57:45.181Z  DBG pytest at 'nicegui': usingNewInterpreterStorage feature flag is 'true'
2023-09-06T22:57:45.181Z INFO testplan at 'nicegui': Reading configuration for workspace nicegui
2023-09-06T22:57:45.182Z  DBG testplan at 'nicegui': usingNewInterpreterStorage feature flag is 'true'
2023-09-06T22:57:46.322Z INFO unittest at 'nicegui': Using auto-detected pythonPath /bin/python3
2023-09-06T22:57:46.322Z INFO pytest at 'nicegui': Using auto-detected pythonPath /bin/python3
2023-09-06T22:57:46.322Z INFO testplan at 'nicegui': Using auto-detected pythonPath /bin/python3
2023-09-06T22:57:46.324Z INFO unittest at 'nicegui': Unittest test discovery is disabled
2023-09-06T22:57:46.325Z INFO pytest at 'nicegui': TestPlan test discovery is disabled
2023-09-06T22:57:46.329Z INFO pytest at 'nicegui': Environment variables file /workspaces/nicegui/.env does not exist
2023-09-06T22:57:46.329Z INFO pytest at 'nicegui': Discovering tests using python path '/bin/python3' in /workspaces/nicegui
2023-09-06T22:57:46.332Z INFO pytest at 'nicegui': Running pytest with arguments: --collect-only, .
2023-09-06T22:57:46.332Z INFO pytest at 'nicegui': Running pytest as a Python module
2023-09-06T22:57:46.348Z CRIT pytest at 'nicegui': Test loading failed: Error: Invalid test discovery output!

Error: Invalid test discovery output!

	at parseTestSuites (/home/vscode/.vscode-server/extensions/littlefoxteam.vscode-python-test-adapter-0.7.1/out/src/pytest/pytestTestCollectionParser.js:14:15)
	at PytestTestRunner.<anonymous> (/home/vscode/.vscode-server/extensions/littlefoxteam.vscode-python-test-adapter-0.7.1/out/src/pytest/pytestTestRunner.js:60:76)
	at Generator.next (<anonymous>)
	at fulfilled (/home/vscode/.vscode-server/extensions/littlefoxteam.vscode-python-test-adapter-0.7.1/node_modules/tslib/tslib.js:114:62)

@jacoverster
Copy link
Contributor Author

jacoverster commented Sep 7, 2023

Hi @natankeddem, with the container the testing now also happens inside the poetry virtual environment. You need to run poetry run pytest. Sometimes the poetry venv can break due to manual installing etc, you can run poetry install again to restore it.

@rodja
Copy link
Member

rodja commented Sep 7, 2023

For me (on mac, M1) the devcontainer does not build:

Expand
#0 11.77 The following packages have unmet dependencies:
#0 11.82  google-chrome-stable:amd64 
[3326 ms] Start: Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /var/folders/23/69ym20yd7n1ffsskbddkk_gc0000gn/T/devcontainercli/container-features/0.50.0-1694061341139/Dockerfile-with-features -t vsc-nicegui-eabe06171a0264f46bf8e005bdb27cefb1fd0de0ff90392b028d7d6e0d57bcc9 --target dev_containers_target_stage --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label /Users/rodja/Projects/nicegui
[+] Building 24.5s (8/13)                                                       
 => [internal] load build definition from Dockerfile-with-features         0.0s
 => => transferring dockerfile: 2.15kB                                     0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 93B                                           0.0s
 => [internal] load metadata for docker.io/library/python:3.8-slim         1.4s
 => [auth] library/python:pull token for registry-1.docker.io              0.0s
 => CACHED [dev_container_auto_added_stage_label 1/8] FROM docker.io/libr  0.0s
 => [internal] load build context                                          0.4s
 => => transferring context: 271.20kB                                      0.3s
 => [dev_container_auto_added_stage_label 2/8] RUN groupadd --gid 1000 v  11.0s
 => ERROR [dev_container_auto_added_stage_label 3/8] RUN wget -nv -O /tm  11.9s 
------                                                                          
 > [dev_container_auto_added_stage_label 3/8] RUN wget -nv -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_116.0.5845.96-1_amd64.deb     && apt-get update && apt-get install -y /tmp/chrome.deb     && rm /tmp/chrome.deb:
#0 9.226 2023-09-07 04:36:03 URL:https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_116.0.5845.96-1_amd64.deb [96765132/96765132] -> "/tmp/chrome.deb" [1]                                                             
#0 9.348 Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB]         
#0 9.450 Get:2 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB]
#0 9.499 Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
#0 9.542 Get:4 http://deb.debian.org/debian bookworm/main arm64 Packages [8803 kB]
#0 10.35 Get:5 http://deb.debian.org/debian bookworm-updates/main arm64 Packages [4960 B]
#0 10.35 Get:6 http://deb.debian.org/debian-security bookworm-security/main arm64 Packages [58.1 kB]
#0 11.04 Fetched 9118 kB in 2s (5098 kB/s)
#0 11.04 Reading package lists...
#0 11.36 Reading package lists...
#0 11.66 Building dependency tree...
#0 11.74 Reading state information...
#0 11.77 Some packages could not be installed. This may mean that you have
#0 11.77 requested an impossible situation or if you are using the unstable
#0 11.77 distribution that some required packages have not yet been created
#0 11.77 or been moved out of Incoming.
#0 11.77 The following information may help to resolve the situation:
#0 11.77 
#0 11.77 The following packages have unmet dependencies:
#0 11.82  google-chrome-stable:amd64 : Depends: libasound2:amd64 (>= 1.0.17) but it is not installable
#0 11.82                               Depends: libatk-bridge2.0-0:amd64 (>= 2.5.3) but it is not installable
#0 11.82                               Depends: libatk1.0-0:amd64 (>= 2.2.0) but it is not installable
#0 11.82                               Depends: libatspi2.0-0:amd64 (>= 2.9.90) but it is not installable
#0 11.82                               Depends: libc6:amd64 (>= 2.17) but it is not installable
#0 11.82                               Depends: libcairo2:amd64 (>= 1.6.0) but it is not installable
#0 11.82                               Depends: libcups2:amd64 (>= 1.6.0) but it is not installable
#0 11.82                               Depends: libcurl3-gnutls:amd64 but it is not installable or
#0 11.82                                        libcurl3-nss:amd64 but it is not installable or
#0 11.82                                        libcurl4:amd64 but it is not installable or
#0 11.82                                        libcurl3:amd64 but it is not installable
#0 11.82                               Depends: libdbus-1-3:amd64 (>= 1.9.14) but it is not installable
#0 11.82                               Depends: libdrm2:amd64 (>= 2.4.75) but it is not installable
#0 11.82                               Depends: libexpat1:amd64 (>= 2.0.1) but it is not installable
#0 11.82                               Depends: libgbm1:amd64 (>= 17.1.0~rc2) but it is not installable
#0 11.82                               Depends: libglib2.0-0:amd64 (>= 2.39.4) but it is not installable
#0 11.82                               Depends: libgtk-3-0:amd64 (>= 3.9.10) but it is not installable or
#0 11.82                                        libgtk-4-1:amd64 but it is not installable
#0 11.82                               Depends: libnspr4:amd64 (>= 2:4.9-2~) but it is not installable
#0 11.82                               Depends: libnss3:amd64 (>= 2:3.35) but it is not installable
#0 11.82                               Depends: libpango-1.0-0:amd64 (>= 1.14.0) but it is not installable
#0 11.82                               Depends: libvulkan1:amd64 but it is not installable
#0 11.82                               Depends: libx11-6:amd64 (>= 2:1.4.99.1) but it is not installable
#0 11.82                               Depends: libxcb1:amd64 (>= 1.9.2) but it is not installable
#0 11.82                               Depends: libxcomposite1:amd64 (>= 1:0.4.4-1) but it is not installable
#0 11.82                               Depends: libxdamage1:amd64 (>= 1:1.1) but it is not installable
#0 11.82                               Depends: libxext6:amd64 but it is not installable
#0 11.82                               Depends: libxfixes3:amd64 but it is not installable
#0 11.82                               Depends: libxkbcommon0:amd64 (>= 0.5.0) but it is not installable
#0 11.82                               Depends: libxrandr2:amd64 but it is not installable
#0 11.83 E: Unable to correct problems, you have held broken packages.
------
ERROR: failed to solve: executor failed running [/bin/sh -c wget -nv -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}-1_amd64.deb     && apt-get update && apt-get install -y /tmp/chrome.deb     && rm /tmp/chrome.deb]: exit code: 100
[28200 ms] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /var/folders/23/69ym20yd7n1ffsskbddkk_gc0000gn/T/devcontainercli/container-features/0.50.0-1694061341139/Dockerfile-with-features -t vsc-nicegui-eabe06171a0264f46bf8e005bdb27cefb1fd0de0ff90392b028d7d6e0d57bcc9 --target dev_containers_target_stage --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label /Users/rodja/Projects/nicegui
[28200 ms]     at IAA (/Users/rodja/.vscode/extensions/ms-vscode-remote.remote-containers-0.304.0/dist/spec-node/devContainersSpecCLI.js:463:1698)
[28200 ms]     at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
[28200 ms]     at async qw (/Users/rodja/.vscode/extensions/ms-vscode-remote.remote-containers-0.304.0/dist/spec-node/devContainersSpecCLI.js:462:1691)
[28200 ms]     at async mK (/Users/rodja/.vscode/extensions/ms-vscode-remote.remote-containers-0.304.0/dist/spec-node/devContainersSpecCLI.js:462:610)
[28200 ms]     at async mAA (/Users/rodja/.vscode/extensions/ms-vscode-remote.remote-containers-0.304.0/dist/spec-node/devContainersSpecCLI.js:479:3660)
[28200 ms]     at async LC (/Users/rodja/.vscode/extensions/ms-vscode-remote.remote-containers-0.304.0/dist/spec-node/devContainersSpecCLI.js:479:4775)
[28201 ms]     at async jeA (/Users/rodja/.vscode/extensions/ms-vscode-remote.remote-containers-0.304.0/dist/spec-node/devContainersSpecCLI.js:611:12219)
[28201 ms]     at async _eA (/Users/rodja/.vscode/extensions/ms-vscode-remote.remote-containers-0.304.0/dist/spec-node/devContainersSpecCLI.js:611:11960)
[28203 ms] Exit code 1
[28205 ms] Command failed: /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Users/rodja/.vscode/extensions/ms-vscode-remote.remote-containers-0.304.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /Users/rodja/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-3487b177-3bf5-4e09-828c-156bd1953f3a1694061337465 --workspace-folder /Users/rodja/Projects/nicegui --workspace-mount-consistency cached --id-label devcontainer.local_folder=/Users/rodja/Projects/nicegui --id-label devcontainer.config_file=/Users/rodja/Projects/nicegui/.devcontainer/devcontainer.json --log-level debug --log-format json --config /Users/rodja/Projects/nicegui/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[28205 ms] Exit code 1

@rodja
Copy link
Member

rodja commented Sep 7, 2023

with the container the testing now also happens inside the poetry virtual environment. You need to run poetry run pytest

@jacoverster Would it not be more convenient to istall it not in a virtual env? It's a container so installing it "globally" should be fine and would simplify usage.

@rodja
Copy link
Member

rodja commented Sep 7, 2023

Seems like Google Chrome is not available for Debian ARM processor yet. Because I the Apple M1/M2 chips are ARM based chrome can not be installed.

@rodja
Copy link
Member

rodja commented Sep 7, 2023

Maybe it's possible to switch to chromium-browser?

@jacoverster
Copy link
Contributor Author

Maybe it's possible to switch to chromium-browser?

It looks like you can access the architecture info during build so we should be able to install processor specific packages.

@jacoverster
Copy link
Contributor Author

jacoverster commented Sep 7, 2023

@rodja can you maybe modify your Dockerfile to a simplified version like this and populate the RUN section under install google chrome for ARM until it builds. Once it builds, add back the rest of the Dockerfile and check if the tests pass?

FROM python:3.8-slim

# Chrome and chromedriver versions must match as per
# https://googlechromelabs.github.io/chrome-for-testing/#stable
ARG CHROME_VERSION=116.0.5845.96
ARG TARGETPLATFORM
RUN echo "I'm building for $TARGETPLATFORM"

# Install google chrome for ARM
RUN ...

# Install chromedriver to a PATH directory
RUN wget -nv -O /tmp/chromedriver.zip https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/${CHROME_VERSION}/linux64/chromedriver-linux64.zip \
    && unzip -j /tmp/chromedriver.zip -d /usr/local/bin/ \
    && rm /tmp/chromedriver.zip

@jacoverster
Copy link
Contributor Author

image

The chromedriver will probably also need to change. All the chrome and chromedriver build versions are available here so maybe we could install it the same way?

@rodja
Copy link
Member

rodja commented Sep 7, 2023

@jacoverster it seems like there is no chrome package available for ARM: https://stackoverflow.com/a/71174097/364388

@jacoverster
Copy link
Contributor Author

It's a container so installing it "globally" should be fine and would simplify usage.

@rodja I tried following the best practices described in this discussion on the poetry repo and summarized in this blog post by one of the poetry contributors.

Would it be possible to completely remove poetry and just install from the pytproject.toml file using pip?

@rodja
Copy link
Member

rodja commented Sep 7, 2023

I've done some experiments/modifications with the Dockerfile to use chromium instead of chrome:

FROM python:3.8-slim

# Chrome and chromedriver versions must match as per
# https://googlechromelabs.github.io/chrome-for-testing/#stable
ARG CHROME_VERSION=116.0.5845.96

ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

ENV POETRY_VERSION=1.6.1 \
    PATH="/home/$USERNAME/.local/bin:$PATH" \
    POETRY_NO_INTERACTION=1 \
    POETRY_VIRTUALENVS_IN_PROJECT=1 \
    POETRY_VIRTUALENVS_CREATE=1 \
    POETRY_CACHE_DIR=/tmp/poetry_cache \
    DISPLAY=:99 \
    DEBIAN_FRONTEND=noninteractive

# Create remote user
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
    && apt-get update \
    && apt-get install -y sudo git wget gnupg unzip curl build-essential \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
    && chmod 0440 /etc/sudoers.d/$USERNAME \
    && rm -rf /var/lib/apt/lists/*

# Install webbrowser and webdriver
RUN apt-get update \
    && apt-get install -y chromium chromium-driver \
    && rm -rf /var/lib/apt/lists/*

USER $USERNAME
WORKDIR /workspaces/nicegui

RUN pip install -U pip && pip install poetry==$POETRY_VERSION

COPY ./pyproject.toml ./poetry.lock* main.py ./
RUN poetry install --all-extras

CMD python -m debugpy --listen 5678 main.py

It starts up fine but the tests failed. The webdriver stuff in conftest.py might need to be changed. But I wont find the time to work on that in the next days.

@jacoverster
Copy link
Contributor Author

I've done some experiments/modifications with the Dockerfile to use chromium instead of chrome

Ok great, I'll modify the Dockerfile to accommodate these changes towards being more platform-specific in the meantime.

@natankeddem
Copy link
Contributor

Hi @natankeddem, with the container the testing now also happens inside the poetry virtual environment. You need to run poetry run pytest. Sometimes the poetry venv can break due to manual installing etc, you can run poetry install again to restore it.

Coming in as just a "user" I feel like it might be nice if somehow we could get the VS Code testing GUI working with this? I understand if there are more complex issues at play that might not allow this functionality. Also, I am running into some errors following your instructions; it seems like there might be some missing dependencies?

It's a container so installing it "globally" should be fine and would simplify usage.

@rodja I tried following the best practices described in this discussion on the poetry repo and summarized in this blog post by one of the poetry contributors.

Would it be possible to completely remove poetry and just install from the pytproject.toml file using pip?

Making the venv also partially removes the inherent advantage of using a container which is that it is a fully encapsulated/reproducible environment. Now you are creating/exposing a venv folder which was not necessarily part of your container build routine that may be polluted in some way outside the scope of the container.

$ poetry run pytest
Creating virtualenv nicegui in /workspaces/nicegui/.venv
Command not found: pytest
$ poetry install
Installing dependencies from lock file

Package operations: 85 installs, 0 updates, 0 removals

  • Installing attrs (23.1.0)
  • Installing exceptiongroup (1.1.2)
  • Installing h11 (0.14.0)
  • Installing idna (3.4)
  • Installing iniconfig (2.0.0)
  • Installing outcome (1.2.0)
  • Installing packaging (23.1)
  • Installing pluggy (1.2.0)
  • Installing py (1.11.0)
  • Installing sniffio (1.3.0)
  • Installing sortedcontainers (2.4.0)
  • Installing toml (0.10.2)
  • Installing typing-extensions (4.7.1)
  • Installing annotated-types (0.5.0)
  • Installing anyio (3.7.1)
  • Installing certifi (2023.7.22)
  • Installing charset-normalizer (3.2.0)
  • Installing pydantic-core (2.4.0)
  • Installing pysocks (1.7.1)
  • Installing pytest (6.2.5)
  • Installing trio (0.22.2)
  • Installing urllib3 (2.0.4)
  • Installing wsproto (1.2.0)
  • Installing bidict (0.22.1)
  • Installing frozenlist (1.4.0)
  • Installing multidict (6.0.4)
  • Installing numpy (1.24.4)
  • Installing pydantic (2.1.1)
  • Installing pytest-metadata (2.0.4)
  • Installing python-engineio (4.5.1)
  • Installing requests (2.31.0)
  • Installing six (1.16.0)
  • Installing starlette (0.27.0)
  • Installing trio-websocket (0.10.3)
  • Installing aiosignal (1.3.1)
  • Installing asttokens (2.2.1)
  • Installing async-timeout (4.0.2)
  • Installing click (8.1.6)
  • Installing colorama (0.4.6)
  • Installing executing (1.2.0)
  • Installing fastapi (0.100.1)
  • Installing httpcore (0.17.3)
  • Installing httptools (0.6.0)
  • Installing markupsafe (2.1.3)
  • Installing pscript (0.7.7)
  • Installing pycodestyle (2.11.0)
  • Installing pygments (2.15.1)
  • Installing pytest-base-url (2.0.0)
  • Installing pytest-html (3.2.0)
  • Installing pytest-variables (2.0.0)
  • Installing python-dateutil (2.8.2)
  • Installing python-dotenv (1.0.0)
  • Installing python-socketio (5.8.0)
  • Installing pytz (2023.3)
  • Installing pyyaml (6.0.1)
  • Installing selenium (4.11.2)
  • Installing soupsieve (2.4.1)
  • Installing tenacity (8.2.2)
  • Installing tzdata (2023.3)
  • Installing uvloop (0.17.0)
  • Installing watchfiles (0.19.0)
  • Installing websockets (11.0.3)
  • Installing yarl (1.9.2)
  • Installing aiofiles (23.1.0)
  • Installing aiohttp (3.8.5)
  • Installing autopep8 (1.7.0)
  • Installing beautifulsoup4 (4.12.2)
  • Installing debugpy (1.6.7)
  • Installing docutils (0.19)
  • Installing fastapi-socketio (0.0.10)
  • Installing httpx (0.24.1)
  • Installing icecream (2.1.3)
  • Installing isort (5.12.0)
  • Installing itsdangerous (2.1.2)
  • Installing jinja2 (3.1.2)
  • Installing markdown2 (2.4.10)
  • Installing orjson (3.9.2)
  • Installing pandas (2.0.3)
  • Installing pytest-asyncio (0.19.0)
  • Installing pytest-selenium (4.0.1)
  • Installing python-multipart (0.0.6)
  • Installing secure (0.3.0)
  • Installing uvicorn (0.22.0)
  • Installing vbuild (0.8.2)
  • Installing webdriver-manager (3.9.1)

Installing the current project: nicegui (0.1.0)
$ poetry run pytest
=========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.8.18, pytest-6.2.5, py-1.11.0, pluggy-1.2.0
driver: Chrome
sensitiveurl: .*
rootdir: /workspaces/nicegui, configfile: pyproject.toml
plugins: asyncio-0.19.0, selenium-4.0.1, base-url-2.0.0, html-3.2.0, anyio-3.7.1, metadata-2.0.4, variables-2.0.0
asyncio: mode=auto
collected 249 items / 1 error / 248 selected                                                                                                                                                              

================================================================================================= ERRORS ==================================================================================================
__________________________________________________________________________________ ERROR collecting tests/test_plotly.py __________________________________________________________________________________
ImportError while importing test module '/workspaces/nicegui/tests/test_plotly.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_plotly.py:2: in <module>
    import plotly.graph_objects as go
E   ModuleNotFoundError: No module named 'plotly'
========================================================================================= short test summary info =========================================================================================
ERROR tests/test_plotly.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================ 1 error in 0.56s =============================================================================================
$ 

@jacoverster
Copy link
Contributor Author

jacoverster commented Sep 7, 2023

@natankeddem to disable the venv just modify the env variables:

    ...
    POETRY_VIRTUALENVS_IN_PROJECT=false \
    POETRY_VIRTUALENVS_CREATE=false \
    ...

And be sure to delete the .venv folder in your project directory, otherwise poetry will detect it and use it.

I've pushed the change to the PR, so just pull them.

@natankeddem
Copy link
Contributor

@natankeddem to disable the venv just modify the env variables:

    ...
    POETRY_VIRTUALENVS_IN_PROJECT=false \
    POETRY_VIRTUALENVS_CREATE=false \
    ...

And be sure to delete the .venv folder in your project directory, otherwise poetry will detect it and use it. I'll push an update for this shortly.

This is giving me a permissions error:

=> ERROR [dev_container_auto_added_stage_label 8/8] RUN poetry install -  2.1s 
------                                                                          
 > [dev_container_auto_added_stage_label 8/8] RUN poetry install --all-extras:  
#0 0.912 Skipping virtualenv creation, as specified in config file.             
#0 1.015 Installing dependencies from lock file                                 
#0 1.300 
#0 1.300 Package operations: 89 installs, 10 updates, 0 removals
#0 1.300 
#0 1.301   • Updating attrs (23.1.0 /home/vscode/.local/lib/python3.8/site-packages -> 23.1.0)
#0 2.045 
#0 2.045   PermissionError
#0 2.045 
#0 2.045   [Errno 13] Permission denied: '/usr/local/lib/python3.8/site-packages/attr'
#0 2.045 
#0 2.045   at /usr/local/lib/python3.8/pathlib.py:1288 in mkdir
#0 2.087       1284│         """
#0 2.087       1285│         if self._closed:
#0 2.087       1286│             self._raise_closed()
#0 2.087       1287│         try:
#0 2.087     → 1288│             self._accessor.mkdir(self, mode)
#0 2.087       1289│         except FileNotFoundError:
#0 2.087       1290│             if not parents or self.parent == self:
#0 2.087       1291│                 raise
#0 2.087       1292│             self.parent.mkdir(parents=True, exist_ok=True)
#0 2.087 
------
Dockerfile-with-features:46
--------------------
  44 |     
  45 |     COPY ./pyproject.toml ./poetry.lock* main.py ./
  46 | >>> RUN poetry install --all-extras
  47 |     
  48 |     CMD python -m debugpy --listen 5678 main.py

@jacoverster
Copy link
Contributor Author

@rodja I noticed that the pip install -e . command is usually run outside the docker containers. Do you prefer this, or can I add it into the container? Alternatively we could add it as a postCreate command in the devcontainer.json file which will always run upon creation.

@jacoverster
Copy link
Contributor Author

This is giving me a permissions error

Just have a look at the updated Dockerfile, the USER $USERNAME line had to be moved down to avoid this.

@jacoverster
Copy link
Contributor Author

Sorry @natankeddem I forgot to add the commit to the PR, will add now.

@natankeddem
Copy link
Contributor

Sorry @natankeddem I forgot to add the commit to the PR, will add now.

Okay just let me know when things are in a state where you feel comfortable with me testing things out more.

@jacoverster
Copy link
Contributor Author

Okay just let me know when things are in a state where you feel comfortable with me testing things out more

Please continue, I pushed the commit.

@natankeddem
Copy link
Contributor

Okay, container builds successfully now. I got dependency errors with poetry run pytest so I did a poetry install but that gave me permission errors. I haven't dug into things but shouldn't the RUN poetry install --all-extras in your Dockerfile be installing all the python dependencies? The user inside the container might not have permissions to install things after the container build process depending on how things are setup.

$ poetry run pytest
Skipping virtualenv creation, as specified in config file.
ImportError while loading conftest '/workspaces/nicegui/tests/conftest.py'.
tests/conftest.py:12: in <module>
    from nicegui import Client, binding, globals  # pylint: disable=redefined-builtin
nicegui/__init__.py:1: in <module>
    from . import elements, globals, ui  # pylint: disable=redefined-builtin
nicegui/ui.py:95: in <module>
    from .element import Element as element
nicegui/element.py:14: in <module>
    from .dependencies import Component, Library, register_library, register_vue_component
nicegui/dependencies.py:11: in <module>
    from .version import __version__
nicegui/version.py:3: in <module>
    __version__: str = importlib.metadata.version('nicegui')
E   importlib.metadata.PackageNotFoundError: nicegui
$ poetry install
Skipping virtualenv creation, as specified in config file.
Installing dependencies from lock file

Package operations: 0 installs, 0 updates, 14 removals

  • Removing bottle (0.12.25): Failed

  CalledProcessError

  Command '['/usr/local/bin/python', '-m', 'pip', 'uninstall', 'bottle', '-y']' returned non-zero exit status 2.

  at /usr/local/lib/python3.8/subprocess.py:516 in run
       512│             # We don't call process.wait() as .__exit__ does that for us.
       513│             raise
       514│         retcode = process.poll()
       515│         if check and retcode:
    →  516│             raise CalledProcessError(retcode, process.args,
       517│                                      output=stdout, stderr=stderr)
       518│     return CompletedProcess(process.args, retcode, stdout, stderr)
       519│ 
       520│ 

The following error occurred when trying to handle this error:


  EnvCommandError

  Command ['/usr/local/bin/python', '-m', 'pip', 'uninstall', 'bottle', '-y'] errored with the following return code 2
  
  Output:
  Found existing installation: bottle 0.12.25
  Uninstalling bottle-0.12.25:
  ERROR: Exception:
  Traceback (most recent call last):
    File "/usr/local/lib/python3.8/shutil.py", line 791, in move
      os.rename(src, real_dst)
  PermissionError: [Errno 13] Permission denied: '/usr/local/bin/bottle.py' -> '/tmp/pip-uninstall-bt4_xhdt/bottle.py'
...
...

@jacoverster
Copy link
Contributor Author

jacoverster commented Sep 7, 2023

@natankeddem as per the current setup you first need to install nicegui locally with pip install -e .. I'm awaiting feedback to maybe put it into the container, but you will need to install it like that for now.

If you want to change the poetry installation with something like poetry install or poetry add ... then you must run it using sudo because it needs root access to the container.

@jacoverster
Copy link
Contributor Author

I suggest we update the relevant contribution/test documentation after this has been thoroughly tested @rodja.

@natankeddem
Copy link
Contributor

Makes sense, I am all for removing additional steps if you can. To get this to work I had to make a venv manually then select it in the dev container then pip install -e .. I am not even sure if what I did was really the correct way of doing things but I got pytest to run. It would be great if you can just click the open dev container once VS Code loads then be off to developing without any additional thought required as to what dependencies to install and which tool to use (pip, poetry, ???).

@natankeddem
Copy link
Contributor

https://askubuntu.com/a/1120102
That provides some ideas on the limit.h related dependencies.

@rodja
Copy link
Member

rodja commented Sep 22, 2023

Ah, if I set FROM --platform=linux/amd64 python:3.8-slim in the Dockerfile the tests start and execute. But they often run into timeouts:

Screenshot 2023-09-22 at 06 20 48

Looks like the emulation is not fast enough (even with Rosetta turned on).

.devcontainer/Dockerfile Outdated Show resolved Hide resolved
@jacoverster
Copy link
Contributor Author

Strange. Now I got the build error

This is strange. To further simplify things we can also consider moving away from the slim container. Maybe try that with the MacOS tests as well, it's possible that missing packages can cause the slow emulation time?

@rodja
Copy link
Member

rodja commented Sep 22, 2023

moving away from the slim container

If I remove the -slim suffix, it builds fine with gcc. But the tests still can't be executed when not using the amd64 image...

to fix pytest on macos arm (M1)
@rodja
Copy link
Member

rodja commented Sep 22, 2023

I got the tests working on mac arm64 (M1). I just needed to configure the binary to chromium. See c8a6eee.

@natankeddem
Copy link
Contributor

So enabling rosetta and switching to amd64 did get things to work but too slowly it sounds like? That discussion on https://github.com/browserless/chrome/ also had some ideas on downloading and matching ARM driver versions. I haven't really dug in, but is that any help to you guys on getting M1 support working? It says to get drivers from here:
https://launchpad.net/ubuntu/bionic/arm64/chromium-chromedriver

@rodja
Copy link
Member

rodja commented Sep 22, 2023

From my point of view we are almost ready (for a first "basic devcontainer"):

  • documentation
  • deciding if we want to use build-essential and python.3.8-slim (~100mb) or simply python-3.8 which already comes with build-essential, wget curl, sed, awk and more useful development tools (~500mb); I'm leaning towards python-3.8 without -slim.
  • if I start the devcontainer and open a terminal it's still /bin/sh

@jacoverster
Copy link
Contributor Author

jacoverster commented Sep 22, 2023

  • if I start the devcontainer and open a terminal it's still /bin/sh

I've compared built sizes here and python-3.8 is at 2.19GB and python.3.8-slim is at 1.6GB for reference. No preference from my side, so happy with both. I'll push 3.8 for now so you can maybe test to see if we can do without build-essentials?

  • if I start the devcontainer and open a terminal it's still /bin/sh

I've made another change to the settings in devcontainer.json, not sure what else to try here as mine defaults to bash. It is maybe worth trying to set this in your VSCode settings? Does that work?

  • documentation

I'm going on a few days of leave today. Will tackle this when I get back.

@jacoverster
Copy link
Contributor Author

One other images we can consider is the official vscode one. It has some nice benefits like built in remote user, security patches, multi-arch support, etc. Just putting it on the table as a potential option as well.

@rodja
Copy link
Member

rodja commented Sep 22, 2023

One other images we can consider is the official vscode one.

Interesting. I'll try it out.

@jacoverster
Copy link
Contributor Author

Interesting. I'll try it out.

Have a look at the linked documentation and the additional features you can add to your container - might be something useful there for you.

@natankeddem
Copy link
Contributor

Should the extensions in .devcontainer/devcontainer.json match nicegui.code-workspace?

@rodja
Copy link
Member

rodja commented Sep 22, 2023

Should the extensions in .devcontainer/devcontainer.json match nicegui.code-workspace?

Yes that would be good!

@rodja
Copy link
Member

rodja commented Sep 23, 2023

While the official python container from vscode looks interesting it may take some time and thinking to figure out how we want to do this. I would like to do this in a separate PR. This one is already quite complex and with 60+ comments a long time in the making.
Because bash now works for me also and documentation was quite easy to add, I consider the "basic version" to be ready for merge!

@rodja rodja self-requested a review September 23, 2023 03:50
@rodja rodja added this to the 1.3.15 milestone Sep 23, 2023
@rodja rodja added the enhancement New feature or request label Sep 23, 2023
@rodja rodja merged commit c93c9b9 into zauberzeug:main Sep 23, 2023
1 check was pending
@jacoverster
Copy link
Contributor Author

Great, thanks for wrapping up the docs @rodja. Glad to get this merged.

@jacoverster jacoverster deleted the basic-devcontainer branch September 26, 2023 06:40
@falkoschindler falkoschindler linked an issue Sep 29, 2023 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Development environment using devcontainer
3 participants