You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* emphasize that we recommended the trusted publisher github action for most maintainers
5
7
6
-
1. How to structure your code into a package like format that can be installed into a Python environment.
7
-
2. How to add a `README` and `LICENSE` file to your package
8
-
3. How to setup your `pyproject.toml` file with all of the metadata that PyPI requires and also metadata that will be helpful for users to find your package.
8
+
TODO: Go back to pyproj toml lesson and add a dev dependencies section with build and twine so they can just pip install -e .[dev] into their environment and be done
9
9
10
-
If you have gone through all of the above lessons, you are now ready to
11
-
build your package's distribution files which are needed for you to publish
12
-
to PyPI. Here, you will learn:
10
+
`pip install build`
11
+
-->
13
12
14
-
* How to set up your account and package on PyPI and
15
-
* How to manually publish to (test) PyPI using [twine](https://twine.readthedocs.io/en/stable/).
16
13
17
-
In a followup lesson, you will learn how to automate publishing to PyPI using GitHub actions.
14
+
In the previous lessons, you've learned:
18
15
16
+
1. How to make your code pip installable.
17
+
2. How to add a `README`, `LICENSE` & `CODE of CONDUCT` file file to your package
18
+
3. How to setup your `pyproject.toml` file to support publishing on PyPI.
19
19
20
20
:::{admonition} Learning Objectives
21
21
:class: tip
22
22
23
23
In this lesson you will learn how to:
24
24
25
-
- How to build your package's sdist and wheel distributions
25
+
- How to build your package's source (sdist) and wheel distributions
26
26
- Setup an account on testPyPI (the process is similar for the real PyPI)
27
-
- Publish your package to testPyPI
27
+
- Publish your package to testPyPI using [twine](https://twine.readthedocs.io/en/stable/)
28
28
29
29
Once your package is on PyPI you can then easily publish it to conda-forge
30
30
using the [grayskull](https://conda.github.io/grayskull/) tool. You do not need to build the package specifically
31
31
for conda, conda-forge will build from your PyPI source distribution file (sdist). You will learn how to publish to conda-forge in the [next lesson](7-publish-conda-forge.md).
32
32
33
+
In a followup lesson, you will learn how to automate publishing to PyPI using GitHub actions.
33
34
:::
34
35
35
36
:::{figure-md} build-workflow-tutorial
@@ -41,9 +42,7 @@ You need to build your Python package in order to publish it to PyPI (or Conda).
@@ -57,7 +56,7 @@ The steps for publishing on test PyPI vs. real PyPI are the same with the
57
56
exception of a different url. Thus, in this lesson you will use testPyPI
58
57
to practice and learn.
59
58
60
-
<!-- in xx lesson, you will learn how to setup an automated release workflow on GitHub
59
+
<!--Add when this lesson is created - in xx lesson, you will learn how to setup an automated release workflow on GitHub
61
60
using GitHub actions that will automate the PyPI publication process whenever
62
61
you create a new software release. -->
63
62
@@ -125,8 +124,7 @@ files. This process is known as building your package.
125
124
126
125
127
126
128
-
<!-- ?? TODO: Go back to pyproj lesson and add a dev dependencies with build and twine?
129
-
`pip install build` -->
127
+
130
128
131
129
3. You are now ready to build your package! Note that here you are using the [PyPA build tool](https://github.com/pypa/build) as a "Front end" tool that builds
132
130
your package's sdist and wheel using the hatchling build back end. Remember that you defined your build backend here in the build system table of your `pyproject.toml` file. So build knows to use [hatchling](https://hatch.pypa.io/latest/).
@@ -175,7 +173,7 @@ lesson.
175
173
You've now created your package distribution. You're officially on
176
174
your way to publishing your package on PyPI.
177
175
178
-
## 2. Setup your testPyPI account
176
+
## Step 2. Setup your testPyPI account
179
177
180
178
Next, you'll setup an account on `testPyPI`. Remember that you
181
179
are using testPyPI here instead of the real PyPI as a way to
@@ -212,7 +210,7 @@ While you don't have to setup 2-factor authentication, we strongly
212
210
suggest that you do so.
213
211
:::
214
212
215
-
## 3. Create a package upload token
213
+
## Step 3. Create a package upload token
216
214
217
215
To upload your package to PyPI, you will need to create a token. Ideally
218
216
this token is specific to the package that you are publishing.
@@ -269,6 +267,7 @@ NOTE: the `.pypirc` file stores your token in plain text format. Thus, in anothe
269
267
:::
270
268
271
269
270
+
:::{admonition} using a .pypirc file if your always publishing manually
272
271
### Create your `.pypirc` file with authentication information
273
272
274
273
To create your `.pypirc` file, do the following.
@@ -297,6 +296,8 @@ Save the file and then check that it looks correct in bash using the `cat` comma
297
296
$ cat ~/.pypirc
298
297
```
299
298
299
+
:::
300
+
300
301
Now, install twine:
301
302
302
303
::::{tab-set}
@@ -436,6 +437,23 @@ you wish to install your newly published package in.
436
437
::::
437
438
438
439
440
+
:::{admonition} The value of end-to-end tools like hatch, flit and poetry
441
+
In this lesson we are using core tools including:
442
+
443
+
* hatchling
444
+
* PyPA's build
445
+
* twine
446
+
447
+
to build and publish your package to PyPI.
448
+
449
+
End-to-end packaging tools such as Hatch, PDM, Poetry and
450
+
Flit can manage all of the above steps but have to be
451
+
configured.
452
+
453
+
For example, while twine users a `.pypirc` file, Hatch will cache your PyPI token information to make publishing to PyPI from your computer easier. Be sure the read the documentation for any end-to-end publication tool that you chose to use.
454
+
:::
455
+
456
+
439
457
<!-- TODO: venv will always be different for windows - do we need a third tab?? Also is conda different on windows? i forget -->
440
458
441
459
<!--TODO: teach them to setup trusted publisher for actions... in the actions lesson
@@ -455,7 +473,8 @@ related to PyPI publication.
455
473
You will learn how to create the automated trusted publisher workflow in a followup lesson.
456
474
457
475
458
-
### If you want to use a manual token-based publication workflow
476
+
### OPTIONAL: If you want to use a manual token-based publication workflow
477
+
459
478
If you plan to use your token regularly to publish to PyPI, we strongly recommend going through the above steps again to create
460
479
a token specific to your new package.
461
480
@@ -470,22 +489,6 @@ To do this:
470
489
471
490
And you're all done!
472
491
473
-
:::{admonition} The value of end-to-end tools like hatch, flit and poetry
474
-
In this lesson we are using core tools including:
475
-
476
-
* hatchling
477
-
* PyPA's build
478
-
* twine
479
-
480
-
to build and publish your package to PyPI.
481
-
482
-
End-to-end packaging tools such as Hatch, PDM, Poetry and
483
-
Flit can manage all of the above steps but have to be
484
-
configured.
485
-
486
-
For example, while twine users a `.pypirc` file, Hatch will cache your PyPI token information to make publishing to PyPI from your computer easier. Be sure the read the documentation for any end-to-end publication tool that you chose to use.
487
-
:::
488
-
489
492
## You have published your package to (test) PyPI!
490
493
491
494
Congratulations. You have now successfully published your package to testPyPI. If you have a package that is ready for real-world use on the real pyPi, then you can follow the same steps to publish it on PyPI.org .
0 commit comments