From 441cbe1f75c81d888bfbc85001101c1f1f76d238 Mon Sep 17 00:00:00 2001 From: Stephan van Rooij <1292510+svrooij@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:57:27 +0000 Subject: [PATCH] docs: DevContainer added and explained Trying to make life easier for new contributors to this project by adding a dev container and additional docs Fixed Provide DevContainer with tests configured #453 --- .devcontainer/devcontainer.json | 40 ++++++++++ .vscode/settings.json | 20 +++++ .vscode/tasks.json | 132 ++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 41 +++++++++- requirements_dev.txt | 2 + 5 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 requirements_dev.txt diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..c0403d5 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,40 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/python +{ + "name": "Python 3", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + // "image": "mcr.microsoft.com/devcontainers/python:3.9-bookworm", + // "image": "mcr.microsoft.com/devcontainers/python:3.10-bookworm", + // "image": "mcr.microsoft.com/devcontainers/python:3.11-bookworm", + "image": "mcr.microsoft.com/devcontainers/python:3.12-bookworm", + // "image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye", + + "features": { + "ghcr.io/hspaans/devcontainer-features/pytest:1": {}, + "ghcr.io/devcontainers-extra/features/pylint:2": {}, + "ghcr.io/devcontainers-extra/features/poetry:2": {}, + "ghcr.io/devcontainers/features/powershell:1": {} + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "git config --global core.autocrlf true && pip3 install --user -r requirements_dev.txt && pwsh -File kiota-python.ps1 install-deps", + + // Configure tool-specific properties. + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "wmiller4.python-venv-switcher" + ] + } + } + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..790145e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,20 @@ +{ + "python.testing.cwd": ".", + // "python.poetryPath": ".venv/bin/poetry", + // "python.testing.pytestPath": ".venv/bin/pytest", + // "python.analysis.typeCheckingMode": "basic", + "python.testing.pytestArgs": [ + "packages/tests", + "packages/abstractions/tests", + "packages/authentication/tests", + "packages/bundle/tests", + "packages/http/tests", + "packages/serialization/form/tests", + "packages/serialization/json/tests", + "packages/serialization/multipart/tests", + "packages/serialization/text/tests", + "--rootdir=${workspaceFolder}" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": false, // Disable pytest (does not work with poetry yet) +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..cb76d8d --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,132 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "poetry:deps", + "type": "shell", + "command": "pwsh", + "args": [ + "--File", + "kiota-python.ps1", + "install-deps" + ], + "options": { + "cwd": "${workspaceFolder}", + }, + "problemMatcher": [ + "$python" + ] + }, + { + "label": "poetry:format", + "type": "shell", + "command": "pwsh", + "args": [ + "--File", + "kiota-python.ps1", + "format" + ], + "options": { + "cwd": "${workspaceFolder}", + }, + "problemMatcher": [ + "$python" + ] + }, + { + "label": "poetry:check-format", + "type": "shell", + "command": "pwsh", + "args": [ + "--File", + "kiota-python.ps1", + "check-format" + ], + "options": { + "cwd": "${workspaceFolder}", + }, + "problemMatcher": [ + "$python" + ] + }, + { + "label": "poetry:lint", + "type": "shell", + "command": "pwsh", + "args": [ + "--File", + "kiota-python.ps1", + "lint" + ], + "options": { + "cwd": "${workspaceFolder}", + }, + "problemMatcher": [ + "$python" + ] + }, + { + "label": "poetry:check-types", + "type": "shell", + "command": "pwsh", + "args": [ + "--File", + "kiota-python.ps1", + "test" + ], + "options": { + "cwd": "${workspaceFolder}", + }, + "problemMatcher": [ + "$python" + ] + }, + { + "label": "poetry:test", + "type": "shell", + "command": "pwsh", + "args": [ + "--File", + "kiota-python.ps1", + "test" + ], + "options": { + "cwd": "${workspaceFolder}", + }, + "problemMatcher": [ + "$python" + ] + }, + { + "label": "poetry:check-all", + "type": "shell", + "command": "pwsh", + "args": [ + "--File", + "kiota-python.ps1", + "test" + ], + "options": { + "cwd": "${workspaceFolder}", + }, + "problemMatcher": [ + "$python" + ] + }, + { + "label": "pre-commit", + "type": "shell", + "command": "echo", + "args": [ + "All tests executed" + ], + "dependsOn":[ + "poetry:format", + "poetry:check-all" + ] + } + + ] +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eb66cf1..1fbd154 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,5 @@ -# Contributing to Kiota Java +# Contributing to Kiota Python Kiota Python is a mono-repo containing source code for the following packages: @@ -142,3 +142,42 @@ To run type checking using `mypy` across all projects, run the following in a po ``` __TIP__ Running `.\kiota-python.ps1 test` should give a hint of all available commands you can pass to the script to run across projects which can be configured this in [this file](./projects-config.json). + + +## Dev Container + +This repository is setup to use [Visual Studio Code Dev Containers](https://code.visualstudio.com/docs/remote/containers) to provide a consistent development environment for contributors. The dev container is configured to have all the necessary tools and dependencies to work on the repository. + +By default we do all development in `Python 3.12`, but we support Python 3.9, 3.10, 3.11, and 3.12. The dev container is configured to use Python 3.12, but you can test your changes by changing the `"image": "mcr.microsoft.com/devcontainers/python:3.12-bookworm",` line in the `.devcontainer/devcontainer.json` file to the desired version. If you save changes to this file, you will be prompted to rebuild the dev container. You can also rebuild the dev container by running the `Remote-Containers: Rebuild Container` command from the command palette. + +### Dependencies + +Upon loading the dev container the `pwsh -File ./kiota-python.ps1 install-deps` command will be run to install the necessary dependencies for the repository. You can also run this command manually by Running the `poetry:deps` task from the VSCode command `Run Task` palette. + +Or run the following command in the terminal: + +```shell +pwsh -File ./kiota-python.ps1 install-deps +``` + +### Running Tests + +To run the tests in the dev container, you can run the `poetry:test` task from the VSCode command `Run Task` palette. + +Or run the following command in the terminal: + +```shell +pwsh -File ./kiota-python.ps1 test +``` + +### Pre-commit tests + +All PR's are tested by the GitHub Actions workflow. To tacle issues before committing, it is adviced to run the `pre-commit` task from the VSCode command `Run Task` palette. This will format your code and run the same checks that are run in the GitHub Actions workflow. + +Or run the following command in the terminal: + +```shell +pwsh -File ./kiota-python.ps1 format +pwsh -File ./kiota-python.ps1 check-all +``` + diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..74ce4cb --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,2 @@ +pylint==3.2.7 +poetry-plugin-mono-repo-deps==0.3.0