Skip to content

Commit b349425

Browse files
committed
Fix: more edits
1 parent 4eb5655 commit b349425

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

tutorials/publish-pypi.md

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,17 @@ to practice and learn.
6666

6767
## 4 Steps for publishing a Python package on PyPI
6868

69-
There are 4 things that you need to do to publish your Python package
69+
In this lesson you will learn how to publish your package to PyPI
70+
using [Hatch](https://hatch.pypa.io/latest/). There are 4 things that
71+
you need to do to publish your Python package:
7072
to PyPI. You need to:
7173

72-
1. **Create a package development environment.** You will do this using Hatch.
73-
1. [**Build your package**](../package-structure-code/python-package-distribution-files-sdist-wheel). Building a package is the process of turning your code into 2 types of distribution files: sdist and wheel. The wheel distribution file is particularly important for users who will `pip install` your package.
74+
1. **Create a package development environment**
75+
1. [**Build your package using `hatch build`**](../package-structure-code/python-package-distribution-files-sdist-wheel). Building a package is the process of turning your code into 2 types of distribution files: sdist and wheel. The wheel distribution file is particularly important for users who will `pip install` your package.
7476
1. **Create an account on (test) PyPI**: You will need to create a PyPI account and associated token which provides permissions for you to upload your package.
75-
1. **Publish to PyPI using `hatch publish`**: Once you have completed the above two steps, you are ready to use `hatch` to publish your package!
77+
1. **Publish to PyPI using `hatch publish`**
78+
7679

77-
In this lesson you will learn how to publish your package to PyPI using [Hatch](https://hatch.pypa.io/latest/).
7880
In a future lesson, you will learn how to create an automated
7981
GitHub action workflow that publishes an updated
8082
version of your package to PyPI every time you create a GitHub release.
@@ -121,7 +123,7 @@ Hatch environment, it will automatically install your package into the environme
121123
source "/Path/to/env/here/hatch/env/virtual/pyosPackage/Mk7F5Y0T/sphinx-2i2c-theme/bin/activate"
122124
```
123125

124-
View what's in the environment:
126+
View what's in the environment using `pip list`:
125127

126128
```bash
127129
➜ pip list
@@ -140,19 +142,31 @@ tzdata 2023.4
140142

141143
At any time you can exit the environment using `exit`.
142144

145+
```bash
146+
➜ hatch shell
147+
source "/Users/leahawasser/Library/Application Support/hatch/env/virtual/pyospackage/twO2iQR3/pyospackage/bin/activate"
148+
149+
# Notice here you're in the (pyospackage) environment which is the default
150+
pyosPackage (☊ main) [✎ ×1 ] is 📦 v0.1.4 via 🐍 pyenv (pyospackage)
151+
exit
152+
153+
pyosPackage (☊ main) [✎ ×1 ] is 📦 v0.1.4 via 🐍 pyenv took 43s
154+
155+
```
156+
143157

144158
### Hatch and environments
145159

146160
Behind the scenes when hatch creates a new virtual environment,
147-
by default it uses venv[^venv].
161+
by default it uses venv[^venv] which is the default environment management tool that comes with Python installations.
148162

149-
hatch will:
150-
1. Create a new virtualenv (venv) that is located on your computer. You can customize the location of this environment if you wish ....<where??>
163+
Hatch will:
164+
1. Create a new virtualenv (venv) that is located on your computer.
151165
2. Install your package into the environment in editable mode (similar to `pip install -e`). This means it installs both your project and your project's dependencies as declared in your pyproject.toml file.
152166

153167
## Step 2: Build your package's sdist and wheel distributions
154168

155-
Once you have your development environment setup, you are ready to build your package using Hatch. Remember that building is the process of turning your Python package files into two distribution files:
169+
Once you have your development environment setup, you are ready to build your package using Hatch. Remember that building is the process of turning your Python package file structure into two distribution files:
156170

157171
1. The [wheel distribution](#python-wheel) is a pre-built version of your package. It useful for users as it can be directly installed using a tool such as `pip`. This file has the extension `.whl`.
158172
2. The [source distribution](#python-source-distribution) is the files that make up your package in an unbuilt format. This file will have the extension `.tar.gz`.
@@ -161,7 +175,7 @@ You will use Hatch as a **Front end** tool that builds
161175
your package's sdist and wheel using the [hatchling](https://hatch.pypa.io/latest/) build back-end.
162176
The hatchling build back-end is used because you declared it in your pyproject.toml file in the [previous lesson](1-installable-code).
163177

164-
To build your package run:
178+
To build your package run `hatch build`:
165179

166180
```bash
167181
➜ hatch build
@@ -194,17 +208,17 @@ dist/pyospackage-0.1.0-py3-none-any.whl
194208
### <i class="fa-solid fa-wand-magic-sparkles"></i> Congratulations - you've created your Python package distribution files <i class="fa-solid fa-wand-magic-sparkles"></i>
195209

196210
You've now built your Python package and created your package distribution files. The next step is to setup
197-
your account on PyPI so you can publish your package.
211+
your account on testPyPI so you can publish your package.
198212

199213
## Step 3. Setup your test PyPI account
200214

201-
Next, you'll setup an account on test PyPI. Remember that you
202-
are using test PyPI here instead of the real PyPI as a way to
215+
Next, you'll setup an account on Test PyPI. Remember that you
216+
are using test PyPI here instead of the PyPI as a way to
203217
safely learn how to publish a package without stressing the
204218
real PyPI's servers.
205219

206-
:::{admonition} Test vs. real PyPI
207-
If you have a package that you are confident belongs on the real PyPI, all of the steps below will also work for you if you replace test.pypi.org with pypi.org wherever it appears.
220+
:::{admonition} Test PyPI vs. PyPI
221+
If you have a package that you are confident belongs on PyPI, all of the steps below will also work for you. When you publish using Hatch, you will call `hatch publish` to publish directly to PyPI instead of `hatch publish -r test` which publishes to Test PyPI.
208222
:::
209223

210224
1. [Open up a web browser and go to the test PyPI website](https://test.pypi.org/).
@@ -236,7 +250,8 @@ use a backup device that only you can access to validate that the person logging
236250

237251
This matters on PyPI because someone could login to your account and upload a version of your package that has security issues. These issues will then impact all of your users when they download and install that version of the package.
238252

239-
2-factor authentication is now required for authentication on PyPI.
253+
2-factor authentication is required for PyPI authentication
254+
as of 1 January 2024.
240255
:::
241256

242257
## Step 4. Create a package upload token
@@ -260,24 +275,23 @@ It's ideal to create a package-specific token. When you create an account wide t
260275
* When you create your token, be sure to copy the token value and store it in a secure place before closing that browser.
261276

262277

278+
Your token should look something like this:
279+
280+
`pypi-abunchofrandomcharactershere...`
263281

282+
It should start with `pypi` followed by a dash and a bunch of characters.
264283

265284
### Upload to PyPI using Hatch
266285

267-
Once you have the token in a safe place, you are ready to publish to
286+
Once you have your token, you are ready to publish to
268287
PyPI.
269288

289+
* Run `hatch publish -r test`
270290

271-
Your token should look something like this:
272-
273-
`pypi-abunchofrandomcharactershere...`
274-
275-
1. Finally run `hatch publish -r test`
276-
277-
-r stands for repository. In this case because you are publishing to test-PyPI you will use `-r test`. Hatch will then ask for a username and credentials.
291+
`-r` stands for repository. In this case because you are publishing to test-PyPI you will use `-r test`. Hatch will then ask for a username and credentials.
278292

279-
* Add the word `__token__` for your username.
280-
* Paste your PyPI token value in for the credential values.
293+
* Add the word `__token__` for your username. This tells Test PyPI that you are using a token value rather than a username.
294+
* Paste your PyPI token value in at the `Enter your credentials` prompt:
281295

282296
```bash
283297
❯ hatch publish -r test

0 commit comments

Comments
 (0)