From a7ee33bdb0c37331c1858bc57c2d44d5cd3f1034 Mon Sep 17 00:00:00 2001 From: 3020772 <3020772@stud.hs-mannheim.de> Date: Sun, 14 Dec 2025 15:28:48 +0100 Subject: [PATCH] merge --- python/.devcontainer/Dockerfile | 25 ++++++++++++------- python/.devcontainer/devcontainer.json | 15 +++++------ python/02_python_interestingPoints/adder.c | 8 ++++++ .../gerade_quadrate.py | 11 ++++++++ .../02_python_interestingPoints/mittelwert.py | 7 ++++++ python/02_python_interestingPoints/ordner.py | 12 +++++++++ .../python_interface.py | 16 ++++++++++++ .../requirements.txt | 2 ++ .../02_python_interestingPoints/webbserver.py | 10 ++++++++ 9 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 python/02_python_interestingPoints/adder.c create mode 100644 python/02_python_interestingPoints/gerade_quadrate.py create mode 100644 python/02_python_interestingPoints/mittelwert.py create mode 100644 python/02_python_interestingPoints/ordner.py create mode 100644 python/02_python_interestingPoints/python_interface.py create mode 100644 python/02_python_interestingPoints/requirements.txt create mode 100644 python/02_python_interestingPoints/webbserver.py diff --git a/python/.devcontainer/Dockerfile b/python/.devcontainer/Dockerfile index eff9cf2..174c999 100644 --- a/python/.devcontainer/Dockerfile +++ b/python/.devcontainer/Dockerfile @@ -1,13 +1,20 @@ -FROM python:3.11-slim +FROM mcr.microsoft.com/devcontainers/python:3.11 -RUN apt-get update && apt-get install -y build-essential +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends build-essential \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* -ARG USERNAME=vscode -ARG USER_UID=1000 -ARG USER_GID=$USER_UID +# --- C-BIBLIOTHEK BAUEN (adder.c) --- +COPY adder.c /tmp/adder.c +# Kompiliert und speichert an einem systemweiten Ort +RUN gcc -shared -o /usr/local/lib/libadder.so /tmp/adder.c -RUN pip install --no-cache-dir pytest black +# --- PYTHON-ABHÄNGIGKEITEN --- +# Kopiert requirements.txt aus dem Projekt-Root +COPY requirements.txt . +# Installiert die Pakete +RUN pip install --no-cache-dir -r requirements.txt -RUN groupadd --gid $USER_GID $USERNAME && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -USER $USERNAME -WORKDIR /workspace +# Setzt das Arbeitsverzeichnis im Container (dies sollte der Mount-Punkt sein) +WORKDIR /workspace \ No newline at end of file diff --git a/python/.devcontainer/devcontainer.json b/python/.devcontainer/devcontainer.json index 5b115e6..a3ae4be 100644 --- a/python/.devcontainer/devcontainer.json +++ b/python/.devcontainer/devcontainer.json @@ -1,21 +1,20 @@ { "name": "Python 3.11 Dev Container", - "image": "dev-test-image:latest", - //"dockerFile": "Dockerfile", + "build": { + "dockerfile": "Dockerfile", + "context": "../02_python_interestingPoints" + }, "mounts": [ "source=${localWorkspaceFolder},target=/workspace,type=bind" ], "remoteUser": "vscode", - "customizations": { "vscode": { "settings": { - // Testing: Pytest-Erkennung aktivieren "python.testing.pytestEnabled": true, "python.testing.pytestArgs": [ "." ], - "python.linting.enabled": true, "python.linting.pylintEnabled": true, "python.formatting.provider": "black" @@ -23,9 +22,11 @@ "extensions": [ "ms-python.python", "ms-python.vscode-pylance" - ] + ], + "features": { + "ghcr.io/devcontainers/features/git:1": {} + } } }, - "postCreateCommand": "pip install --upgrade pip" } \ No newline at end of file diff --git a/python/02_python_interestingPoints/adder.c b/python/02_python_interestingPoints/adder.c new file mode 100644 index 0000000..5052936 --- /dev/null +++ b/python/02_python_interestingPoints/adder.c @@ -0,0 +1,8 @@ +#include + +// Die Funktion, die Python aufrufen wird +// extern "C" ist wichtig, um die Namenskonvention (Name Mangling) zu verhindern +extern int32_t addiere_zahlen(int32_t a, int32_t b) { + // Gibt die Summe der beiden übergebenen Zahlen zurück + return a + b; +} \ No newline at end of file diff --git a/python/02_python_interestingPoints/gerade_quadrate.py b/python/02_python_interestingPoints/gerade_quadrate.py new file mode 100644 index 0000000..1b3c69c --- /dev/null +++ b/python/02_python_interestingPoints/gerade_quadrate.py @@ -0,0 +1,11 @@ +max = 100 + +gerade_quadrate_lang = [] +for i in range(1, max): + if i % 2 == 0: + gerade_quadrate_lang.append(i * i) + +gerade_quadrate_kurz = [i * i for i in range(1, max) if i % 2 == 0] + +print(f"Liste (iterativ): {gerade_quadrate_lang}") +print(f"Liste (funktional): {gerade_quadrate_kurz}") \ No newline at end of file diff --git a/python/02_python_interestingPoints/mittelwert.py b/python/02_python_interestingPoints/mittelwert.py new file mode 100644 index 0000000..469c033 --- /dev/null +++ b/python/02_python_interestingPoints/mittelwert.py @@ -0,0 +1,7 @@ +import numpy as np + +messwerte = np.array([25.5, 30.1, 28.9, 35.0, 29.8, 31.2]) + +durchschnitt = np.mean(messwerte) + +print(f"Der durchschnittliche Wert beträgt: {durchschnitt:.2f}") \ No newline at end of file diff --git a/python/02_python_interestingPoints/ordner.py b/python/02_python_interestingPoints/ordner.py new file mode 100644 index 0000000..b7b2fe6 --- /dev/null +++ b/python/02_python_interestingPoints/ordner.py @@ -0,0 +1,12 @@ +import os + +aktueller_ordner = "." + +print(f"Inhalt des Ordners '{aktueller_ordner}':") + +for element in os.listdir(aktueller_ordner): + + if os.path.isfile(element): + print(f" - Datei: {element}") + else: + print(f" - Ordner: {element}") \ No newline at end of file diff --git a/python/02_python_interestingPoints/python_interface.py b/python/02_python_interestingPoints/python_interface.py new file mode 100644 index 0000000..fd12d32 --- /dev/null +++ b/python/02_python_interestingPoints/python_interface.py @@ -0,0 +1,16 @@ +import ctypes +import os + +lib_path = "/usr/local/lib/libadder.so" +c_lib = ctypes.CDLL(lib_path) + +c_lib.addiere_zahlen.argtypes = [ctypes.c_int32, ctypes.c_int32] +c_lib.addiere_zahlen.restype = ctypes.c_int32 + +zahl_a = 33 +zahl_b = 34 + +ergebnis = c_lib.addiere_zahlen(zahl_a, zahl_b) + +print(f"Zahlen: {zahl_a} + {zahl_b}") +print(f"Ergebnis von C-Funktion: {ergebnis}") \ No newline at end of file diff --git a/python/02_python_interestingPoints/requirements.txt b/python/02_python_interestingPoints/requirements.txt new file mode 100644 index 0000000..f8f99f0 --- /dev/null +++ b/python/02_python_interestingPoints/requirements.txt @@ -0,0 +1,2 @@ +numpy +flask \ No newline at end of file diff --git a/python/02_python_interestingPoints/webbserver.py b/python/02_python_interestingPoints/webbserver.py new file mode 100644 index 0000000..51e1868 --- /dev/null +++ b/python/02_python_interestingPoints/webbserver.py @@ -0,0 +1,10 @@ +from flask import Flask + +app = Flask(__name__) + +@app.route("/hallo") +def hallo_welt(): + return "

Hallo vom Server!

" + +if __name__ == "__main__": + app.run(debug=False) \ No newline at end of file