main
Matias Mas Viehl 2025-12-14 15:28:48 +01:00
parent 828937930f
commit a7ee33bdb0
9 changed files with 90 additions and 16 deletions

View File

@ -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

View File

@ -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"
}

View File

@ -0,0 +1,8 @@
#include <stdint.h>
// 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;
}

View File

@ -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}")

View File

@ -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}")

View File

@ -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}")

View File

@ -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}")

View File

@ -0,0 +1,2 @@
numpy
flask

View File

@ -0,0 +1,10 @@
from flask import Flask
app = Flask(__name__)
@app.route("/hallo")
def hallo_welt():
return "<h1>Hallo vom Server!</h1>"
if __name__ == "__main__":
app.run(debug=False)