Skip to content
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

[Tuesday july 2 merge] Fix: update hatch install instructions #308

Merged
merged 6 commits into from
Jul 3, 2024
Merged
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
92 changes: 77 additions & 15 deletions tutorials/get-to-know-hatch.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,99 @@
# Get to know Hatch

Our Python packaging tutorials use the tool Hatch.
In this tutorial, you will install and get to know Hatch a bit more before starting to use it.
Our Python packaging tutorials use the tool
[Hatch](https://hatch.pypa.io/latest/). While there are [many great packaging](/package-structure-code/python-package-build-tools)
tool options out there, we have selected to teach Hatch because

1. It is an end-to-end tool that supports most of the steps required to create a quality Python package. Beginners will have fewer tools to learn if they use Hatch.
1. It supports different build back-ends if you ever need to compile code in other languages.
1. As a community, pyOpenSci has decided that Hatch is a user-friendly tool that supports many different scientific Python use cases.

In this tutorial, you will install and get to know Hatch a bit more before
starting to use it.

You need two things to successfully complete this tutorial:

1. You need Python installed.
2. You need Hatch installed.

:::{important}
If you don't already have Python installed, Hatch will do it for you when you
install Hatch.

Hatch uses [UV](https://astral.sh/blog/uv) to install Python. UV is a super
fast Python package installer and resolver written in Rust.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not true; the Python installation logic is custom (I don't even think UV supports that yet). There is however an option to use UV for package installation.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh gosh - ok i'll remove that entire breakout as it's not relevant for someone just getting started. I didn't realize the Python installation was custom, @ofek thank you for looking at this!

i need to spend some time reading more about UV and Pixie. as those tools are mixed up in my head right now (probably because i haven't used them yet).

Copy link
Contributor

Choose a reason for hiding this comment

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

In the context of Hatch, UV is used (if that option is enabled) solely as a replacement for pip and virtualenv.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok got it. thank you so much @ofek .

:::

## Install Hatch
To begin, install Hatch from the command line using [pipx](https://pipx.pypa.io/stable/)

To begin, follow the operating-specific instructions below to install Hatch.

::::{tab-set}

:::{tab-item} MAC

Follow the instructions [here](https://hatch.pypa.io/latest/install/#installers).

* Download the latest GUI installer for MAC [hatch-universal.pkg](https://github.com/pypa/hatch/releases/latest/download/hatch-universal.pkg).
* Run the installer and follow the setup instructions.
* If your terminal is open, then restart it.

:::

:::{tab-item} Windows

* In your browser, download the correct `.msi` file for your system:
[hatch-x64.msi](https://github.com/pypa/hatch/releases/latest/download/hatch-x64.msi)
* Run your downloaded installer file and follow the on-screen instructions.

:::

:::{tab-item} Linux

We suggest that you install Hatch using pipx on Linux.
however, if you prefer another method, check out the [Hatch installation documentation](https://hatch.pypa.io/latest/install/) for other methods.

```bash
pipx install hatch
# First install pipx
> apt install pipx
# Then install hatch using pipx
> pipx install hatch
```

:::{tip}
Hatch can also be installed directly using `pip` or `conda`, but we encourage you to use `pipx`.
This is because `pipx` will ensure that your package is available across all of your Python
environments on your computer rather than just in the environment that you install it into.
If you install hatch this way you will have to take care that the environment it is installed into
is activated for the command to work.
:::
::::

### Check that hatch installed correctly

You can check that hatch is working properly by issuing a simple command to get the version
Once you have completed the installation instructions above, you can open your terminal, and make sure that Hatch installed correctly using
the command below:

```bash
hatch --version
# Hatch, version 1.9.4
```

Note the version numbers will likely be different
*Note the version number output of `hatch --version` will likely be
different from the output above in this tutorial.*

:::{tip}
Hatch can also be installed directly using `pip` or `conda`. We
encourage
you to follow the instructions above because we have found that the Hatch installers for Windows and Mac are easiest and most efficient.

Our Linux users have found success installing Hatch with `pipx` if they
already use `apt install`.

Both approaches (using a graphical installer on Windows / MAC and `pipx`) ensure that you have Hatch installed
globally. A global install means that Hatch is available
across all of your Python environments on your computer.
:::

## Configure hatch

Once you have installed Hatch, you will want to customize the configuration.
Once you have installed Hatch, you can customize the configuration which
includes the default name and setup that you want to have for every
package that you create using Hatch. While this step is not required, we suggest it.

Hatch stores your configuration information in a [`config.toml` file](https://hatch.pypa.io/latest/config/project-templates/).

Expand Down Expand Up @@ -141,14 +205,12 @@ and maintaining your Python package easier.

A few features that Hatch offers


1. it will convert metadata stored in a `setup.py` or `setup.cfg` file to a pyproject.toml file for you (see [Migrating setup.py to pyproject.toml using Hatch](setup-py-to-pyproject-toml.md
))
2. It will help you by storing configuration information for publishing to PyPI after you've entered it once.

Use `hatch -h` to see all of the available commands.


## What's next

In the next lesson you'll learn how to package and make your code installable using Hatch.
Loading