$npx -y skills add MLOps-Courses/mlops-coding-skills --skill mlops-initializationGuide to initialize a new MLOps project with standard tools (uv, git, VS Code) and best practices.
| 1 | # MLOps Initialization |
| 2 | |
| 3 | ## Goal |
| 4 | |
| 5 | To initialize a robust, production-ready MLOps project structure using the modern Python toolchain (`uv`), industry-standard version control (`git`), and a configured development environment (`VS Code`). This skill ensures reproducibility, collaboration, and high code quality from day one. |
| 6 | |
| 7 | ## Prerequisites |
| 8 | |
| 9 | - **Language**: Python 3.14 (latest stable) |
| 10 | - **Manager**: `uv` (replaces pip, venv, poetry, pyenv) |
| 11 | - **VCS**: Git |
| 12 | - **IDE**: VS Code (recommended) |
| 13 | |
| 14 | ## Instructions |
| 15 | |
| 16 | ### 1. System & Toolchain Verification |
| 17 | |
| 18 | Before modifying files, verify that the essential tools are available. |
| 19 | |
| 20 | 1. **Check `uv`**: |
| 21 | - Ensure `uv` is installed: `uv --version` |
| 22 | - If missing, install it: `curl -LsSf https://astral.sh/uv/install.sh | sh` |
| 23 | 2. **Check `git`**: |
| 24 | - Ensure `git` is installed: `git --version` |
| 25 | |
| 26 | ### 2. Project Initialization |
| 27 | |
| 28 | Initialize the project structure using `uv` to ensure modern standards (`pyproject.toml`). |
| 29 | |
| 30 | 1. **Create Directory** (if not already inside): |
| 31 | - `mkdir <project_name> && cd <project_name>` |
| 32 | 2. **Initialize Project**: |
| 33 | - Run `uv init` |
| 34 | - This creates `pyproject.toml`, `.python-version`, and a basic `hello.py`. |
| 35 | 3. **Configure `pyproject.toml`**: |
| 36 | - Update **metadata**: `name`, `version`, `description`, `authors`, `license`. |
| 37 | - Set **requires-python**: Ensure it matches the project's target environment (e.g., `>=3.14`). |
| 38 | - **Example Structure**: |
| 39 | |
| 40 | ```toml |
| 41 | [project] |
| 42 | name = "my-mlops-project" |
| 43 | version = "0.1.0" |
| 44 | description = "A robust MLOps project." |
| 45 | readme = "README.md" |
| 46 | requires-python = ">=3.14" |
| 47 | license = { file = "LICENSE" } |
| 48 | authors = [{ name = "Your Name", email = "your.email@example.com" }] |
| 49 | dependencies = [ |
| 50 | "pandas>=2.3.0", |
| 51 | "loguru>=0.7.0", |
| 52 | # Add other runtime dependencies here |
| 53 | ] |
| 54 | |
| 55 | [project.urls] |
| 56 | Repository = "https://github.com/username/my-mlops-project" |
| 57 | Documentation = "https://username.github.io/my-mlops-project" |
| 58 | |
| 59 | # PEP 735 dependency groups (not shipped with the package). |
| 60 | [dependency-groups] |
| 61 | dev = [ |
| 62 | "pytest>=9.0.0", |
| 63 | "ruff>=0.15.0", |
| 64 | "ty>=0.0.56,<0.1", # pre-1.0: pin a compatible range |
| 65 | ] |
| 66 | |
| 67 | [build-system] |
| 68 | requires = ["uv_build>=0.9.0"] |
| 69 | build-backend = "uv_build" |
| 70 | ``` |
| 71 | |
| 72 | ### 3. Dependency Management |
| 73 | |
| 74 | Establish a clean separation between production and development dependencies. |
| 75 | |
| 76 | 1. **Add Runtime Dependencies** (Production): |
| 77 | - Use `uv add <package>` for libraries needed in production (e.g., `fastapi`, `numpy`, `torch`). |
| 78 | - These go into `[project.dependencies]` in `pyproject.toml`. |
| 79 | 2. **Add Dev Dependencies** (Development): |
| 80 | - Use `uv add --dev <package>` (or `--group dev`) for tools like `pytest`, `ruff`, `ty`. |
| 81 | - These go into `[dependency-groups]` (PEP 735) and are kept out of production builds. |
| 82 | 3. **Sync Environment**: |
| 83 | - Run `uv sync` to resolve dependencies, create the `.venv`, and generate the `uv.lock` file. |
| 84 | - **Critical**: The `uv.lock` file pins exact versions of all dependencies (including transitive ones). It ensures that every developer and CI/CD pipeline uses the exact same environment, preventing "it works on my machine" issues. Commit this file to git. |
| 85 | |
| 86 | ### 4. Version Control (Git) |
| 87 | |
| 88 | Set up a clean repository and ensure unwanted files are ignored. |
| 89 | |
| 90 | 1. **Initialize Git**: |
| 91 | - `git init` |
| 92 | - `git branch -M main` |
| 93 | 2. **Create `.gitignore`**: |
| 94 | - Write a robust `.gitignore` tailored for Python/MLOps. |
| 95 | - **Must Include**: |
| 96 | - Environment: `.venv/`, `.env` |
| 97 | - Caches: `__pycache__/`, `.pytest_cache/`, `.ruff_cache/`, `.ty_cache/` |
| 98 | - Builds: `dist/`, `build/`, `*.egg-info/` |
| 99 | - Data/Models: `data/`, `models/`, `outputs/` (unless using DVC/LFS) |
| 100 | - IDE: `.vscode/` (selectively), `.idea/`, `.DS_Store` |
| 101 | - *Note*: It is often good practice to commit project-specific `.vscode/settings.json` but ignore `User` settings. |
| 102 | 3. **Verify Status**: |
| 103 | - `git status` should show only source files, config files, and the lockfile. |
| 104 | |
| 105 | ### 5. IDE Configuration (VS Code) |
| 106 | |
| 107 | Standardize the developer experience (DX) by committing project-specific settings. |
| 108 | |
| 109 | 1. **Install Recommended Extensions**: |
| 110 | - **Python Tier A**: `ms-python.python`, `charliermarsh.ruff`, `ms-python.vscode-pylance`, `ms-toolsai.jupyter`. |
| 111 | - **Productivity**: `eamodio.gitlens`, `alefragnani.project-manager`, `usernamehw.errorlens`. |
| 112 | 2. **Create `.vscode` Directory**: |
| 113 | - `mkdir .vscode` |
| 114 | 3. **Create `settings.json`**: |
| 115 | - Configure settings to enforce code quality and use the `uv` environment. |
| 116 | - **Key Settings**: |
| 117 | |
| 118 | ```json |
| 119 | { |
| 120 | "[python]": { |
| 121 | "editor.defaultFormatter": "charliermarsh.ruff", |