Skip to content

Final series lessons - pyproject, code of conduct & license files #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix: update links throughout lessons
  • Loading branch information
lwasser committed Mar 1, 2024
commit ae4a4aa1a7fba6d629bf07924e56e0575fddc28c
26 changes: 20 additions & 6 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Community docs

Publish your docs
```
## _new_ Tutorial series - how to create a Python package
## _new_ Tutorial Series: How to Create a Python Package

The how to create a Python package tutorial series is being developed
by the community now! Join our community review process or watch development of these tutorials in our [Github repo here](https://github.com/pyOpenSci/python-package-guide).
Expand All @@ -67,18 +67,32 @@ by the community now! Join our community review process or watch development of
:gutter: 3

::::{grid-item}

:::{card} ✿ Tutorials ✿
:::{card} ✿ Create a Package Tutorials ✿
:class-card: left-aligned

* [What is a Python package?](/tutorials/intro)
* [Make your code installable](/tutorials/1-installable-code)
* [Publish your package to (test) PyPi](/tutorials/publish-pypi)
* *How to add a README and LICENSE to support publication (coming next!)*
* *How to add metadata to a pyproject.toml file for publication to PyPI.*
* [Publish your package to conda-forge](/tutorials/publish-conda-forge)

:::
::::

::::{grid-item}
:::{card} ✿ Package Metadata Tutorials ✿
:class-card: left-aligned

_The third lesson is currently under review in our [GitHub Repo here](https://github.com/pyOpenSci/python-package-guide/pulls). It will be live by the end of Feb 2024_
* [How to add a README file](/tutorials/add-readme)
* [How to add metadata to a pyproject.toml file for publication to PyPI.](/tutorials/pyproject-toml.md)

:::
::::

::::{grid-item}
:::{card} ✿ Packaging Tool Tutorials ✿
:class-card: left-aligned

* [Introduction to Hatch](/tutorials/get-to-know-hatch)

:::
::::
Expand Down
16 changes: 7 additions & 9 deletions tutorials/1-installable-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,9 @@ file.
[Learn more about the pyproject.toml format here.](../package-structure-code/pyproject-toml-python-package-metadata)
:::

:::{todo}

You will learn more about the `pyproject.toml` format in the
[next lesson when you add additional metadata / information to this file.](5-pyproject-toml.md)
:::
[next lesson when you add additional metadata / information to this file.](pyproject-toml.md)

- Open up the `pyproject.toml` file that Hatch created in your favorite text editor. It should look something like the example below.

Expand Down Expand Up @@ -614,13 +613,12 @@ In the upcoming lessons you will:
* Add more metadata to your `pyproject.toml` file to support PyPI publication.
* learn how to publish to **conda-forge** from **PyPI**.

:::{todo}
This is the content with links once the links are live we can uncomment this and remove the unlinked content above!
* Add a [README file](2-add-readme.md) and [LICENSE](4-add-license-file.md) to your package

* Add a [README file](add-readme.md) and [LICENSE](add-license-coc.md) to your package
* [Add more metadata to your `pyproject.toml`](5-pyproject-toml.md) file to support PyPI publication.
* [Learn how to build your package distribution](6-publish-pypi.md) files (**sdist** and **wheel**) and publish to **test PyPI**.
* Finally you will learn how to publish to **conda-forge** from **PyPI**.
:::
* [Learn how to build your package distribution](publish-pypi) files (**sdist** and **wheel**) and publish to **test PyPI**.
* Finally you will learn how to [publish to **conda-forge**](publish-conda-forge) from **PyPI**.


## Footnotes

Expand Down
25 changes: 8 additions & 17 deletions tutorials/publish-pypi.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Publish your Python package to PyPI

:::{todo}

- emphasize that we recommended the trusted publisher GitHub action for most maintainers
- Make sure they add /dist to their .gitignore file. We have not discussed GitHub workflows anywhere yet. Where does that fit?
- https://hatch.pypa.io/latest/intro/#existing-project <- hatch will migrate from setup.py for you - if we go with hatch then we may want to add this to the installable code lesson
- Should we install hatch with pipx?
:::


```bash
pipx install hatch
Expand Down Expand Up @@ -38,13 +38,8 @@ using [Grayskull](https://conda.github.io/grayskull/).

You will learn how to publish to conda-forge in a future lesson.

:::{todo}
Fix this link once the lesson is published.
You will learn how to publish to conda-forge in the [next lesson](publish-conda-forge).

You will learn how to publish to conda-forge in the [next lesson](7-publish-conda-forge.md).
:::

:::

:::{figure-md} build-workflow-tutorial
<img src="../images/tutorials/publish-package-pypi-conda.png" alt="Graphic showing the high level packaging workflow. On the left you see a graphic with code, metadata and tests in it. Those items all go into your package. An arrow to the right takes you to a build distribution files box. Another arrow to the right takes you to a publish to PyPI box which has an arrow containing sdist and wheel that notes those files go to PyPI for hosting. From PyPI is an arrow containing sdist since you can then connect to conda-forge for an automated build that sends distributions from PyPI to conda-forge." width="700px">
Expand Down Expand Up @@ -191,10 +186,8 @@ You can learn more about
building in the [build page of our packaging guide](../package-structure-code/python-package-distribution-files-sdist-wheel).
:::

:::{todo}
The sdist is important if you wish to [publish
your package to conda-forge](7-publish-conda-forge) which you will learn about in a later lesson.
:::
your package to conda-forge](publish-conda-forge). You will learn about this in a later lesson.

:::{todo}
➜ hatch build
Expand Down Expand Up @@ -232,7 +225,7 @@ Show them how to do this

1. update the project-name in the pyproject.toml file
2. update the module repository directory to be the same
:::
:::

:::{figure-md} build-workflow-tutorial
<img src="../images/tutorials/testpypi-search.png" alt="This is a screenshot of the test PyPI website. At the top in the search bar, you can see the search for pyosPackage. The search return says there were no results for pyosPackage Did you mean probpackage" width="700px">
Expand Down Expand Up @@ -361,14 +354,12 @@ testPyPI as a permanent way to install your package. Test PyPi is a perfect plac
In this lesson you are using Hatch and hatchling to create, build and publish your Python Package. [Click here to learn about other packaging tools in the ecosystem.](../package-structure-code/python-package-build-tools.md)
:::


<!-- TODO: venv will always be different for windows - do we need a third tab?? Also is conda different on windows? i forget -->

<!--TODO: teach them to setup trusted publisher for actions... in the actions lesson
:::{todo}
teach them to setup trusted publisher for actions... in the actions lesson
https://pypi.org/help/#twofa

from PyPI: https://pypi.org/help/#apitoken - You can create a token for an entire PyPI account, in which case, the token will work for all projects associated with that account. Alternatively, you can limit a token's scope to a specific project.
-->
:::

## Package-specific token vs trusted publisher

Expand Down
17 changes: 1 addition & 16 deletions tutorials/pyproject-toml.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
# Make your Python package PyPI ready - pyproject.toml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Predictably, i want to make some adjustments to the ToC structure here - i'll make a PR, but yes! make ToC easy to scan and use hierarchy to group ideas. i rly like this page i just want to make it easier to see how good it is!!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course. i'll read through your comments below and see what i can implement now vs later when you submit a pr!!


:::{todo}
- add a note for hatch - if you want to use dynamic versioning you'll need to add `tool.hatch.version` to the pyproject.toml file.
- TODO: decide how we want to list readme and license? it might make sense to just follow the simplest option and do spdx?
- make sure they add the dev requirements here... including build.
license = { text = "MIT" } that format is a toml inline table https://toml.io/en/v1.0.0#inline-table and it becomes a subtable of the project table

* make sure we have this listing for license
* SPDX for licenses https://spdx.dev/use/overview/
is 2 above enough for examples? should we show a few others?

:::


In [the installable code lesson](2-installable-code), you learned how to add the bare minimum information to a `pyproject.toml` file to make it installable. You then learned how to [publish that bare minimum version of your package to PyPI](publish-pypi.md).

Following that you learned how to add a:
* [README.md](add-readme)
* [LICENSE](add-license-coc) and
* [CODE_OF_CONDUCT](add-coc)

to your package directory.
to the root of your project directory.

To enhance the visibility of your package on PyPI and provide more information
about its compatibility with Python versions, project development status, and
Expand All @@ -29,8 +16,6 @@ file. This
lesson will guide you through the process.


of your GitHub or GitLab repository.

:::{admonition} Learning Objectives
:class: tip

Expand Down