container-superposition 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +843 -0
- package/dist/scripts/init.d.ts +3 -0
- package/dist/scripts/init.d.ts.map +1 -0
- package/dist/scripts/init.js +1190 -0
- package/dist/scripts/init.js.map +1 -0
- package/dist/scripts/migrate-to-manifests.d.ts +12 -0
- package/dist/scripts/migrate-to-manifests.d.ts.map +1 -0
- package/dist/scripts/migrate-to-manifests.js +230 -0
- package/dist/scripts/migrate-to-manifests.js.map +1 -0
- package/dist/tool/questionnaire/composer.d.ts +6 -0
- package/dist/tool/questionnaire/composer.d.ts.map +1 -0
- package/dist/tool/questionnaire/composer.js +1232 -0
- package/dist/tool/questionnaire/composer.js.map +1 -0
- package/dist/tool/readme/markdown-parser.d.ts +30 -0
- package/dist/tool/readme/markdown-parser.d.ts.map +1 -0
- package/dist/tool/readme/markdown-parser.js +139 -0
- package/dist/tool/readme/markdown-parser.js.map +1 -0
- package/dist/tool/readme/readme-generator.d.ts +9 -0
- package/dist/tool/readme/readme-generator.d.ts.map +1 -0
- package/dist/tool/readme/readme-generator.js +422 -0
- package/dist/tool/readme/readme-generator.js.map +1 -0
- package/dist/tool/schema/custom-loader.d.ts +17 -0
- package/dist/tool/schema/custom-loader.d.ts.map +1 -0
- package/dist/tool/schema/custom-loader.js +149 -0
- package/dist/tool/schema/custom-loader.js.map +1 -0
- package/dist/tool/schema/overlay-loader.d.ts +47 -0
- package/dist/tool/schema/overlay-loader.d.ts.map +1 -0
- package/dist/tool/schema/overlay-loader.js +252 -0
- package/dist/tool/schema/overlay-loader.js.map +1 -0
- package/dist/tool/schema/types.d.ts +212 -0
- package/dist/tool/schema/types.d.ts.map +1 -0
- package/dist/tool/schema/types.js +5 -0
- package/dist/tool/schema/types.js.map +1 -0
- package/docs/README.md +308 -0
- package/docs/architecture.md +233 -0
- package/docs/creating-overlays.md +549 -0
- package/docs/custom-patches.md +540 -0
- package/docs/dependencies.md +279 -0
- package/docs/examples/custom-patches-example.md +85 -0
- package/docs/examples.md +576 -0
- package/docs/messaging-comparison.md +265 -0
- package/docs/messaging-quick-start.md +385 -0
- package/docs/observability-workflow.md +537 -0
- package/docs/overlay-manifest-refactoring.md +214 -0
- package/docs/overlay-metadata-archive.md +54 -0
- package/docs/overlays.md +523 -0
- package/docs/presets-architecture.md +498 -0
- package/docs/presets.md +366 -0
- package/docs/publishing.md +476 -0
- package/docs/quick-reference.md +326 -0
- package/docs/ux.md +170 -0
- package/features/README.md +85 -0
- package/features/cross-distro-packages/README.md +146 -0
- package/features/cross-distro-packages/devcontainer-feature.json +20 -0
- package/features/cross-distro-packages/install.sh +58 -0
- package/features/local-secrets-manager/devcontainer-feature.json +18 -0
- package/features/local-secrets-manager/install.sh +127 -0
- package/features/project-scaffolder/devcontainer-feature.json +24 -0
- package/features/project-scaffolder/install.sh +100 -0
- package/features/team-conventions/devcontainer-feature.json +24 -0
- package/features/team-conventions/install.sh +93 -0
- package/overlays/.registry/README.md +14 -0
- package/overlays/.registry/base-images.yml +26 -0
- package/overlays/.registry/base-templates.yml +7 -0
- package/overlays/README.md +155 -0
- package/overlays/alertmanager/.env.example +5 -0
- package/overlays/alertmanager/README.md +465 -0
- package/overlays/alertmanager/alert-rules.yml +56 -0
- package/overlays/alertmanager/alertmanager.yml +42 -0
- package/overlays/alertmanager/devcontainer.patch.json +12 -0
- package/overlays/alertmanager/docker-compose.yml +20 -0
- package/overlays/alertmanager/overlay.yml +17 -0
- package/overlays/alertmanager/setup.sh +53 -0
- package/overlays/alertmanager/verify.sh +31 -0
- package/overlays/aws-cli/README.md +473 -0
- package/overlays/aws-cli/devcontainer.patch.json +13 -0
- package/overlays/aws-cli/overlay.yml +13 -0
- package/overlays/azure-cli/README.md +551 -0
- package/overlays/azure-cli/devcontainer.patch.json +8 -0
- package/overlays/azure-cli/overlay.yml +13 -0
- package/overlays/bun/README.md +312 -0
- package/overlays/bun/devcontainer.patch.json +41 -0
- package/overlays/bun/overlay.yml +16 -0
- package/overlays/bun/setup.sh +79 -0
- package/overlays/bun/verify.sh +30 -0
- package/overlays/codex/README.md +128 -0
- package/overlays/codex/devcontainer.patch.json +3 -0
- package/overlays/codex/overlay.yml +14 -0
- package/overlays/codex/setup.sh +24 -0
- package/overlays/codex/verify.sh +30 -0
- package/overlays/commitlint/README.md +333 -0
- package/overlays/commitlint/devcontainer.patch.json +8 -0
- package/overlays/commitlint/overlay.yml +16 -0
- package/overlays/commitlint/setup.sh +234 -0
- package/overlays/direnv/README.md +504 -0
- package/overlays/direnv/devcontainer.patch.json +6 -0
- package/overlays/direnv/overlay.yml +13 -0
- package/overlays/direnv/setup.sh +139 -0
- package/overlays/docker-in-docker/README.md +534 -0
- package/overlays/docker-in-docker/devcontainer.patch.json +10 -0
- package/overlays/docker-in-docker/overlay.yml +13 -0
- package/overlays/docker-sock/README.md +256 -0
- package/overlays/docker-sock/devcontainer.patch.json +9 -0
- package/overlays/docker-sock/docker-compose.yml +8 -0
- package/overlays/docker-sock/overlay.yml +13 -0
- package/overlays/dotnet/README.md +147 -0
- package/overlays/dotnet/devcontainer.patch.json +51 -0
- package/overlays/dotnet/global-tools.txt +24 -0
- package/overlays/dotnet/overlay.yml +13 -0
- package/overlays/dotnet/setup.sh +51 -0
- package/overlays/dotnet/verify.sh +26 -0
- package/overlays/gcloud/README.md +269 -0
- package/overlays/gcloud/devcontainer.patch.json +14 -0
- package/overlays/gcloud/overlay.yml +14 -0
- package/overlays/gcloud/verify.sh +52 -0
- package/overlays/git-helpers/README.md +168 -0
- package/overlays/git-helpers/devcontainer.patch.json +33 -0
- package/overlays/git-helpers/overlay.yml +15 -0
- package/overlays/git-helpers/setup.sh +91 -0
- package/overlays/go/README.md +293 -0
- package/overlays/go/devcontainer.patch.json +43 -0
- package/overlays/go/overlay.yml +15 -0
- package/overlays/go/setup.sh +33 -0
- package/overlays/go/verify.sh +40 -0
- package/overlays/grafana/.env.example +9 -0
- package/overlays/grafana/README.md +462 -0
- package/overlays/grafana/dashboard-provider.yml +11 -0
- package/overlays/grafana/dashboards/observability-overview.json +263 -0
- package/overlays/grafana/devcontainer.patch.json +12 -0
- package/overlays/grafana/docker-compose.yml +27 -0
- package/overlays/grafana/grafana-datasources.yml +57 -0
- package/overlays/grafana/overlay.yml +21 -0
- package/overlays/grafana/verify.sh +34 -0
- package/overlays/jaeger/.env.example +7 -0
- package/overlays/jaeger/README.md +867 -0
- package/overlays/jaeger/devcontainer.patch.json +12 -0
- package/overlays/jaeger/docker-compose.yml +17 -0
- package/overlays/jaeger/overlay.yml +19 -0
- package/overlays/java/README.md +267 -0
- package/overlays/java/devcontainer.patch.json +44 -0
- package/overlays/java/overlay.yml +16 -0
- package/overlays/java/setup.sh +41 -0
- package/overlays/java/verify.sh +42 -0
- package/overlays/just/README.md +443 -0
- package/overlays/just/devcontainer.patch.json +3 -0
- package/overlays/just/overlay.yml +13 -0
- package/overlays/just/setup.sh +182 -0
- package/overlays/kubectl-helm/README.md +660 -0
- package/overlays/kubectl-helm/devcontainer.patch.json +10 -0
- package/overlays/kubectl-helm/overlay.yml +13 -0
- package/overlays/loki/.env.example +5 -0
- package/overlays/loki/README.md +1156 -0
- package/overlays/loki/devcontainer.patch.json +12 -0
- package/overlays/loki/docker-compose.yml +18 -0
- package/overlays/loki/loki-config.yaml +45 -0
- package/overlays/loki/overlay.yml +17 -0
- package/overlays/minio/.env.example +9 -0
- package/overlays/minio/README.md +639 -0
- package/overlays/minio/devcontainer.patch.json +30 -0
- package/overlays/minio/docker-compose.yml +28 -0
- package/overlays/minio/overlay.yml +18 -0
- package/overlays/minio/setup.sh +61 -0
- package/overlays/minio/verify.sh +64 -0
- package/overlays/mkdocs/README.md +309 -0
- package/overlays/mkdocs/devcontainer.patch.json +24 -0
- package/overlays/mkdocs/overlay.yml +15 -0
- package/overlays/modern-cli-tools/README.md +556 -0
- package/overlays/modern-cli-tools/devcontainer.patch.json +3 -0
- package/overlays/modern-cli-tools/overlay.yml +13 -0
- package/overlays/modern-cli-tools/setup.sh +153 -0
- package/overlays/mongodb/.env.example +9 -0
- package/overlays/mongodb/README.md +481 -0
- package/overlays/mongodb/devcontainer.patch.json +32 -0
- package/overlays/mongodb/docker-compose.yml +44 -0
- package/overlays/mongodb/overlay.yml +17 -0
- package/overlays/mongodb/verify.sh +48 -0
- package/overlays/mysql/.env.example +11 -0
- package/overlays/mysql/README.md +542 -0
- package/overlays/mysql/devcontainer.patch.json +34 -0
- package/overlays/mysql/docker-compose.yml +55 -0
- package/overlays/mysql/overlay.yml +16 -0
- package/overlays/mysql/verify.sh +48 -0
- package/overlays/nats/.env.example +5 -0
- package/overlays/nats/README.md +762 -0
- package/overlays/nats/devcontainer.patch.json +24 -0
- package/overlays/nats/docker-compose.yml +31 -0
- package/overlays/nats/overlay.yml +18 -0
- package/overlays/nats/verify.sh +50 -0
- package/overlays/ngrok/README.md +503 -0
- package/overlays/ngrok/devcontainer.patch.json +3 -0
- package/overlays/ngrok/overlay.yml +14 -0
- package/overlays/ngrok/setup.sh +125 -0
- package/overlays/nodejs/README.md +192 -0
- package/overlays/nodejs/devcontainer.patch.json +49 -0
- package/overlays/nodejs/global-packages.txt +16 -0
- package/overlays/nodejs/overlay.yml +14 -0
- package/overlays/nodejs/setup.sh +46 -0
- package/overlays/nodejs/verify.sh +32 -0
- package/overlays/otel-collector/.env.example +9 -0
- package/overlays/otel-collector/README.md +1257 -0
- package/overlays/otel-collector/devcontainer.patch.json +28 -0
- package/overlays/otel-collector/docker-compose.yml +22 -0
- package/overlays/otel-collector/otel-collector-config.yaml +68 -0
- package/overlays/otel-collector/overlay.yml +21 -0
- package/overlays/otel-collector/setup.sh +49 -0
- package/overlays/otel-demo-nodejs/.env.example +2 -0
- package/overlays/otel-demo-nodejs/Dockerfile-otel-demo-nodejs +17 -0
- package/overlays/otel-demo-nodejs/README.md +409 -0
- package/overlays/otel-demo-nodejs/devcontainer.patch.json +12 -0
- package/overlays/otel-demo-nodejs/docker-compose.yml +19 -0
- package/overlays/otel-demo-nodejs/overlay.yml +23 -0
- package/overlays/otel-demo-nodejs/package-otel-demo-nodejs.json +20 -0
- package/overlays/otel-demo-nodejs/server-otel-demo-nodejs.js +259 -0
- package/overlays/otel-demo-nodejs/tracing-otel-demo-nodejs.js +57 -0
- package/overlays/otel-demo-nodejs/verify.sh +31 -0
- package/overlays/otel-demo-python/.env.example +2 -0
- package/overlays/otel-demo-python/Dockerfile-otel-demo-python +16 -0
- package/overlays/otel-demo-python/README.md +82 -0
- package/overlays/otel-demo-python/app-otel-demo-python.py +208 -0
- package/overlays/otel-demo-python/devcontainer.patch.json +12 -0
- package/overlays/otel-demo-python/docker-compose.yml +19 -0
- package/overlays/otel-demo-python/overlay.yml +23 -0
- package/overlays/otel-demo-python/requirements-otel-demo-python.txt +4 -0
- package/overlays/otel-demo-python/verify.sh +31 -0
- package/overlays/playwright/README.md +629 -0
- package/overlays/playwright/devcontainer.patch.json +9 -0
- package/overlays/playwright/overlay.yml +13 -0
- package/overlays/postgres/.env.example +6 -0
- package/overlays/postgres/README.md +602 -0
- package/overlays/postgres/devcontainer.patch.json +21 -0
- package/overlays/postgres/docker-compose.yml +22 -0
- package/overlays/postgres/overlay.yml +15 -0
- package/overlays/postgres/verify.sh +45 -0
- package/overlays/powershell/README.md +314 -0
- package/overlays/powershell/devcontainer.patch.json +22 -0
- package/overlays/powershell/overlay.yml +13 -0
- package/overlays/powershell/setup.sh +29 -0
- package/overlays/powershell/verify.sh +38 -0
- package/overlays/pre-commit/README.md +263 -0
- package/overlays/pre-commit/devcontainer.patch.json +9 -0
- package/overlays/pre-commit/overlay.yml +16 -0
- package/overlays/pre-commit/setup.sh +129 -0
- package/overlays/presets/docs-site.yml +118 -0
- package/overlays/presets/fullstack.yml +181 -0
- package/overlays/presets/microservice.yml +118 -0
- package/overlays/presets/web-api.yml +109 -0
- package/overlays/prometheus/.env.example +5 -0
- package/overlays/prometheus/README.md +1246 -0
- package/overlays/prometheus/devcontainer.patch.json +12 -0
- package/overlays/prometheus/docker-compose.yml +22 -0
- package/overlays/prometheus/overlay.yml +17 -0
- package/overlays/prometheus/prometheus.yml +12 -0
- package/overlays/prometheus/verify.sh +34 -0
- package/overlays/promtail/.env.example +2 -0
- package/overlays/promtail/README.md +357 -0
- package/overlays/promtail/devcontainer.patch.json +5 -0
- package/overlays/promtail/docker-compose.yml +16 -0
- package/overlays/promtail/overlay.yml +17 -0
- package/overlays/promtail/promtail-config.yaml +60 -0
- package/overlays/promtail/verify.sh +31 -0
- package/overlays/pulumi/README.md +472 -0
- package/overlays/pulumi/devcontainer.patch.json +13 -0
- package/overlays/pulumi/overlay.yml +14 -0
- package/overlays/pulumi/verify.sh +31 -0
- package/overlays/python/README.md +919 -0
- package/overlays/python/devcontainer.patch.json +41 -0
- package/overlays/python/overlay.yml +12 -0
- package/overlays/python/requirements-overlay.txt +13 -0
- package/overlays/python/setup.sh +47 -0
- package/overlays/python/verify.sh +32 -0
- package/overlays/rabbitmq/.env.example +7 -0
- package/overlays/rabbitmq/README.md +680 -0
- package/overlays/rabbitmq/devcontainer.patch.json +28 -0
- package/overlays/rabbitmq/docker-compose.yml +30 -0
- package/overlays/rabbitmq/overlay.yml +18 -0
- package/overlays/rabbitmq/verify.sh +41 -0
- package/overlays/redis/.env.example +4 -0
- package/overlays/redis/README.md +776 -0
- package/overlays/redis/devcontainer.patch.json +21 -0
- package/overlays/redis/docker-compose.yml +21 -0
- package/overlays/redis/overlay.yml +15 -0
- package/overlays/redis/verify.sh +41 -0
- package/overlays/redpanda/.env.example +10 -0
- package/overlays/redpanda/README.md +703 -0
- package/overlays/redpanda/devcontainer.patch.json +37 -0
- package/overlays/redpanda/docker-compose.yml +67 -0
- package/overlays/redpanda/overlay.yml +21 -0
- package/overlays/redpanda/verify.sh +48 -0
- package/overlays/rust/README.md +299 -0
- package/overlays/rust/devcontainer.patch.json +39 -0
- package/overlays/rust/overlay.yml +15 -0
- package/overlays/rust/setup.sh +36 -0
- package/overlays/rust/verify.sh +51 -0
- package/overlays/sqlite/README.md +584 -0
- package/overlays/sqlite/devcontainer.patch.json +14 -0
- package/overlays/sqlite/overlay.yml +15 -0
- package/overlays/sqlite/setup.sh +27 -0
- package/overlays/sqlite/verify.sh +43 -0
- package/overlays/sqlserver/.env.example +6 -0
- package/overlays/sqlserver/README.md +592 -0
- package/overlays/sqlserver/devcontainer.patch.json +22 -0
- package/overlays/sqlserver/docker-compose.yml +32 -0
- package/overlays/sqlserver/overlay.yml +17 -0
- package/overlays/sqlserver/verify.sh +30 -0
- package/overlays/tempo/.env.example +5 -0
- package/overlays/tempo/README.md +273 -0
- package/overlays/tempo/devcontainer.patch.json +12 -0
- package/overlays/tempo/docker-compose.yml +20 -0
- package/overlays/tempo/overlay.yml +20 -0
- package/overlays/tempo/tempo-config.yaml +32 -0
- package/overlays/tempo/verify.sh +31 -0
- package/overlays/terraform/README.md +389 -0
- package/overlays/terraform/devcontainer.patch.json +15 -0
- package/overlays/terraform/overlay.yml +14 -0
- package/overlays/terraform/verify.sh +63 -0
- package/package.json +74 -0
- package/templates/README.md +285 -0
- package/templates/compose/.devcontainer/devcontainer.json +46 -0
- package/templates/compose/.devcontainer/docker-compose.yml +12 -0
- package/templates/compose/README.md +20 -0
- package/templates/plain/.devcontainer/devcontainer.json +35 -0
- package/templates/plain/README.md +21 -0
- package/tool/README.md +281 -0
- package/tool/schema/base-images.schema.json +43 -0
- package/tool/schema/base-templates.schema.json +34 -0
- package/tool/schema/config.schema.json +71 -0
- package/tool/schema/overlay-manifest.schema.json +86 -0
|
@@ -0,0 +1,919 @@
|
|
|
1
|
+
# Python Overlay
|
|
2
|
+
|
|
3
|
+
Adds Python 3.12 with development tools, linting, and formatting.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Python 3.12** with pip, setuptools, and wheel
|
|
8
|
+
- **VS Code Extensions:**
|
|
9
|
+
- Python (ms-python.python)
|
|
10
|
+
- Pylance (ms-python.vscode-pylance)
|
|
11
|
+
- Black Formatter (ms-python.black-formatter)
|
|
12
|
+
- Ruff (charliermarsh.ruff)
|
|
13
|
+
- **Automatic dependency installation** from:
|
|
14
|
+
- `requirements.txt`
|
|
15
|
+
- `requirements-dev.txt`
|
|
16
|
+
- `pyproject.toml` (editable install)
|
|
17
|
+
- `setup.py` (legacy support)
|
|
18
|
+
- **Pre-configured settings:**
|
|
19
|
+
- Black as default formatter
|
|
20
|
+
- Format on save enabled
|
|
21
|
+
- Auto-organize imports
|
|
22
|
+
- PYTHONPATH set to workspace root
|
|
23
|
+
|
|
24
|
+
## Virtual Environment Philosophy
|
|
25
|
+
|
|
26
|
+
This overlay uses **user-level pip installations** (`pip install --user`) instead of virtual environments inside the container for these reasons:
|
|
27
|
+
|
|
28
|
+
### Why Not venv in Container?
|
|
29
|
+
|
|
30
|
+
1. **Container IS the environment** - The devcontainer already provides isolation
|
|
31
|
+
2. **Simpler workflow** - No need to activate/deactivate venv
|
|
32
|
+
3. **Better VS Code integration** - Python extension finds packages automatically
|
|
33
|
+
4. **Fewer moving parts** - Less to go wrong
|
|
34
|
+
|
|
35
|
+
### When to Use venv
|
|
36
|
+
|
|
37
|
+
Use a virtual environment if you need:
|
|
38
|
+
|
|
39
|
+
- Multiple Python versions in the same container
|
|
40
|
+
- Strict dependency isolation for testing
|
|
41
|
+
- Exact production parity (though containers already provide this)
|
|
42
|
+
|
|
43
|
+
To create a venv manually:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
python -m venv .venv
|
|
47
|
+
source .venv/bin/activate
|
|
48
|
+
pip install -r requirements.txt
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Then update VS Code settings:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python"
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Automatic Setup
|
|
60
|
+
|
|
61
|
+
The overlay automatically runs on container creation:
|
|
62
|
+
|
|
63
|
+
1. ✅ Installs overlay packages from `.devcontainer/requirements-overlay.txt`
|
|
64
|
+
2. ✅ Checks for `requirements.txt` → installs with pip
|
|
65
|
+
3. ✅ Checks for `requirements-dev.txt` → installs dev dependencies
|
|
66
|
+
4. ✅ Checks for `pyproject.toml` → installs project in editable mode
|
|
67
|
+
5. ✅ Checks for `setup.py` → installs legacy projects
|
|
68
|
+
6. ✅ Upgrades pip, setuptools, and wheel to latest
|
|
69
|
+
|
|
70
|
+
## Customizing Overlay Packages
|
|
71
|
+
|
|
72
|
+
The overlay includes a `requirements-overlay.txt` file in `.devcontainer/` that you can customize:
|
|
73
|
+
|
|
74
|
+
**`.devcontainer/requirements-overlay.txt`:**
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
# Python overlay default packages
|
|
78
|
+
# Customize this file to add or remove packages for your project
|
|
79
|
+
|
|
80
|
+
# Add your project dependencies here
|
|
81
|
+
# Example:
|
|
82
|
+
requests>=2.31.0
|
|
83
|
+
pytest>=7.4.0
|
|
84
|
+
black>=23.0.0
|
|
85
|
+
jupyter>=1.0.0
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**When to use:**
|
|
89
|
+
|
|
90
|
+
- Add common development tools you always want
|
|
91
|
+
- Install packages needed across all environments
|
|
92
|
+
- Pre-install heavy dependencies (pandas, numpy, etc.)
|
|
93
|
+
|
|
94
|
+
**Rebuild container** after editing to install new packages.
|
|
95
|
+
|
|
96
|
+
## Project Structures Supported
|
|
97
|
+
|
|
98
|
+
### Modern Python (pyproject.toml)
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
my-project/
|
|
102
|
+
├── pyproject.toml
|
|
103
|
+
├── src/
|
|
104
|
+
│ └── mypackage/
|
|
105
|
+
│ └── __init__.py
|
|
106
|
+
└── tests/
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Result:** `pip install --user -e .` (editable install)
|
|
110
|
+
|
|
111
|
+
### Classic Python (requirements.txt)
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
my-project/
|
|
115
|
+
├── requirements.txt
|
|
116
|
+
├── requirements-dev.txt (optional)
|
|
117
|
+
└── src/
|
|
118
|
+
└── main.py
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Result:** Dependencies installed, ready to run
|
|
122
|
+
|
|
123
|
+
### Package with setup.py
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
my-project/
|
|
127
|
+
├── setup.py
|
|
128
|
+
├── README.md
|
|
129
|
+
└── mypackage/
|
|
130
|
+
└── __init__.py
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Result:** Package installed in editable mode
|
|
134
|
+
|
|
135
|
+
## Common Workflows
|
|
136
|
+
|
|
137
|
+
### Data Science / Notebooks
|
|
138
|
+
|
|
139
|
+
Add to `requirements.txt`:
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
jupyter
|
|
143
|
+
pandas
|
|
144
|
+
numpy
|
|
145
|
+
matplotlib
|
|
146
|
+
scikit-learn
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Web Development (FastAPI)
|
|
150
|
+
|
|
151
|
+
Add to `requirements.txt`:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
fastapi
|
|
155
|
+
uvicorn[standard]
|
|
156
|
+
pydantic
|
|
157
|
+
sqlalchemy
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### CLI Tools
|
|
161
|
+
|
|
162
|
+
Use `pyproject.toml`:
|
|
163
|
+
|
|
164
|
+
```toml
|
|
165
|
+
[project]
|
|
166
|
+
name = "mytool"
|
|
167
|
+
version = "0.1.0"
|
|
168
|
+
dependencies = ["click", "requests"]
|
|
169
|
+
|
|
170
|
+
[project.scripts]
|
|
171
|
+
mytool = "mytool.cli:main"
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Best Practices
|
|
175
|
+
|
|
176
|
+
1. **Pin versions** in requirements.txt for reproducibility
|
|
177
|
+
2. **Separate dev dependencies** in requirements-dev.txt
|
|
178
|
+
3. **Use pyproject.toml** for modern Python projects
|
|
179
|
+
4. **Add `.gitignore`** for `__pycache__`, `.pytest_cache`, etc.
|
|
180
|
+
|
|
181
|
+
## Troubleshooting
|
|
182
|
+
|
|
183
|
+
### "Module not found" after adding dependency
|
|
184
|
+
|
|
185
|
+
Container caches are not refreshed. Rebuild the container:
|
|
186
|
+
|
|
187
|
+
- **VS Code:** `Cmd+Shift+P` → "Dev Containers: Rebuild Container"
|
|
188
|
+
|
|
189
|
+
### Need different Python version?
|
|
190
|
+
|
|
191
|
+
Update `devcontainer.patch.json`:
|
|
192
|
+
|
|
193
|
+
```json
|
|
194
|
+
{
|
|
195
|
+
"features": {
|
|
196
|
+
"ghcr.io/devcontainers/features/python:1": {
|
|
197
|
+
"version": "3.11" // or "3.10", "3.13", etc.
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Want to use venv anyway?
|
|
204
|
+
|
|
205
|
+
Add to your project's `.devcontainer/devcontainer.json`:
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
{
|
|
209
|
+
"postCreateCommand": "python -m venv .venv && .venv/bin/pip install -r requirements.txt",
|
|
210
|
+
"customizations": {
|
|
211
|
+
"vscode": {
|
|
212
|
+
"settings": {
|
|
213
|
+
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python"
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Common Python Commands
|
|
221
|
+
|
|
222
|
+
### Package Management
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# Install package
|
|
226
|
+
pip install requests
|
|
227
|
+
|
|
228
|
+
# Install with version
|
|
229
|
+
pip install requests==2.31.0
|
|
230
|
+
|
|
231
|
+
# Install from requirements.txt
|
|
232
|
+
pip install -r requirements.txt
|
|
233
|
+
|
|
234
|
+
# Install in editable mode
|
|
235
|
+
pip install -e .
|
|
236
|
+
|
|
237
|
+
# Upgrade package
|
|
238
|
+
pip install --upgrade requests
|
|
239
|
+
|
|
240
|
+
# Uninstall package
|
|
241
|
+
pip uninstall requests
|
|
242
|
+
|
|
243
|
+
# List installed packages
|
|
244
|
+
pip list
|
|
245
|
+
|
|
246
|
+
# Show package info
|
|
247
|
+
pip show requests
|
|
248
|
+
|
|
249
|
+
# Check for updates
|
|
250
|
+
pip list --outdated
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Working with Dependencies
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
# Generate requirements.txt
|
|
257
|
+
pip freeze > requirements.txt
|
|
258
|
+
|
|
259
|
+
# Generate minimal requirements (only direct deps)
|
|
260
|
+
pip-compile requirements.in
|
|
261
|
+
|
|
262
|
+
# Install dev dependencies
|
|
263
|
+
pip install -r requirements-dev.txt
|
|
264
|
+
|
|
265
|
+
# Install with extras
|
|
266
|
+
pip install requests[security]
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Python Environment
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
# Check Python version
|
|
273
|
+
python --version
|
|
274
|
+
|
|
275
|
+
# Run Python script
|
|
276
|
+
python script.py
|
|
277
|
+
|
|
278
|
+
# Run module
|
|
279
|
+
python -m http.server 8000
|
|
280
|
+
|
|
281
|
+
# Interactive shell
|
|
282
|
+
python
|
|
283
|
+
ipython # if installed
|
|
284
|
+
|
|
285
|
+
# Check where Python is
|
|
286
|
+
which python
|
|
287
|
+
|
|
288
|
+
# Show Python path
|
|
289
|
+
python -c "import sys; print('\n'.join(sys.path))"
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Testing Setup
|
|
293
|
+
|
|
294
|
+
### pytest
|
|
295
|
+
|
|
296
|
+
Add to `requirements-dev.txt`:
|
|
297
|
+
|
|
298
|
+
```
|
|
299
|
+
pytest>=7.4.0
|
|
300
|
+
pytest-cov>=4.1.0
|
|
301
|
+
pytest-asyncio>=0.21.0
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
**Run tests:**
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
# Run all tests
|
|
308
|
+
pytest
|
|
309
|
+
|
|
310
|
+
# Run specific file
|
|
311
|
+
pytest tests/test_auth.py
|
|
312
|
+
|
|
313
|
+
# Run specific test
|
|
314
|
+
pytest tests/test_auth.py::test_login
|
|
315
|
+
|
|
316
|
+
# Run with coverage
|
|
317
|
+
pytest --cov=src --cov-report=html
|
|
318
|
+
|
|
319
|
+
# Run with verbose output
|
|
320
|
+
pytest -v
|
|
321
|
+
|
|
322
|
+
# Run in parallel
|
|
323
|
+
pytest -n auto
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
**Example test:**
|
|
327
|
+
|
|
328
|
+
```python
|
|
329
|
+
# tests/test_math.py
|
|
330
|
+
def test_addition():
|
|
331
|
+
assert 1 + 1 == 2
|
|
332
|
+
|
|
333
|
+
def test_subtraction():
|
|
334
|
+
result = 10 - 5
|
|
335
|
+
assert result == 5
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### unittest (Standard Library)
|
|
339
|
+
|
|
340
|
+
```python
|
|
341
|
+
# tests/test_math.py
|
|
342
|
+
import unittest
|
|
343
|
+
|
|
344
|
+
class TestMath(unittest.TestCase):
|
|
345
|
+
def test_addition(self):
|
|
346
|
+
self.assertEqual(1 + 1, 2)
|
|
347
|
+
|
|
348
|
+
def test_subtraction(self):
|
|
349
|
+
result = 10 - 5
|
|
350
|
+
self.assertEqual(result, 5)
|
|
351
|
+
|
|
352
|
+
if __name__ == '__main__':
|
|
353
|
+
unittest.main()
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
**Run tests:**
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
# Discover and run all tests
|
|
360
|
+
python -m unittest discover
|
|
361
|
+
|
|
362
|
+
# Run specific test file
|
|
363
|
+
python -m unittest tests.test_math
|
|
364
|
+
|
|
365
|
+
# Run specific test
|
|
366
|
+
python -m unittest tests.test_math.TestMath.test_addition
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## Code Quality Tools
|
|
370
|
+
|
|
371
|
+
### Black (Formatter)
|
|
372
|
+
|
|
373
|
+
Pre-configured in this overlay.
|
|
374
|
+
|
|
375
|
+
```bash
|
|
376
|
+
# Format file
|
|
377
|
+
black script.py
|
|
378
|
+
|
|
379
|
+
# Format directory
|
|
380
|
+
black src/
|
|
381
|
+
|
|
382
|
+
# Check without modifying
|
|
383
|
+
black --check src/
|
|
384
|
+
|
|
385
|
+
# Show what would change
|
|
386
|
+
black --diff src/
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
**Configuration (.pyproject.toml):**
|
|
390
|
+
|
|
391
|
+
```toml
|
|
392
|
+
[tool.black]
|
|
393
|
+
line-length = 100
|
|
394
|
+
target-version = ['py312']
|
|
395
|
+
include = '\.pyi?$'
|
|
396
|
+
extend-exclude = '''
|
|
397
|
+
/(
|
|
398
|
+
# directories
|
|
399
|
+
\.eggs
|
|
400
|
+
| \.git
|
|
401
|
+
| \.venv
|
|
402
|
+
| build
|
|
403
|
+
| dist
|
|
404
|
+
)/
|
|
405
|
+
'''
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### Ruff (Linter)
|
|
409
|
+
|
|
410
|
+
Pre-configured in this overlay.
|
|
411
|
+
|
|
412
|
+
```bash
|
|
413
|
+
# Lint files
|
|
414
|
+
ruff check .
|
|
415
|
+
|
|
416
|
+
# Auto-fix issues
|
|
417
|
+
ruff check --fix .
|
|
418
|
+
|
|
419
|
+
# Show rule explanations
|
|
420
|
+
ruff rule E501
|
|
421
|
+
|
|
422
|
+
# Format code
|
|
423
|
+
ruff format .
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
**Configuration (.pyproject.toml):**
|
|
427
|
+
|
|
428
|
+
```toml
|
|
429
|
+
[tool.ruff]
|
|
430
|
+
line-length = 100
|
|
431
|
+
target-version = "py312"
|
|
432
|
+
|
|
433
|
+
[tool.ruff.lint]
|
|
434
|
+
select = ["E", "F", "I", "N", "W"]
|
|
435
|
+
ignore = ["E501"]
|
|
436
|
+
|
|
437
|
+
[tool.ruff.lint.per-file-ignores]
|
|
438
|
+
"__init__.py" = ["F401"]
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### mypy (Type Checker)
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
# Install
|
|
445
|
+
pip install mypy
|
|
446
|
+
|
|
447
|
+
# Check types
|
|
448
|
+
mypy src/
|
|
449
|
+
|
|
450
|
+
# Check specific file
|
|
451
|
+
mypy script.py
|
|
452
|
+
|
|
453
|
+
# Strict mode
|
|
454
|
+
mypy --strict src/
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
**Configuration (pyproject.toml):**
|
|
458
|
+
|
|
459
|
+
```toml
|
|
460
|
+
[tool.mypy]
|
|
461
|
+
python_version = "3.12"
|
|
462
|
+
warn_return_any = true
|
|
463
|
+
warn_unused_configs = true
|
|
464
|
+
disallow_untyped_defs = true
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
## Common Workflows
|
|
468
|
+
|
|
469
|
+
### Web Development with FastAPI
|
|
470
|
+
|
|
471
|
+
**requirements.txt:**
|
|
472
|
+
|
|
473
|
+
```
|
|
474
|
+
fastapi>=0.104.0
|
|
475
|
+
uvicorn[standard]>=0.24.0
|
|
476
|
+
pydantic>=2.5.0
|
|
477
|
+
sqlalchemy>=2.0.0
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
**main.py:**
|
|
481
|
+
|
|
482
|
+
```python
|
|
483
|
+
from fastapi import FastAPI
|
|
484
|
+
|
|
485
|
+
app = FastAPI()
|
|
486
|
+
|
|
487
|
+
@app.get("/")
|
|
488
|
+
async def root():
|
|
489
|
+
return {"message": "Hello World"}
|
|
490
|
+
|
|
491
|
+
@app.get("/items/{item_id}")
|
|
492
|
+
async def read_item(item_id: int):
|
|
493
|
+
return {"item_id": item_id}
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
**Run:**
|
|
497
|
+
|
|
498
|
+
```bash
|
|
499
|
+
uvicorn main:app --reload
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
### Data Science with Pandas
|
|
503
|
+
|
|
504
|
+
**requirements.txt:**
|
|
505
|
+
|
|
506
|
+
```
|
|
507
|
+
pandas>=2.1.0
|
|
508
|
+
numpy>=1.26.0
|
|
509
|
+
matplotlib>=3.8.0
|
|
510
|
+
jupyter>=1.0.0
|
|
511
|
+
scikit-learn>=1.3.0
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
**Example:**
|
|
515
|
+
|
|
516
|
+
```python
|
|
517
|
+
import pandas as pd
|
|
518
|
+
import matplotlib.pyplot as plt
|
|
519
|
+
|
|
520
|
+
# Read CSV
|
|
521
|
+
df = pd.read_csv('data.csv')
|
|
522
|
+
|
|
523
|
+
# Analyze data
|
|
524
|
+
print(df.describe())
|
|
525
|
+
print(df.head())
|
|
526
|
+
|
|
527
|
+
# Plot
|
|
528
|
+
df.plot(x='date', y='value')
|
|
529
|
+
plt.show()
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
### CLI Tools with Click
|
|
533
|
+
|
|
534
|
+
**requirements.txt:**
|
|
535
|
+
|
|
536
|
+
```
|
|
537
|
+
click>=8.1.0
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
**cli.py:**
|
|
541
|
+
|
|
542
|
+
```python
|
|
543
|
+
import click
|
|
544
|
+
|
|
545
|
+
@click.command()
|
|
546
|
+
@click.option('--name', default='World', help='Name to greet')
|
|
547
|
+
@click.option('--count', default=1, help='Number of greetings')
|
|
548
|
+
def hello(name, count):
|
|
549
|
+
"""Simple program that greets NAME COUNT times."""
|
|
550
|
+
for _ in range(count):
|
|
551
|
+
click.echo(f'Hello {name}!')
|
|
552
|
+
|
|
553
|
+
if __name__ == '__main__':
|
|
554
|
+
hello()
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
**Run:**
|
|
558
|
+
|
|
559
|
+
```bash
|
|
560
|
+
python cli.py --name Alice --count 3
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
### Async Programming
|
|
564
|
+
|
|
565
|
+
```python
|
|
566
|
+
import asyncio
|
|
567
|
+
import aiohttp
|
|
568
|
+
|
|
569
|
+
async def fetch_url(url):
|
|
570
|
+
async with aiohttp.ClientSession() as session:
|
|
571
|
+
async with session.get(url) as response:
|
|
572
|
+
return await response.text()
|
|
573
|
+
|
|
574
|
+
async def main():
|
|
575
|
+
urls = [
|
|
576
|
+
'https://api.example.com/1',
|
|
577
|
+
'https://api.example.com/2',
|
|
578
|
+
'https://api.example.com/3',
|
|
579
|
+
]
|
|
580
|
+
tasks = [fetch_url(url) for url in urls]
|
|
581
|
+
results = await asyncio.gather(*tasks)
|
|
582
|
+
return results
|
|
583
|
+
|
|
584
|
+
if __name__ == '__main__':
|
|
585
|
+
results = asyncio.run(main())
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
## Package Structure Best Practices
|
|
589
|
+
|
|
590
|
+
### Simple Project
|
|
591
|
+
|
|
592
|
+
```
|
|
593
|
+
my-project/
|
|
594
|
+
├── README.md
|
|
595
|
+
├── requirements.txt
|
|
596
|
+
├── requirements-dev.txt
|
|
597
|
+
├── .gitignore
|
|
598
|
+
├── src/
|
|
599
|
+
│ └── main.py
|
|
600
|
+
└── tests/
|
|
601
|
+
└── test_main.py
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
### Package Project
|
|
605
|
+
|
|
606
|
+
```
|
|
607
|
+
my-package/
|
|
608
|
+
├── README.md
|
|
609
|
+
├── pyproject.toml
|
|
610
|
+
├── .gitignore
|
|
611
|
+
├── src/
|
|
612
|
+
│ └── mypackage/
|
|
613
|
+
│ ├── __init__.py
|
|
614
|
+
│ ├── core.py
|
|
615
|
+
│ └── utils.py
|
|
616
|
+
└── tests/
|
|
617
|
+
├── __init__.py
|
|
618
|
+
└── test_core.py
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
**pyproject.toml:**
|
|
622
|
+
|
|
623
|
+
```toml
|
|
624
|
+
[build-system]
|
|
625
|
+
requires = ["hatchling"]
|
|
626
|
+
build-backend = "hatchling.build"
|
|
627
|
+
|
|
628
|
+
[project]
|
|
629
|
+
name = "mypackage"
|
|
630
|
+
version = "0.1.0"
|
|
631
|
+
description = "My awesome package"
|
|
632
|
+
readme = "README.md"
|
|
633
|
+
requires-python = ">=3.12"
|
|
634
|
+
dependencies = [
|
|
635
|
+
"requests>=2.31.0",
|
|
636
|
+
]
|
|
637
|
+
|
|
638
|
+
[project.optional-dependencies]
|
|
639
|
+
dev = [
|
|
640
|
+
"pytest>=7.4.0",
|
|
641
|
+
"black>=23.0.0",
|
|
642
|
+
"ruff>=0.1.0",
|
|
643
|
+
]
|
|
644
|
+
|
|
645
|
+
[project.scripts]
|
|
646
|
+
mytool = "mypackage.cli:main"
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
### Application Project
|
|
650
|
+
|
|
651
|
+
```
|
|
652
|
+
my-app/
|
|
653
|
+
├── README.md
|
|
654
|
+
├── pyproject.toml
|
|
655
|
+
├── .env.example
|
|
656
|
+
├── .gitignore
|
|
657
|
+
├── app/
|
|
658
|
+
│ ├── __init__.py
|
|
659
|
+
│ ├── main.py
|
|
660
|
+
│ ├── models/
|
|
661
|
+
│ ├── routes/
|
|
662
|
+
│ └── services/
|
|
663
|
+
├── tests/
|
|
664
|
+
│ ├── unit/
|
|
665
|
+
│ └── integration/
|
|
666
|
+
└── alembic/ # Database migrations
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
## Environment Variables
|
|
670
|
+
|
|
671
|
+
### .env File
|
|
672
|
+
|
|
673
|
+
Create `.env` for local configuration:
|
|
674
|
+
|
|
675
|
+
```bash
|
|
676
|
+
# Database
|
|
677
|
+
DATABASE_URL=postgresql://user:pass@localhost:5432/dbname
|
|
678
|
+
|
|
679
|
+
# API Keys
|
|
680
|
+
API_KEY=your_secret_key
|
|
681
|
+
SECRET_KEY=another_secret
|
|
682
|
+
|
|
683
|
+
# Environment
|
|
684
|
+
ENVIRONMENT=development
|
|
685
|
+
DEBUG=True
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
**Load with python-dotenv:**
|
|
689
|
+
|
|
690
|
+
```bash
|
|
691
|
+
pip install python-dotenv
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
```python
|
|
695
|
+
from dotenv import load_dotenv
|
|
696
|
+
import os
|
|
697
|
+
|
|
698
|
+
load_dotenv()
|
|
699
|
+
|
|
700
|
+
database_url = os.getenv('DATABASE_URL')
|
|
701
|
+
api_key = os.getenv('API_KEY')
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
## Dependency Management Strategies
|
|
705
|
+
|
|
706
|
+
### Option 1: Simple requirements.txt
|
|
707
|
+
|
|
708
|
+
Best for: Small projects, quick scripts
|
|
709
|
+
|
|
710
|
+
```bash
|
|
711
|
+
# Production dependencies
|
|
712
|
+
cat > requirements.txt <<EOF
|
|
713
|
+
requests==2.31.0
|
|
714
|
+
fastapi==0.104.0
|
|
715
|
+
uvicorn==0.24.0
|
|
716
|
+
EOF
|
|
717
|
+
|
|
718
|
+
# Development dependencies
|
|
719
|
+
cat > requirements-dev.txt <<EOF
|
|
720
|
+
-r requirements.txt
|
|
721
|
+
pytest==7.4.0
|
|
722
|
+
black==23.11.0
|
|
723
|
+
ruff==0.1.6
|
|
724
|
+
EOF
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
### Option 2: pyproject.toml
|
|
728
|
+
|
|
729
|
+
Best for: Packages, modern projects
|
|
730
|
+
|
|
731
|
+
```toml
|
|
732
|
+
[project]
|
|
733
|
+
dependencies = [
|
|
734
|
+
"requests>=2.31.0",
|
|
735
|
+
"fastapi>=0.104.0",
|
|
736
|
+
]
|
|
737
|
+
|
|
738
|
+
[project.optional-dependencies]
|
|
739
|
+
dev = [
|
|
740
|
+
"pytest>=7.4.0",
|
|
741
|
+
"black>=23.0.0",
|
|
742
|
+
]
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
### Option 3: Poetry
|
|
746
|
+
|
|
747
|
+
```bash
|
|
748
|
+
pip install poetry
|
|
749
|
+
|
|
750
|
+
# Initialize project
|
|
751
|
+
poetry init
|
|
752
|
+
|
|
753
|
+
# Add dependencies
|
|
754
|
+
poetry add requests
|
|
755
|
+
poetry add --group dev pytest
|
|
756
|
+
|
|
757
|
+
# Install
|
|
758
|
+
poetry install
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
## Performance Tips
|
|
762
|
+
|
|
763
|
+
### Use Built-in Functions
|
|
764
|
+
|
|
765
|
+
```python
|
|
766
|
+
# Slow
|
|
767
|
+
result = []
|
|
768
|
+
for item in items:
|
|
769
|
+
result.append(item * 2)
|
|
770
|
+
|
|
771
|
+
# Fast
|
|
772
|
+
result = [item * 2 for item in items]
|
|
773
|
+
|
|
774
|
+
# Faster (for large datasets)
|
|
775
|
+
result = list(map(lambda x: x * 2, items))
|
|
776
|
+
```
|
|
777
|
+
|
|
778
|
+
### Use Generator Expressions
|
|
779
|
+
|
|
780
|
+
```python
|
|
781
|
+
# Memory-intensive
|
|
782
|
+
squares = [x**2 for x in range(1000000)]
|
|
783
|
+
|
|
784
|
+
# Memory-efficient
|
|
785
|
+
squares = (x**2 for x in range(1000000))
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
### Profile Code
|
|
789
|
+
|
|
790
|
+
```bash
|
|
791
|
+
# Install profiling tools
|
|
792
|
+
pip install line_profiler memory_profiler
|
|
793
|
+
|
|
794
|
+
# Profile script
|
|
795
|
+
python -m cProfile -s cumulative script.py
|
|
796
|
+
|
|
797
|
+
# Line profiler
|
|
798
|
+
kernprof -l -v script.py
|
|
799
|
+
|
|
800
|
+
# Memory profiler
|
|
801
|
+
python -m memory_profiler script.py
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
## Debugging
|
|
805
|
+
|
|
806
|
+
### Python Debugger (pdb)
|
|
807
|
+
|
|
808
|
+
```python
|
|
809
|
+
import pdb
|
|
810
|
+
|
|
811
|
+
def buggy_function(x):
|
|
812
|
+
pdb.set_trace() # Breakpoint
|
|
813
|
+
result = x * 2
|
|
814
|
+
return result
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
**pdb Commands:**
|
|
818
|
+
|
|
819
|
+
```
|
|
820
|
+
n - next line
|
|
821
|
+
s - step into
|
|
822
|
+
c - continue
|
|
823
|
+
p variable - print variable
|
|
824
|
+
l - list code
|
|
825
|
+
q - quit
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
### VS Code Debugger
|
|
829
|
+
|
|
830
|
+
Already configured with Python extension.
|
|
831
|
+
|
|
832
|
+
**launch.json:**
|
|
833
|
+
|
|
834
|
+
```json
|
|
835
|
+
{
|
|
836
|
+
"version": "0.2.0",
|
|
837
|
+
"configurations": [
|
|
838
|
+
{
|
|
839
|
+
"name": "Python: Current File",
|
|
840
|
+
"type": "python",
|
|
841
|
+
"request": "launch",
|
|
842
|
+
"program": "${file}",
|
|
843
|
+
"console": "integratedTerminal"
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
"name": "Python: FastAPI",
|
|
847
|
+
"type": "python",
|
|
848
|
+
"request": "launch",
|
|
849
|
+
"module": "uvicorn",
|
|
850
|
+
"args": ["main:app", "--reload"],
|
|
851
|
+
"jinja": true
|
|
852
|
+
}
|
|
853
|
+
]
|
|
854
|
+
}
|
|
855
|
+
```
|
|
856
|
+
|
|
857
|
+
## Security Best Practices
|
|
858
|
+
|
|
859
|
+
1. **Pin dependencies** - Use exact versions in requirements.txt
|
|
860
|
+
2. **Audit packages** - Run `pip audit` regularly
|
|
861
|
+
3. **Don't commit secrets** - Use .env and .gitignore
|
|
862
|
+
4. **Use virtual environments** - Isolate project dependencies
|
|
863
|
+
5. **Keep Python updated** - Update to latest patch versions
|
|
864
|
+
6. **Validate input** - Never trust user input
|
|
865
|
+
7. **Use type hints** - Catch errors early with mypy
|
|
866
|
+
|
|
867
|
+
## Common Issues
|
|
868
|
+
|
|
869
|
+
### Import errors
|
|
870
|
+
|
|
871
|
+
```bash
|
|
872
|
+
# Ensure PYTHONPATH includes src/
|
|
873
|
+
export PYTHONPATH="${PYTHONPATH}:${PWD}/src"
|
|
874
|
+
|
|
875
|
+
# Or install in editable mode
|
|
876
|
+
pip install -e .
|
|
877
|
+
```
|
|
878
|
+
|
|
879
|
+
### Permission errors
|
|
880
|
+
|
|
881
|
+
```bash
|
|
882
|
+
# Use --user flag
|
|
883
|
+
pip install --user package-name
|
|
884
|
+
|
|
885
|
+
# Or ensure pip is upgraded
|
|
886
|
+
pip install --upgrade pip
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
### Conflicting dependencies
|
|
890
|
+
|
|
891
|
+
```bash
|
|
892
|
+
# Use pip-tools
|
|
893
|
+
pip install pip-tools
|
|
894
|
+
|
|
895
|
+
# Create requirements.in with loose versions
|
|
896
|
+
cat > requirements.in <<EOF
|
|
897
|
+
requests
|
|
898
|
+
fastapi
|
|
899
|
+
EOF
|
|
900
|
+
|
|
901
|
+
# Compile to requirements.txt with exact versions
|
|
902
|
+
pip-compile requirements.in
|
|
903
|
+
```
|
|
904
|
+
|
|
905
|
+
## Related Overlays
|
|
906
|
+
|
|
907
|
+
- **mkdocs** - Python-based documentation (includes MkDocs + Material theme)
|
|
908
|
+
- **pre-commit** - Code quality gates (works great with Python hooks)
|
|
909
|
+
- **postgres** - PostgreSQL database (for Django/Flask apps)
|
|
910
|
+
- **redis** - Redis cache (for Celery/FastAPI apps)
|
|
911
|
+
|
|
912
|
+
## Additional Resources
|
|
913
|
+
|
|
914
|
+
- [Python Documentation](https://docs.python.org/3/)
|
|
915
|
+
- [Python Package Index (PyPI)](https://pypi.org/)
|
|
916
|
+
- [Real Python Tutorials](https://realpython.com/)
|
|
917
|
+
- [FastAPI Documentation](https://fastapi.tiangolo.com/)
|
|
918
|
+
- [Django Documentation](https://docs.djangoproject.com/)
|
|
919
|
+
- [pytest Documentation](https://docs.pytest.org/)
|