|
| 1 | +# Deployment Guide |
| 2 | + |
| 3 | +This guide explains how to deploy `code-trajectory-mcp` to TestPyPI (for testing) and PyPI (for production). |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +### 1. Create TestPyPI Account |
| 8 | + |
| 9 | +1. Go to [https://test.pypi.org/account/register/](https://test.pypi.org/account/register/) |
| 10 | +2. Create an account |
| 11 | +3. Verify your email |
| 12 | + |
| 13 | +### 2. Create API Token |
| 14 | + |
| 15 | +1. Log in to TestPyPI |
| 16 | +2. Go to [Account Settings](https://test.pypi.org/manage/account/) |
| 17 | +3. Scroll to "API tokens" |
| 18 | +4. Click "Add API token" |
| 19 | +5. Set name (e.g., "code-trajectory-upload") |
| 20 | +6. Set scope to "Entire account" (or specific project if you've created it) |
| 21 | +7. Copy the generated token (starts with `pypi-`) |
| 22 | +8. **Important:** Save this token securely - you won't see it again! |
| 23 | + |
| 24 | +### 3. Configure `.pypirc` (Optional but Recommended) |
| 25 | + |
| 26 | +Create or edit `~/.pypirc` (Windows: `%USERPROFILE%\.pypirc`): |
| 27 | + |
| 28 | +```ini |
| 29 | +[distutils] |
| 30 | +index-servers = |
| 31 | + pypi |
| 32 | + testpypi |
| 33 | + |
| 34 | +[testpypi] |
| 35 | +repository = https://test.pypi.org/legacy/ |
| 36 | +username = __token__ |
| 37 | +password = pypi-YOUR_TOKEN_HERE |
| 38 | + |
| 39 | +[pypi] |
| 40 | +repository = https://pypi.org/legacy/ |
| 41 | +username = __token__ |
| 42 | +password = pypi-YOUR_TOKEN_HERE_WHEN_READY |
| 43 | +``` |
| 44 | + |
| 45 | +**Note:** Replace `pypi-YOUR_TOKEN_HERE` with your actual token. |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## Deployment to TestPyPI |
| 50 | + |
| 51 | +### Method 1: Using the Automation Script (Recommended) |
| 52 | + |
| 53 | +```powershell |
| 54 | +.\deploy-testpypi.ps1 |
| 55 | +``` |
| 56 | + |
| 57 | +This script will: |
| 58 | +1. Clean old build artifacts |
| 59 | +2. Build the package |
| 60 | +3. Upload to TestPyPI |
| 61 | +4. Test installation from TestPyPI |
| 62 | + |
| 63 | +### Method 2: Manual Deployment |
| 64 | + |
| 65 | +```powershell |
| 66 | +# 1. Clean old builds |
| 67 | +Remove-Item -Recurse -Force dist -ErrorAction SilentlyContinue |
| 68 | +
|
| 69 | +# 2. Build the package |
| 70 | +uv build |
| 71 | +
|
| 72 | +# 3. Install twine (if not already installed) |
| 73 | +uv pip install twine |
| 74 | +
|
| 75 | +# 4. Upload to TestPyPI |
| 76 | +twine upload --repository testpypi dist/* |
| 77 | +
|
| 78 | +# You'll be prompted for username and password: |
| 79 | +# Username: __token__ |
| 80 | +# Password: pypi-YOUR_TOKEN_HERE |
| 81 | +``` |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## Testing the TestPyPI Package |
| 86 | + |
| 87 | +### Install from TestPyPI |
| 88 | + |
| 89 | +```bash |
| 90 | +# Using pip |
| 91 | +pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ code-trajectory |
| 92 | + |
| 93 | +# Using uv |
| 94 | +uv pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ code-trajectory |
| 95 | +``` |
| 96 | + |
| 97 | +**Note:** `--extra-index-url https://pypi.org/simple/` is needed because dependencies (like `mcp`, `gitpython`) are on regular PyPI, not TestPyPI. |
| 98 | + |
| 99 | +### Test the Installation |
| 100 | + |
| 101 | +```bash |
| 102 | +# Check version |
| 103 | +code-trajectory --version |
| 104 | + |
| 105 | +# Or test with uvx |
| 106 | +uvx --from code-trajectory --index-url https://test.pypi.org/simple/ code-trajectory |
| 107 | +``` |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +## Deployment to PyPI (Production) |
| 112 | + |
| 113 | +**⚠️ Only deploy to PyPI when you're confident the package works correctly!** |
| 114 | + |
| 115 | +### Prerequisites |
| 116 | + |
| 117 | +1. Create PyPI account at [https://pypi.org/account/register/](https://pypi.org/account/register/) |
| 118 | +2. Generate API token (same process as TestPyPI) |
| 119 | +3. Update `~/.pypirc` with PyPI credentials |
| 120 | + |
| 121 | +### Deploy to PyPI |
| 122 | + |
| 123 | +```powershell |
| 124 | +# 1. Clean and build |
| 125 | +Remove-Item -Recurse -Force dist -ErrorAction SilentlyContinue |
| 126 | +uv build |
| 127 | +
|
| 128 | +# 2. Upload to PyPI |
| 129 | +twine upload dist/* |
| 130 | +``` |
| 131 | + |
| 132 | +--- |
| 133 | + |
| 134 | +## Automated CI/CD Deployment (Optional) |
| 135 | + |
| 136 | +You can automate deployment with GitHub Actions. Create `.github/workflows/publish.yml`: |
| 137 | + |
| 138 | +```yaml |
| 139 | +name: Publish to PyPI |
| 140 | + |
| 141 | +on: |
| 142 | + release: |
| 143 | + types: [published] |
| 144 | + |
| 145 | +jobs: |
| 146 | + deploy: |
| 147 | + runs-on: ubuntu-latest |
| 148 | + steps: |
| 149 | + - uses: actions/checkout@v4 |
| 150 | + |
| 151 | + - name: Install uv |
| 152 | + uses: astral-sh/setup-uv@v1 |
| 153 | + |
| 154 | + - name: Set up Python |
| 155 | + run: uv python install 3.14 |
| 156 | + |
| 157 | + - name: Build package |
| 158 | + run: uv build |
| 159 | + |
| 160 | + - name: Publish to PyPI |
| 161 | + env: |
| 162 | + TWINE_USERNAME: __token__ |
| 163 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 164 | + run: | |
| 165 | + uv pip install twine |
| 166 | + twine upload dist/* |
| 167 | +``` |
| 168 | +
|
| 169 | +Add `PYPI_API_TOKEN` to your GitHub repository secrets. |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +## Troubleshooting |
| 174 | + |
| 175 | +### Package Name Already Exists |
| 176 | + |
| 177 | +If `code-trajectory` is already taken on PyPI, you'll need to: |
| 178 | +1. Choose a different name in `pyproject.toml` |
| 179 | +2. Rebuild and reupload |
| 180 | + |
| 181 | +### Version Already Exists |
| 182 | + |
| 183 | +PyPI doesn't allow re-uploading the same version. You need to: |
| 184 | +1. Increment version in `pyproject.toml` |
| 185 | +2. Rebuild and reupload |
| 186 | + |
| 187 | +### Dependencies Not Found |
| 188 | + |
| 189 | +TestPyPI doesn't have all packages. When installing from TestPyPI, always use: |
| 190 | +```bash |
| 191 | +--extra-index-url https://pypi.org/simple/ |
| 192 | +``` |
| 193 | + |
| 194 | +--- |
| 195 | + |
| 196 | +## Version Management |
| 197 | + |
| 198 | +Current version: `0.1.1` (in `pyproject.toml`) |
| 199 | + |
| 200 | +To update version: |
| 201 | +1. Edit `pyproject.toml` |
| 202 | +2. Update `version = "0.1.2"` (or whatever the new version is) |
| 203 | +3. Commit changes |
| 204 | +4. Create new git tag: `git tag v0.1.2` |
| 205 | +5. Push tag: `git push origin v0.1.2` |
| 206 | +6. Build and deploy |
| 207 | + |
| 208 | +--- |
| 209 | + |
| 210 | +## Package Information |
| 211 | + |
| 212 | +- **Package name:** `code-trajectory` |
| 213 | +- **Import name:** `code_trajectory` |
| 214 | +- **Entry point:** `code-trajectory` command |
| 215 | +- **TestPyPI URL:** https://test.pypi.org/project/code-trajectory/ |
| 216 | +- **PyPI URL:** https://pypi.org/project/code-trajectory/ (when published) |
| 217 | + |
| 218 | +--- |
| 219 | + |
| 220 | +## Useful Commands |
| 221 | + |
| 222 | +```powershell |
| 223 | +# Check what will be included in the package |
| 224 | +uv build --outdir dist-test |
| 225 | +
|
| 226 | +# Check package contents |
| 227 | +tar -tzf dist/code_trajectory-0.1.1.tar.gz |
| 228 | +
|
| 229 | +# Validate package before upload |
| 230 | +twine check dist/* |
| 231 | +``` |
0 commit comments