|
| 1 | +# Publishing pythonstl to PyPI |
| 2 | + |
| 3 | +This document provides step-by-step instructions for building and publishing the pythonstl package to PyPI. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Install required tools: |
| 8 | + |
| 9 | +```bash |
| 10 | +pip install --upgrade pip |
| 11 | +pip install build twine |
| 12 | +``` |
| 13 | + |
| 14 | +## Step 1: Clean Previous Builds |
| 15 | + |
| 16 | +Remove any existing build artifacts: |
| 17 | + |
| 18 | +```bash |
| 19 | +# Windows PowerShell |
| 20 | +Remove-Item -Recurse -Force dist, build, *.egg-info -ErrorAction SilentlyContinue |
| 21 | + |
| 22 | +# Linux/Mac |
| 23 | +rm -rf dist build *.egg-info |
| 24 | +``` |
| 25 | + |
| 26 | +## Step 2: Build the Distribution |
| 27 | + |
| 28 | +Build both source distribution and wheel: |
| 29 | + |
| 30 | +```bash |
| 31 | +python -m build |
| 32 | +``` |
| 33 | + |
| 34 | +This creates: |
| 35 | +- `dist/pythonstl-0.1.0.tar.gz` (source distribution) |
| 36 | +- `dist/pythonstl-0.1.0-py3-none-any.whl` (wheel) |
| 37 | + |
| 38 | +## Step 3: Validate the Build |
| 39 | + |
| 40 | +Check the distribution files for errors: |
| 41 | + |
| 42 | +```bash |
| 43 | +twine check dist/* |
| 44 | +``` |
| 45 | + |
| 46 | +Expected output: |
| 47 | +``` |
| 48 | +Checking dist/pythonstl-0.1.0-py3-none-any.whl: PASSED |
| 49 | +Checking dist/pythonstl-0.1.0.tar.gz: PASSED |
| 50 | +``` |
| 51 | + |
| 52 | +## Step 4: Test on TestPyPI (Recommended) |
| 53 | + |
| 54 | +### Upload to TestPyPI |
| 55 | + |
| 56 | +```bash |
| 57 | +twine upload --repository testpypi dist/* |
| 58 | +``` |
| 59 | + |
| 60 | +You'll be prompted for credentials. Use: |
| 61 | +- Username: `__token__` |
| 62 | +- Password: Your TestPyPI API token (starts with `pypi-`) |
| 63 | + |
| 64 | +### Install from TestPyPI |
| 65 | + |
| 66 | +Test the installation: |
| 67 | + |
| 68 | +```bash |
| 69 | +pip install --index-url https://test.pypi.org/simple/ pythonstl |
| 70 | +``` |
| 71 | + |
| 72 | +### Verify Installation |
| 73 | + |
| 74 | +```python |
| 75 | +python -c "from pythonstl import vector; v = vector(); v.push_back(1); print('✓ Installation successful')" |
| 76 | +``` |
| 77 | + |
| 78 | +## Step 5: Publish to Production PyPI |
| 79 | + |
| 80 | +### Using API Token (Recommended) |
| 81 | + |
| 82 | +```bash |
| 83 | +twine upload dist/* -u __token__ -p YOUR_PYPI_API_TOKEN |
| 84 | +``` |
| 85 | + |
| 86 | +**Security Best Practices:** |
| 87 | +- Never commit API tokens to version control |
| 88 | +- Store tokens in environment variables or password managers |
| 89 | +- Use project-scoped tokens when possible |
| 90 | +- Rotate tokens periodically |
| 91 | + |
| 92 | +### Using Environment Variable |
| 93 | + |
| 94 | +Set your token as an environment variable: |
| 95 | + |
| 96 | +```bash |
| 97 | +# Windows PowerShell |
| 98 | +$env:TWINE_PASSWORD = "pypi-YOUR_TOKEN_HERE" |
| 99 | +twine upload dist/* -u __token__ |
| 100 | + |
| 101 | +# Linux/Mac |
| 102 | +export TWINE_PASSWORD="pypi-YOUR_TOKEN_HERE" |
| 103 | +twine upload dist/* -u __token__ |
| 104 | +``` |
| 105 | + |
| 106 | +### Using .pypirc (Alternative) |
| 107 | + |
| 108 | +Create `~/.pypirc`: |
| 109 | + |
| 110 | +```ini |
| 111 | +[pypi] |
| 112 | +username = __token__ |
| 113 | +password = pypi-YOUR_TOKEN_HERE |
| 114 | +``` |
| 115 | + |
| 116 | +**Warning:** Ensure `.pypirc` has restricted permissions (chmod 600 on Unix). |
| 117 | + |
| 118 | +Then upload: |
| 119 | + |
| 120 | +```bash |
| 121 | +twine upload dist/* |
| 122 | +``` |
| 123 | + |
| 124 | +## Step 6: Verify Publication |
| 125 | + |
| 126 | +After successful upload: |
| 127 | + |
| 128 | +1. Visit https://pypi.org/project/pythonstl/ |
| 129 | +2. Install from PyPI: |
| 130 | + ```bash |
| 131 | + pip install pythonstl |
| 132 | + ``` |
| 133 | +3. Test the installation: |
| 134 | + ```python |
| 135 | + from pythonstl import stack, queue, vector, stl_set, stl_map, priority_queue |
| 136 | + print("✓ All imports successful") |
| 137 | + ``` |
| 138 | + |
| 139 | +## Troubleshooting |
| 140 | + |
| 141 | +### Build Fails |
| 142 | + |
| 143 | +- Ensure `pyproject.toml` is valid |
| 144 | +- Check that all package directories have `__init__.py` |
| 145 | +- Verify Python version >= 3.10 |
| 146 | + |
| 147 | +### Upload Fails |
| 148 | + |
| 149 | +- **403 Forbidden**: Check API token permissions |
| 150 | +- **400 Bad Request**: Package name may already exist |
| 151 | +- **File already exists**: Version already published (increment version) |
| 152 | + |
| 153 | +### Import Errors After Installation |
| 154 | + |
| 155 | +- Clear pip cache: `pip cache purge` |
| 156 | +- Reinstall: `pip uninstall pythonstl && pip install pythonstl` |
| 157 | +- Check for naming conflicts with other packages |
| 158 | + |
| 159 | +## Version Management |
| 160 | + |
| 161 | +For future releases: |
| 162 | + |
| 163 | +1. Update version in `pythonstl/__init__.py` |
| 164 | +2. Update version in `pyproject.toml` |
| 165 | +3. Create git tag: `git tag v0.1.1` |
| 166 | +4. Rebuild and republish |
| 167 | + |
| 168 | +## Security Checklist |
| 169 | + |
| 170 | +Before publishing: |
| 171 | + |
| 172 | +- [ ] No hardcoded secrets in code |
| 173 | +- [ ] No sensitive data in examples |
| 174 | +- [ ] LICENSE file included |
| 175 | +- [ ] README.md is accurate |
| 176 | +- [ ] All tests pass |
| 177 | +- [ ] Version number is correct |
| 178 | +- [ ] API token is secure |
| 179 | + |
| 180 | +## Post-Publication |
| 181 | + |
| 182 | +1. Create GitHub release with changelog |
| 183 | +2. Update documentation |
| 184 | +3. Announce on relevant channels |
| 185 | +4. Monitor PyPI download stats |
| 186 | +5. Respond to issues and feedback |
| 187 | + |
| 188 | +## Resources |
| 189 | + |
| 190 | +- PyPI: https://pypi.org/ |
| 191 | +- TestPyPI: https://test.pypi.org/ |
| 192 | +- Packaging Guide: https://packaging.python.org/ |
| 193 | +- Twine Documentation: https://twine.readthedocs.io/ |
0 commit comments