|
1 | 1 | # Publishing to PyPI |
2 | 2 |
|
3 | | -This guide explains how to publish `pgsql-test` to PyPI using Poetry. |
4 | | - |
5 | | -## Prerequisites |
6 | | - |
7 | | -1. **PyPI Account**: Create an account at https://pypi.org/account/register/ |
8 | | -2. **API Token**: Generate an API token at https://pypi.org/manage/account/token/ |
9 | | -3. **Poetry**: Already installed if you've been developing locally |
10 | | - |
11 | | -## One-Time Setup |
12 | | - |
13 | | -Configure Poetry with your PyPI token: |
14 | | - |
15 | | -```bash |
16 | | -poetry config pypi-token.pypi <your-token> |
17 | | -``` |
18 | | - |
19 | | -Alternatively, you can use environment variables: |
20 | | - |
21 | | -```bash |
22 | | -export POETRY_PYPI_TOKEN_PYPI=<your-token> |
23 | | -``` |
24 | | - |
25 | | -## Publishing Steps |
26 | | - |
27 | | -### 1. Update Version |
28 | | - |
29 | | -Update the version in `pyproject.toml`: |
30 | | - |
31 | | -```toml |
32 | | -[tool.poetry] |
33 | | -name = "pgsql-test" |
34 | | -version = "0.1.1" # Bump this |
35 | | -``` |
36 | | - |
37 | | -Or use Poetry's version command: |
38 | | - |
39 | | -```bash |
40 | | -# Bump patch version (0.1.0 -> 0.1.1) |
41 | | -poetry version patch |
42 | | - |
43 | | -# Bump minor version (0.1.0 -> 0.2.0) |
44 | | -poetry version minor |
45 | | - |
46 | | -# Bump major version (0.1.0 -> 1.0.0) |
47 | | -poetry version major |
48 | | - |
49 | | -# Set specific version |
50 | | -poetry version 1.0.0 |
51 | | -``` |
52 | | - |
53 | | -### 2. Run Tests |
54 | | - |
55 | | -Ensure all tests pass before publishing: |
56 | | - |
57 | | -```bash |
58 | | -poetry run pytest -v |
59 | | -poetry run ruff check . |
60 | | -poetry run mypy src --ignore-missing-imports |
61 | | -``` |
62 | | - |
63 | | -### 3. Build the Package |
64 | | - |
65 | | -```bash |
66 | | -poetry build |
67 | | -``` |
68 | | - |
69 | | -This creates distribution files in the `dist/` directory: |
70 | | -- `pgsql_test-0.1.1.tar.gz` (source distribution) |
71 | | -- `pgsql_test-0.1.1-py3-none-any.whl` (wheel) |
72 | | - |
73 | | -### 4. Publish to PyPI |
74 | | - |
75 | | -```bash |
76 | | -poetry publish |
77 | | -``` |
78 | | - |
79 | | -Or build and publish in one command: |
80 | | - |
81 | | -```bash |
82 | | -poetry publish --build |
83 | | -``` |
84 | | - |
85 | | -## Testing with TestPyPI |
86 | | - |
87 | | -Before publishing to the real PyPI, you can test with TestPyPI: |
88 | | - |
89 | | -### 1. Create TestPyPI Account |
90 | | - |
91 | | -Register at https://test.pypi.org/account/register/ |
92 | | - |
93 | | -### 2. Configure TestPyPI |
94 | | - |
95 | | -```bash |
96 | | -poetry config repositories.testpypi https://test.pypi.org/legacy/ |
97 | | -poetry config pypi-token.testpypi <your-testpypi-token> |
98 | | -``` |
99 | | - |
100 | | -### 3. Publish to TestPyPI |
101 | | - |
102 | | -```bash |
103 | | -poetry publish --build -r testpypi |
104 | | -``` |
105 | | - |
106 | | -### 4. Test Installation |
107 | | - |
108 | | -```bash |
109 | | -pip install --index-url https://test.pypi.org/simple/ pgsql-test |
110 | | -``` |
111 | | - |
112 | | -## GitHub Actions Automation |
113 | | - |
114 | | -To automate publishing on releases, add this workflow to `.github/workflows/publish.yml`: |
115 | | - |
116 | | -```yaml |
117 | | -name: Publish to PyPI |
118 | | - |
119 | | -on: |
120 | | - release: |
121 | | - types: [published] |
122 | | - |
123 | | -jobs: |
124 | | - publish: |
125 | | - runs-on: ubuntu-latest |
126 | | - steps: |
127 | | - - uses: actions/checkout@v4 |
128 | | - |
129 | | - - name: Set up Python |
130 | | - uses: actions/setup-python@v5 |
131 | | - with: |
132 | | - python-version: "3.12" |
133 | | - |
134 | | - - name: Install Poetry |
135 | | - uses: snok/install-poetry@v1 |
136 | | - |
137 | | - - name: Build and publish |
138 | | - env: |
139 | | - POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} |
140 | | - run: poetry publish --build |
141 | | -``` |
142 | | -
|
143 | | -Then add your PyPI token as a repository secret named `PYPI_TOKEN`. |
144 | | - |
145 | | -## Versioning Guidelines |
146 | | - |
147 | | -Follow [Semantic Versioning](https://semver.org/): |
148 | | - |
149 | | -- **MAJOR** (1.0.0): Breaking changes to the public API |
150 | | -- **MINOR** (0.1.0): New features, backwards compatible |
151 | | -- **PATCH** (0.0.1): Bug fixes, backwards compatible |
152 | | - |
153 | | -For pre-release versions: |
154 | | -- `0.1.0a1` - Alpha release |
155 | | -- `0.1.0b1` - Beta release |
156 | | -- `0.1.0rc1` - Release candidate |
157 | | - |
158 | | -## Checklist Before Publishing |
159 | | - |
160 | | -- [ ] All tests pass locally |
161 | | -- [ ] Version number updated in `pyproject.toml` |
162 | | -- [ ] CHANGELOG updated (if you have one) |
163 | | -- [ ] README is up to date |
164 | | -- [ ] Commit and push all changes |
165 | | -- [ ] Create a git tag for the release |
166 | | - |
167 | | -```bash |
168 | | -git tag v0.1.1 |
169 | | -git push origin v0.1.1 |
170 | | -``` |
171 | | - |
172 | | -## Troubleshooting |
173 | | - |
174 | | -### "File already exists" Error |
175 | | - |
176 | | -PyPI doesn't allow overwriting existing versions. You must bump the version number. |
177 | | - |
178 | | -### Authentication Failed |
179 | | - |
180 | | -Verify your token is correct: |
181 | | - |
182 | | -```bash |
183 | | -poetry config pypi-token.pypi --unset |
184 | | -poetry config pypi-token.pypi <new-token> |
185 | | -``` |
186 | | - |
187 | | -### Package Name Conflict |
188 | | - |
189 | | -If `pgsql-test` is taken, you may need to use a different name like `pgsql-test-py` or `constructive-pgsql-test`. |
| 3 | +https://packaging.python.org/en/latest/tutorials/packaging-projects/ |
0 commit comments