Skip to content

Commit

Permalink
python3: Fix and improve pip install on host and containers
Browse files Browse the repository at this point in the history
Remove --system-break-packages from pip install and add
requirements-local.txt to separate the host pip dependencies from the
debug container ones (requirements-debug.txt).

Signed-off-by: Andre Riesco <[email protected]>
  • Loading branch information
andreriesco committed Apr 18, 2024
1 parent 9195cdb commit e6d4d38
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 33 deletions.
12 changes: 6 additions & 6 deletions python3Console/.doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ The deployable package is then copied into the running debug container using **s

Remote debugging is performed by running **debugpy** inside the running container on the device, in a task named **start-torizon-debug\${architecture}**, and then attaching to this running container, as described at [VSCode Python remote debugging](https://code.visualstudio.com/docs/python/debugging#_remote-script-debugging-with-ssh). For local debugging, the method used is the one described in the [VSCode documentation for Python Debugging](https://code.visualstudio.com/docs/python/debugging) is used. The tasks that perform the debugging are those present in the **launch.json** file.

The dependencies of the project that should be installed using **pip** should be defined on the **requirements-debug.txt** file (remote Debug image and local host dependencies) and on the **requirements-release.txt** file (remote Release image dependencies).
The python packages of the project that should be installed using **pip** should be defined on:
- **requirements-local.txt** file for host/local debugging packages
- **requirements-debug.txt** file for remote debugging image package (installed on **Dockerfile.debug** file)
- **requirements-release.txt** file for production (release) image packages (installed on **Dockerfile** file)

The source code of the template is a simple Hello World (Hello Torizon, actually) in Python.

Expand All @@ -27,17 +30,14 @@ How to create a virtual environment on this template:

`python -m venv .venv --system-site-packages`

If you do not want to use Python packages installed with **apt** on your host remove the **--system-site-packages** argument. In this case, you have to include **debugpy** on the **requirements-debug.txt** file.
If you do not want to use Python packages installed with **apt** on your host remove the **--system-site-packages** argument.

- Press **F1**
- Select the command **Python: Select Interpreter**
- Select the Python interpreter of your **.venv**
- Select the Python interpreter of your **.venv**
- If it doesn't select the Python from the venv, press F1 and select the command
**Developer: Reload Window**)

To install a Python package on the venv (and also on the Debug image), put it
on the **requirements-debug.txt** file (to install it on the Release image put it
on the **requirements.release.txt** file)

For more details, please watch the demonstration video below:

Expand Down
7 changes: 3 additions & 4 deletions python3Console/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "process",
"args": [
"4",
],
],
"dependsOn": [
"validate-settings",
"validate-arch-arm",
Expand Down Expand Up @@ -62,7 +62,7 @@
"type": "process",
"args": [
"4",
],
],
"dependsOn": [
"validate-settings",
"validate-arch-arm64",
Expand Down Expand Up @@ -117,9 +117,8 @@
"-m",
"pip",
"install",
"--break-system-packages",
"-r",
"requirements-debug.txt"
"requirements-local.txt"
],
"dependsOrder": "sequence",
"problemMatcher": "$msCompile",
Expand Down
7 changes: 3 additions & 4 deletions python3Console/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ RUN python3 -m venv ${APP_ROOT}/.venv --system-site-packages
# Install pip packages on venv
COPY requirements-release.txt /requirements-release.txt
RUN . ${APP_ROOT}/.venv/bin/activate && \
pip3 install --upgrade pip && pip3 install --break-system-packages -r requirements-release.txt && \
pip3 install --upgrade pip && pip3 install -r requirements-release.txt && \
rm requirements-release.txt

# Copy the application source code in the workspace to the $APP_ROOT directory
# path inside the container, where $APP_ROOT is the torizon_app_root
# Copy the application source code in the workspace to the $APP_ROOT directory
# path inside the container, where $APP_ROOT is the torizon_app_root
# configuration defined in settings.json
COPY ./src ${APP_ROOT}/src

Expand All @@ -53,4 +53,3 @@ WORKDIR ${APP_ROOT}
ENV APP_ROOT=${APP_ROOT}
# Activate and run the code
CMD . ${APP_ROOT}/.venv/bin/activate && python3 src/main.py --no-sandbox

6 changes: 3 additions & 3 deletions python3Console/Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ RUN python3 -m venv ${APP_ROOT}/.venv --system-site-packages
# Install pip packages on venv
COPY requirements-debug.txt /requirements-debug.txt
RUN . ${APP_ROOT}/.venv/bin/activate && \
pip3 install --upgrade pip && pip3 install --break-system-packages -r requirements-debug.txt && \
pip3 install --upgrade pip && pip3 install -r requirements-debug.txt && \
rm requirements-debug.txt

# ⚠️ DEBUG PURPOSES ONLY!!
Expand All @@ -99,8 +99,8 @@ RUN mkdir /var/run/sshd && \
RUN rm -r /etc/ssh/ssh*key && \
dpkg-reconfigure openssh-server

# Copy the application source code in the workspace to the $APP_ROOT directory
# path inside the container, where $APP_ROOT is the torizon_app_root
# Copy the application source code in the workspace to the $APP_ROOT directory
# path inside the container, where $APP_ROOT is the torizon_app_root
# configuration defined in settings.json
COPY --chown=$SSHUSERNAME:$SSHUSERNAME ./src ${APP_ROOT}/src

Expand Down
1 change: 1 addition & 0 deletions python3Console/requirements-local.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debugpy
14 changes: 8 additions & 6 deletions python3Pyside2QML/.doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ The deployable package is then copied into the running debug container using **s

Remote debugging is performed by running **debugpy** inside the running container on the device, in a task named **start-torizon-debug\${architecture}**, and then attaching to this running container, as described at [VSCode Python remote debugging](https://code.visualstudio.com/docs/python/debugging#_remote-script-debugging-with-ssh). For local debugging, the method used is the one described in the [VSCode documentation for Python Debugging](https://code.visualstudio.com/docs/python/debugging) is used. The tasks that perform the debugging are those present in the **launch.json** file.

The dependencies of the project that should be installed using **pip** should be defined on the **requirements-debug.txt** file (remote Debug image and local host dependencies) and on the **requirements-release.txt** file (remote Release image dependencies).
The python packages of the project that should be installed using **pip** should be defined on:
- **requirements-local.txt** file for host/local debugging packages
- **requirements-debug.txt** file for remote debugging image package (installed on **Dockerfile.debug** file)
- **requirements-release.txt** file for production (release) image packages (installed on **Dockerfile** file)

The source code of the template is a simple Hello World (Hello Torizon, actually) in Python.

## Create a Python Virtual Environment

Expand All @@ -25,17 +30,14 @@ How to create a virtual environment on this template:

`python -m venv .venv --system-site-packages`

If you do not want to use Python packages installed with **apt** on your host remove the **--system-site-packages** argument. In this case, you have to include **debugpy** on the **requirements-debug.txt** file.
If you do not want to use Python packages installed with **apt** on your host remove the **--system-site-packages** argument.

- Press **F1**
- Select the command **Python: Select Interpreter**
- Select the Python interpreter of your **.venv**
- Select the Python interpreter of your **.venv**
- If it doesn't select the Python from the venv, press F1 and select the command
**Developer: Reload Window**)

To install a Python package on the venv (and also on the Debug image), put it
on the **requirements-debug.txt** file (to install it on the Release image put it
on the **requirements.release.txt** file)

For more details, please watch the demonstration video below:

Expand Down
7 changes: 3 additions & 4 deletions python3Pyside2QML/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "process",
"args": [
"4",
],
],
"dependsOn": [
"validate-settings",
"validate-arch-arm",
Expand Down Expand Up @@ -62,7 +62,7 @@
"type": "process",
"args": [
"4",
],
],
"dependsOn": [
"validate-settings",
"validate-arch-arm64",
Expand Down Expand Up @@ -117,9 +117,8 @@
"-m",
"pip",
"install",
"--break-system-packages",
"-r",
"requirements-debug.txt"
"requirements-local.txt"
],
"dependsOrder": "sequence",
"problemMatcher": "$msCompile",
Expand Down
6 changes: 3 additions & 3 deletions python3Pyside2QML/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ RUN python3 -m venv ${APP_ROOT}/.venv --system-site-packages
# Install pip packages on venv
COPY requirements-release.txt /requirements-release.txt
RUN . ${APP_ROOT}/.venv/bin/activate && \
pip3 install --upgrade pip && pip3 install --break-system-packages -r requirements-release.txt && \
pip3 install --upgrade pip && pip3 install -r requirements-release.txt && \
rm requirements-release.txt

USER torizon

# Copy the application source code in the workspace to the $APP_ROOT directory
# path inside the container, where $APP_ROOT is the torizon_app_root
# Copy the application source code in the workspace to the $APP_ROOT directory
# path inside the container, where $APP_ROOT is the torizon_app_root
# configuration defined in settings.json
COPY ./src ${APP_ROOT}/src

Expand Down
6 changes: 3 additions & 3 deletions python3Pyside2QML/Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ RUN python3 -m venv ${APP_ROOT}/.venv --system-site-packages
# Install pip packages on venv
COPY requirements-debug.txt /requirements-debug.txt
RUN . ${APP_ROOT}/.venv/bin/activate && \
pip3 install --upgrade pip && pip3 install --break-system-packages -r requirements-debug.txt && \
pip3 install --upgrade pip && pip3 install -r requirements-debug.txt && \
rm requirements-debug.txt

# ⚠️ DEBUG PURPOSES ONLY!!
Expand All @@ -131,8 +131,8 @@ RUN mkdir /var/run/sshd && \
RUN rm -r /etc/ssh/ssh*key && \
dpkg-reconfigure openssh-server

# Copy the application source code in the workspace to the $APP_ROOT directory
# path inside the container, where $APP_ROOT is the torizon_app_root
# Copy the application source code in the workspace to the $APP_ROOT directory
# path inside the container, where $APP_ROOT is the torizon_app_root
# configuration defined in settings.json
COPY --chown=$SSHUSERNAME:$SSHUSERNAME ./src ${APP_ROOT}/src

Expand Down
1 change: 1 addition & 0 deletions python3Pyside2QML/requirements-local.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debugpy

0 comments on commit e6d4d38

Please sign in to comment.