diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 935bcd0..6f6659c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -6,6 +6,23 @@ "vscode" ], "workspaceFolder": "/workspace", + "mounts": [ + { + "source": "cache-${devcontainerId}", + "target": "/home/${remoteUser}/.cache", + "type": "volume" + }, + { + "source": "venv-${devcontainerId}", + "target": "${containerWorkspaceFolder}/.venv", + "type": "volume" + }, + { + "source": "${localEnv:HOME}/.ssh", + "target": "/home/${remoteUser}/.ssh", + "type": "bind" + } + ], "features": { "ghcr.io/dhoeric/features/hadolint:1": {} }, @@ -33,8 +50,9 @@ }, "containerEnv": { "DISPLAY": "dummy", - "UV_PROJECT_ENVIRONMENT": "/home/vscode/.venv" + "UV_PROJECT_ENVIRONMENT": "${containerWorkspaceFolder}/.venv" }, + "updateContentCommand": "sudo chown -R vscode /home/${remoteUser}/.cache ${containerWorkspaceFolder}/.venv /home/${remoteUser}/.ssh", "postCreateCommand": "uv sync --frozen", "postStartCommand": "uv run pre-commit install", "remoteUser": "vscode" diff --git a/.vscode/settings.json b/.vscode/settings.json index f7e8fdb..2e2a9c5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,7 +6,7 @@ "notebook.source.organizeImports": "explicit" }, "notebook.formatOnSave.enabled": true, - "python.defaultInterpreterPath": "/home/vscode/.venv/bin/python", + "python.defaultInterpreterPath": ".venv/bin/python", "python.languageServer": "None", "python.testing.autoTestDiscoverOnSaveEnabled": false, "python.testing.pytestEnabled": true, @@ -14,8 +14,8 @@ "tests" ], "python.testing.unittestEnabled": false, - "sqlfluff.config": "${workspaceFolder}/.sqlfluff", - "sqlfluff.executablePath": "/home/vscode/.venv/bin/sqlfluff", + "sqlfluff.config": ".sqlfluff", + "sqlfluff.executablePath": ".venv/bin/sqlfluff", "sqlfluff.format.enabled": true, "sqlfluff.linter.run": "onType", "terminal.integrated.defaultProfile.linux": "zsh", diff --git a/docs/configurations/ruff.md b/docs/configurations/ruff.md index a571980..8a74770 100644 --- a/docs/configurations/ruff.md +++ b/docs/configurations/ruff.md @@ -20,7 +20,7 @@ The Ruff formatter is an extremely fast Python code formatter designed as a drop They are set as default in this repository. === "ruff.toml" - ```{.toml hl_lines=42-57} + ```{.toml hl_lines=42-58 81-83} # Exclude a variety of commonly ignored directories. exclude = [ ".bzr", @@ -73,6 +73,7 @@ The Ruff formatter is an extremely fast Python code formatter designed as a drop "E117", "ISC001", "ISC002", + "PLC0415", "Q000", "Q001", "Q002", @@ -99,11 +100,15 @@ The Ruff formatter is an extremely fast Python code formatter designed as a drop # Like Black, automatically detect the appropriate line ending. line-ending = "auto" + + [lint.per-file-ignores] + # Ignore all directories named `tests`. + "tests/**" = ["INP001", "S101"] ``` === "pyproject.toml" - ```{.toml hl_lines=43-58} + ```{.toml hl_lines=43-59 82-84} [tool.ruff] # Exclude a variety of commonly ignored directories. exclude = [ @@ -139,8 +144,8 @@ The Ruff formatter is an extremely fast Python code formatter designed as a drop line-length = 88 indent-width = 4 - # Assume Python 3.12 - target-version = "py312" + # Assume Python 3.14 + target-version = "py314" [tool.ruff.lint] # Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. @@ -157,6 +162,7 @@ The Ruff formatter is an extremely fast Python code formatter designed as a drop "E117", "ISC001", "ISC002", + "PLC0415", "Q000", "Q001", "Q002", @@ -183,13 +189,17 @@ The Ruff formatter is an extremely fast Python code formatter designed as a drop # Like Black, automatically detect the appropriate line ending. line-ending = "auto" + + [tool.ruff.lint.per-file-ignores] + # Ignore all directories named `tests`. + "tests/**" = ["INP001", "S101"] ``` ## extensions.json The following settings are required for automatic formatting on VSCode. ```{.json title=".vscode/extensions.json" } { - "python.defaultInterpreterPath": "/home/vscode/.venv/bin/python", + "python.defaultInterpreterPath": ".venv/bin/python", "[python]": { "editor.codeActionsOnSave": { "source.fixAll": "explicit", diff --git a/docs/configurations/uv.md b/docs/configurations/uv.md index 88cf336..9d7b3f6 100644 --- a/docs/configurations/uv.md +++ b/docs/configurations/uv.md @@ -6,45 +6,78 @@ ## Virtual Environment Set the `UV_PROJECT_ENVIRONMENT` not to create a virtual environment in the project directory. -```{.dockerfile title=".devcontainer/Dockerfile" hl_lines="34"} +```json title=".devcontainer/devcontainer.json" hl_lines="10-24 53 55" { "name": "uv", - "build": { - "context": "..", - "dockerfile": "Dockerfile", - "args": { - "UV_VERSION": "0.5.11", - "DEBIAN_VERSION": "bookworm" + "dockerComposeFile": "../.devcontainer/docker-compose.yml", + "service": "vscode", + "runServices": [ + "vscode" + ], + "workspaceFolder": "/workspace", + "mounts": [ + { + "source": "cache-${devcontainerId}", + "target": "/home/${remoteUser}/.cache", + "type": "volume" + }, + { + "source": "venv-${devcontainerId}", + "target": "${containerWorkspaceFolder}/.venv", + "type": "volume" + }, + { + "source": "${localEnv:HOME}/.ssh", + "target": "/home/${remoteUser}/.ssh", + "type": "bind" } - }, + ], "features": { "ghcr.io/dhoeric/features/hadolint:1": {} }, "customizations": { "vscode": { "extensions": [ + "astral-sh.ty", "charliermarsh.ruff", + "dorzey.vscode-sqlfluff", "exiasr.hadolint", "kevinrose.vsc-python-indent", "mosapride.zenkaku", "ms-azuretools.vscode-docker", "ms-python.python", + "ms-python.vscode-pylance", + "ms-toolsai.jupyter", "njpwerner.autodocstring", "redhat.vscode-yaml", "shardulm94.trailing-spaces", - "tamasfe.even-better-toml" + "streetsidesoftware.code-spell-checker", + "tamasfe.even-better-toml", + "yzhang.markdown-all-in-one" ] } }, "containerEnv": { "DISPLAY": "dummy", - "PYTHONUNBUFFERED": "True", - "UV_LINK_MODE": "copy", - "UV_PROJECT_ENVIRONMENT": "/home/vscode/.venv" + "UV_PROJECT_ENVIRONMENT": "${containerWorkspaceFolder}/.venv" }, + "updateContentCommand": "sudo chown -R vscode ${containerWorkspaceFolder}/.venv /home/${remoteUser}/.ssh", "postCreateCommand": "uv sync --frozen", "postStartCommand": "uv run pre-commit install", "remoteUser": "vscode" } - ``` + +### Key Configuration Details + +**Mounts Section:** +- The `.venv` directory is stored in a Docker named volume (`venv-${devcontainerId}`) for better performance and isolation +- SSH keys from the host (`${localEnv:HOME}/.ssh`) are bind-mounted to enable git operations with SSH authentication + +**Environment Variables:** +- `UV_PROJECT_ENVIRONMENT` is set to `${containerWorkspaceFolder}/.venv` to ensure uv uses the mounted volume + +**Update Content Command:** +- `updateContentCommand` sets proper ownership of `.venv` and `.ssh` directories to the `vscode` user after container updates + +This configuration eliminates the need for volume definitions in `docker-compose.yml`, as volumes are managed directly through the devcontainer `mounts` section. diff --git a/docs/usecases/jupyter.md b/docs/usecases/jupyter.md index bfc3f58..b569cd3 100644 --- a/docs/usecases/jupyter.md +++ b/docs/usecases/jupyter.md @@ -56,7 +56,7 @@ git switch jupyter "notebook.source.organizeImports": "explicit" }, "notebook.formatOnSave.enabled": true, - "python.defaultInterpreterPath": "/home/vscode/.venv/bin/python", + "python.defaultInterpreterPath": ".venv/bin/python", "[python]": { "editor.codeActionsOnSave": { "source.fixAll": "explicit",