From 8cc9b489648e934781290aa2ff453f47f3fb5abf Mon Sep 17 00:00:00 2001 From: Simon Jordan Date: Sun, 17 Nov 2024 14:03:03 +0000 Subject: [PATCH] Add support for Python integration tests --- .devcontainer/devcontainer.json | 14 ++++++++++---- Dockerfile | 14 +++++++++++++- tools/fix/fixdialectc | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ebde165..89c4047 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,10 +10,16 @@ "extensions": [ "ms-vscode.cpptools", "ms-vscode.cmake-tools", - "GitHub.vscode-github-actions" - ] + "GitHub.vscode-github-actions", + "ms-python.python" + ], + "settings": { + "python.defaultInterpreterPath": "/venv/bin/python", + "python.venvPath": "/venv", + "terminal.integrated.defaultProfile.linux": "bash" + } } }, - "postCreateCommand": "cmake -S . -B build", + "postCreateCommand": "python3 -m venv /venv && source /venv/bin/activate && pip install --no-cache-dir pytest pyyaml && cmake -S . -B build", "remoteUser": "root" -} +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 50031ed..25bd46e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,8 @@ ENV LANG=C.UTF-8 ENV LC_ALL=C.UTF-8 ENV CC=/usr/bin/gcc ENV CXX=/usr/bin/g++ +ENV VIRTUAL_ENV=/venv +ENV PATH="$VIRTUAL_ENV/bin:$PATH" # Install core development tools and dependencies RUN apt-get update && apt-get install -y \ @@ -22,6 +24,7 @@ RUN apt-get update && apt-get install -y \ zlib1g-dev \ python3 \ python3-pip \ + python3-venv \ python3-yaml \ git \ xxd \ @@ -42,6 +45,12 @@ RUN gcc --version && g++ --version && cmake --version # Set the working directory WORKDIR /usr/src/SubZero +# Create and activate a Python virtual environment +RUN python3 -m venv $VIRTUAL_ENV + +# Install Python dependencies into the virtual environment +RUN pip install --no-cache-dir pytest pyyaml + # Copy the entire project into the container, excluding files in .dockerignore COPY . . @@ -51,11 +60,14 @@ RUN chmod +x tools/gen-version-file \ tools/gen-test-proto \ tools/fix/fixdialectc +# Add virtual environment activation to bashrc +RUN echo "source $VIRTUAL_ENV/bin/activate" >> ~/.bashrc + # Build the project using CMake with verbose output RUN cmake -S . -B build -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=20 -DCMAKE_CXX_STANDARD_REQUIRED=ON RUN cmake --build build -# Run tests +# Run C++ tests RUN cd build && ctest --output-on-failure # Default command when the container is run diff --git a/tools/fix/fixdialectc b/tools/fix/fixdialectc index d07b33d..17be0d5 100755 --- a/tools/fix/fixdialectc +++ b/tools/fix/fixdialectc @@ -11,7 +11,7 @@ parser.add_argument('--source-path', help="output source path") args = parser.parse_args() -data = yaml.load(open(args.input_file, 'r')) +data = yaml.load(open(args.input_file, 'r'), Loader=yaml.SafeLoader) name = data["name"] base_protocol = data["base_protocol"]