Skip to content

Commit f09c87e

Browse files
Update project_publishing.md
1 parent 18e9eca commit f09c87e

File tree

1 file changed

+115
-4
lines changed

1 file changed

+115
-4
lines changed

episodes/project_publishing.md

Lines changed: 115 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ exercises: 15
2323

2424
## Introduction
2525
Once we have created our project, defined all the necessary metadata in the toml file, its time to publish our project. Let see the tools and steps we need to acheive this.
26-
We need to install the following tools
26+
We need to install the following tools i.e. `build` and `twine`
2727
1. `build` : A tool to read the ['pyproject']toml file and build the package files
2828
```bash
2929
pip install build
@@ -63,16 +63,127 @@ We need to install the following tools
6363
<img width="259" height="398" alt="image" src="https://github.com/user-attachments/assets/302f502b-34ed-470e-a4e0-884b808a6ff0" />
6464

6565

66-
3. `twine` : A tool for securely uploading packages to PyPI and TestPyPI.
66+
2. Create an account on TestPyPI
67+
Visit this [URL](https://test.pypi.org/account/register/) and crete an account to generate the API keys, to be able to upload your package to TestPyPI in the next step.
68+
69+
4. `twine` : A tool for securely uploading packages to PyPI and TestPyPI.
6770
```bash
6871
pip install build twine
6972
7073
twine upload --repository testpypi dist/*
7174
```
7275
You'll be prompted to enter your TestPyPI username and password. It's recommended to use an API token instead of your password. When prompted for your password, paste the token in.
73-
74-
That's it! After the upload is successful, your package will be available on TestPyPI.
7576

77+
```output
78+
Uploading distributions to https://test.pypi.org/legacy/
79+
INFO dist/po_greet_me-0.1.1-py3-none-any.whl (0.8 KB)
80+
INFO dist/po_greet_me-0.1.1.tar.gz (5.0 KB)
81+
INFO username set by command options
82+
INFO Querying keyring for password
83+
INFO No keyring backend found
84+
Enter your API token:
85+
INFO username: __token__
86+
INFO password: <hidden>
87+
Uploading po_greet_me-0.1.1-py3-none-any.whl
88+
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.5/2.5 kB • 00:00 • ?
89+
INFO Response from https://test.pypi.org/legacy/:
90+
200 OK
91+
INFO <html>
92+
<head>
93+
<title>200 OK</title>
94+
</head>
95+
<body>
96+
<h1>200 OK</h1>
97+
<br/><br/>
98+
99+
100+
101+
</body>
102+
</html>
103+
Uploading po_greet_me-0.1.1.tar.gz
104+
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.7/6.7 kB • 00:00 • ?
105+
INFO Response from https://test.pypi.org/legacy/:
106+
200 OK
107+
INFO <html>
108+
<head>
109+
<title>200 OK</title>
110+
</head>
111+
<body>
112+
<h1>200 OK</h1>
113+
<br/><br/>
114+
115+
116+
117+
</body>
118+
</html>
119+
120+
View at:
121+
https://test.pypi.org/project/po-greet-me/0.1.1/
122+
```
123+
124+
That's it! After the upload is successful, your package will be available on TestPyPI. E.g. : https://test.pypi.org/project/po-greet-me/0.1.1/
125+
126+
It is possible that the name of your project already exists or is simialr to an existing project. In that case you may end up in an error like this :
127+
```output
128+
twine upload --repository testpypi dist/*
129+
Uploading distributions to https://test.pypi.org/legacy/
130+
Enter your API token:
131+
Uploading greet_me-0.1.1-py3-none-any.whl
132+
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.6/2.6 kB • 00:00 • ?
133+
WARNING Error during upload. Retry with the --verbose option for more details.
134+
ERROR HTTPError: 403 Forbidden from https://test.pypi.org/legacy/
135+
Forbidden
136+
```
137+
This isnt always helpful and you should try this command as tipped in the error message above to know more.
138+
```bash
139+
twine upload --repository testpypi dist/* --verbose
140+
```
141+
```output
142+
Uploading distributions to https://test.pypi.org/legacy/
143+
INFO dist/greet_me-0.1.1-py3-none-any.whl (0.9 KB)
144+
INFO dist/greet_me-0.1.1.tar.gz (4.9 KB)
145+
INFO username set by command options
146+
INFO Querying keyring for password
147+
INFO No keyring backend found
148+
Enter your API token:
149+
INFO username: __token__
150+
INFO password: <hidden>
151+
Uploading greet_me-0.1.1-py3-none-any.whl
152+
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.6/2.6 kB • 00:00 • ?
153+
INFO Response from https://test.pypi.org/legacy/:
154+
400 Bad Request
155+
INFO <html>
156+
<head>
157+
<title>400 The name 'greet-me' is too similar to an existing project. See https://test.pypi.org/help/#project-name for more information.</title>
158+
</head>
159+
<body>
160+
<h1>400 The name 'greet-me' is too similar to an existing project. See https://test.pypi.org/help/#project-name for more information.</h1>
161+
The server could not comply with the request since it is either malformed or otherwise incorrect.<br/><br/>
162+
The name &#x27;greet-me&#x27; is too similar to an existing project. See https://test.pypi.org/help/#project-name for more information.
163+
164+
165+
</body>
166+
</html>
167+
ERROR HTTPError: 400 Bad Request from https://test.pypi.org/legacy/
168+
Bad Request
169+
```
170+
To fix this, rename you project e.g. to `po_greet_me` , and add the following in `pyproject.toml` file.
171+
and try the steps below to upload it again.
172+
```toml
173+
[tool.hatch.build.targets.wheel]
174+
packages = ["src/po_greet_me"]
175+
```
176+
```bash
177+
# 1. (Recommended) Remove the old build directory
178+
rm -rf dist
179+
180+
# 2. Re-build your package with the new name
181+
python -m build
182+
183+
# 3. Upload the new version to TestPyPI
184+
twine upload --repository testpypi dist/*
185+
```
186+
76187
::::::::::::::::::::::::::::::::::::: keypoints
77188
78189

0 commit comments

Comments
 (0)