Managing Environment & Dependencies
When to use this skill
- •When the user asks to "install packages", "setup project", or "initialize environment".
- •When encountering
ModuleNotFoundErroror missing dependencies. - •When creating new projects.
- •Triggers: "初始化環境", "缺少套件", "Module not found", "安裝依賴", "setup project", "執行 script", "python main.py"
Logic Flow & Decision Tree
0. Pre-Execution Gate (CRITICAL)
When: User asks to run a command (e.g., python main.py).
Action:
- •PAUSE. Do not execute immediately.
- •Check: Does
pyproject.tomlorrequirements.txtexist? - •If Missing: STOP and invoke Branch B (ask to setup environment first).
- •If Present: Proceed to standard execution.
1. Detection Phase
Action: Check project root for containerization markers:
- •
docker-compose.yml - •
Dockerfile
2. Branch A: Containerized Project (Exists)
Context: The project is already dockerized.
Rule: Strictly Forbidden to suggest pip install on Local Host.
Actions:
- •Modify
Dockerfileorpyproject.toml/requirements.txtinside the container source. - •Rebuild: Suggest
docker-compose buildordocker build. - •Maintain consistency: Ensure the container image remains the single source of truth.
3. Branch B: Local Project (Missing Docker)
Context: No Docker configuration found. Action:
- •Proactive Inquiry:
"偵測到此專案尚未容器化。是否建立 Docker 環境以確保一致性? (Detected non-containerized project. Should we dockerize?)"
- •If User Accepts (YES):
- •Generate
Dockerfile(Multi-stage best practices). - •Generate
docker-compose.yml(Development volume mapping).
- •Generate
- •If User Rejects (NO):
- •Strict Check: Verify if running inside
venvorconda. - •Safeguard: If no virtual env active, WARN user about global pollution before proceeding.
- •Proceed: Install locally.
- •Strict Check: Verify if running inside
Dependency Standards
1. Premier Choice (Default): pyproject.toml
- •Tooling: Standard for Poetry, Hatch, or modern Setuptools.
- •Usage: Always prefer creating/updating
pyproject.tomlfor new dependencies. - •Why: Metadata + Dependencies in one place.
2. Legacy Fallback: requirements.txt
- •Usage: Only if:
- •User explicitly requests it.
- •Project is legacy and already strictly binds to it.