|
| 1 | +# Publishing EdgeX Python SDK to PyPI |
| 2 | + |
| 3 | +This guide explains how to publish the EdgeX Python SDK to PyPI without using personal accounts. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +### 1. Create Organization PyPI Account |
| 8 | + |
| 9 | +1. Go to [PyPI Registration](https://pypi.org/account/register/) |
| 10 | +2. Create an account using the organization email (e.g., `info@edgex.exchange`) |
| 11 | +3. Verify the email address |
| 12 | +4. Enable 2FA for security |
| 13 | + |
| 14 | +### 2. Create API Tokens |
| 15 | + |
| 16 | +For security, use API tokens instead of passwords: |
| 17 | + |
| 18 | +1. Log into the organization PyPI account |
| 19 | +2. Go to Account Settings → API tokens |
| 20 | +3. Create a new API token: |
| 21 | + - **Name**: `edgex-python-sdk-upload` |
| 22 | + - **Scope**: Limit to specific project (after first upload) |
| 23 | +4. Copy and securely store the token (starts with `pypi-`) |
| 24 | + |
| 25 | +### 3. Set up GitHub Secrets |
| 26 | + |
| 27 | +Add the following secrets to your GitHub repository: |
| 28 | + |
| 29 | +1. Go to GitHub repository → Settings → Secrets and variables → Actions |
| 30 | +2. Add these secrets: |
| 31 | + - `PYPI_API_TOKEN`: Your PyPI API token |
| 32 | + - `TEST_PYPI_API_TOKEN`: Your Test PyPI API token (optional, for testing) |
| 33 | + |
| 34 | +## Publishing Methods |
| 35 | + |
| 36 | +### Method 1: Automated Publishing via GitHub Actions (Recommended) |
| 37 | + |
| 38 | +This method automatically publishes when you create a GitHub release: |
| 39 | + |
| 40 | +1. **Create a release**: |
| 41 | + ```bash |
| 42 | + git tag v0.1.0 |
| 43 | + git push origin v0.1.0 |
| 44 | + ``` |
| 45 | + |
| 46 | +2. **Create GitHub release**: |
| 47 | + - Go to GitHub → Releases → Create a new release |
| 48 | + - Choose the tag you just created |
| 49 | + - Add release notes |
| 50 | + - Publish the release |
| 51 | + |
| 52 | +3. **GitHub Actions will automatically**: |
| 53 | + - Build the package |
| 54 | + - Run quality checks |
| 55 | + - Upload to PyPI |
| 56 | + |
| 57 | +### Method 2: Manual Publishing |
| 58 | + |
| 59 | +If you prefer manual control: |
| 60 | + |
| 61 | +1. **Install build tools**: |
| 62 | + ```bash |
| 63 | + pip install build twine |
| 64 | + ``` |
| 65 | + |
| 66 | +2. **Build the package**: |
| 67 | + ```bash |
| 68 | + python scripts/build_and_test_package.py |
| 69 | + ``` |
| 70 | + |
| 71 | +3. **Upload to Test PyPI first** (recommended): |
| 72 | + ```bash |
| 73 | + twine upload --repository testpypi dist/* |
| 74 | + ``` |
| 75 | + |
| 76 | +4. **Test installation from Test PyPI**: |
| 77 | + ```bash |
| 78 | + pip install --index-url https://test.pypi.org/simple/ edgex-python-sdk |
| 79 | + ``` |
| 80 | + |
| 81 | +5. **Upload to PyPI**: |
| 82 | + ```bash |
| 83 | + twine upload dist/* |
| 84 | + ``` |
| 85 | + |
| 86 | +## Testing Before Publishing |
| 87 | + |
| 88 | +### Local Testing |
| 89 | + |
| 90 | +1. **Build and test locally**: |
| 91 | + ```bash |
| 92 | + python scripts/build_and_test_package.py |
| 93 | + ``` |
| 94 | + |
| 95 | +2. **Install locally**: |
| 96 | + ```bash |
| 97 | + pip install dist/edgex_python_sdk-*.whl |
| 98 | + ``` |
| 99 | + |
| 100 | +3. **Test basic functionality**: |
| 101 | + ```python |
| 102 | + import edgex_sdk |
| 103 | + print(edgex_sdk.__version__) |
| 104 | + ``` |
| 105 | + |
| 106 | +### Test PyPI |
| 107 | + |
| 108 | +Always test on Test PyPI before publishing to the main PyPI: |
| 109 | + |
| 110 | +1. **Upload to Test PyPI**: |
| 111 | + ```bash |
| 112 | + twine upload --repository testpypi dist/* |
| 113 | + ``` |
| 114 | + |
| 115 | +2. **Install from Test PyPI**: |
| 116 | + ```bash |
| 117 | + pip install --index-url https://test.pypi.org/simple/ edgex-python-sdk |
| 118 | + ``` |
| 119 | + |
| 120 | +## Version Management |
| 121 | + |
| 122 | +Update version numbers in these files before publishing: |
| 123 | + |
| 124 | +1. `setup.py` - line with `version="x.x.x"` |
| 125 | +2. `pyproject.toml` - line with `version = "x.x.x"` |
| 126 | +3. `edgex_sdk/__init__.py` - add `__version__ = "x.x.x"` |
| 127 | + |
| 128 | +## Security Best Practices |
| 129 | + |
| 130 | +1. **Use API tokens**, not passwords |
| 131 | +2. **Enable 2FA** on PyPI account |
| 132 | +3. **Limit token scope** to specific projects |
| 133 | +4. **Store tokens securely** in GitHub Secrets |
| 134 | +5. **Rotate tokens regularly** |
| 135 | +6. **Never commit tokens** to version control |
| 136 | + |
| 137 | +## Troubleshooting |
| 138 | + |
| 139 | +### Common Issues |
| 140 | + |
| 141 | +1. **Package name already exists**: |
| 142 | + - Choose a different name in `setup.py` and `pyproject.toml` |
| 143 | + |
| 144 | +2. **Version already exists**: |
| 145 | + - Increment version number |
| 146 | + - You cannot overwrite existing versions on PyPI |
| 147 | + |
| 148 | +3. **Authentication failed**: |
| 149 | + - Check API token is correct |
| 150 | + - Ensure token has proper permissions |
| 151 | + |
| 152 | +4. **Build fails**: |
| 153 | + - Run `python scripts/build_and_test_package.py` locally |
| 154 | + - Check for missing dependencies or syntax errors |
| 155 | + |
| 156 | +### Getting Help |
| 157 | + |
| 158 | +- PyPI Help: https://pypi.org/help/ |
| 159 | +- Packaging Guide: https://packaging.python.org/ |
| 160 | +- GitHub Actions: https://docs.github.com/en/actions |
| 161 | + |
| 162 | +## Post-Publishing |
| 163 | + |
| 164 | +After successful publishing: |
| 165 | + |
| 166 | +1. **Test installation**: |
| 167 | + ```bash |
| 168 | + pip install edgex-python-sdk |
| 169 | + ``` |
| 170 | + |
| 171 | +2. **Update documentation** if needed |
| 172 | + |
| 173 | +3. **Announce the release** to users |
| 174 | + |
| 175 | +4. **Monitor for issues** and user feedback |
0 commit comments