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
Copy file name to clipboardExpand all lines: tutorials/get-to-know-hatch.md
+101-27
Original file line number
Diff line number
Diff line change
@@ -1,50 +1,121 @@
1
-
# Get to know Hatch
1
+
# Get to Know Hatch
2
2
3
-
Our Python packaging tutorials use the tool Hatch.
4
-
In this tutorial, you will install and get to know Hatch a bit more before starting to use it.
3
+
Our Python packaging tutorials use the tool
4
+
[Hatch](https://hatch.pypa.io/latest/). While there are [many great packaging
5
+
tools](/package-structure-code/python-package-build-tools) out there, we have
6
+
selected Hatch because:
7
+
8
+
1. It is an end-to-end tool that supports most of the steps required to create
9
+
a quality Python package. Beginners will have fewer tools to learn if they
10
+
use Hatch.
11
+
2. It supports different build back-ends if you ever need to compile code in
12
+
other languages.
13
+
3. As a community, pyOpenSci has decided that Hatch is a user-friendly tool that
14
+
supports many different scientific Python use cases.
15
+
16
+
In this tutorial, you will install and get to know Hatch a bit more before
17
+
starting to use it.
18
+
19
+
You need two things to successfully complete this tutorial:
20
+
21
+
1. You need Python installed.
22
+
2. You need Hatch installed.
23
+
24
+
:::{important}
25
+
If you don't already have Python installed on your computer, Hatch will do it
26
+
for you when you install Hatch.
27
+
:::
5
28
6
29
## Install Hatch
7
-
To begin, install Hatch from the command line using [pipx](https://pipx.pypa.io/stable/)
30
+
31
+
To begin, follow the operating-system-specific instructions below to install
32
+
Hatch.
33
+
34
+
::::{tab-set}
35
+
36
+
:::{tab-item} MAC
37
+
38
+
Follow the instructions [here](https://hatch.pypa.io/latest/install/#installers).
39
+
40
+
* Download the latest GUI installer for MAC [hatch-universal.pkg](https://github.com/pypa/hatch/releases/latest/download/hatch-universal.pkg).
41
+
* Run the installer and follow the setup instructions.
42
+
* If your terminal is open, then restart it.
43
+
44
+
:::
45
+
46
+
:::{tab-item} Windows
47
+
48
+
* In your browser, download the correct `.msi` file for your system:
* Run your downloaded installer file and follow the on-screen instructions.
51
+
52
+
:::
53
+
54
+
:::{tab-item} Linux
55
+
56
+
We suggest that you install Hatch using pipx on Linux.
57
+
however, if you prefer another method, check out the [Hatch installation documentation](https://hatch.pypa.io/latest/install/) for other methods.
8
58
9
59
```bash
10
-
pipx install hatch
60
+
# First install pipx
61
+
> apt install pipx
62
+
# Then install hatch using pipx
63
+
> pipx install hatch
11
64
```
12
65
13
-
:::{tip}
14
-
Hatch can also be installed directly using `pip` or `conda`, but we encourage you to use `pipx`.
15
-
This is because `pipx` will ensure that your package is available across all of your Python
16
-
environments on your computer rather than just in the environment that you install it into.
17
-
If you install hatch this way you will have to take care that the environment it is installed into
18
-
is activated for the command to work.
19
66
:::
67
+
::::
68
+
69
+
### Check that hatch installed correctly
20
70
21
-
You can check that hatch is working properly by issuing a simple command to get the version
71
+
Once you have completed the installation instructions above, you can open your
72
+
terminal, and make sure that Hatch installed correctly using the command below:
22
73
23
74
```bash
24
75
hatch --version
25
76
# Hatch, version 1.9.4
26
77
```
27
78
28
-
Note the version numbers will likely be different
79
+
*Note the version number output of `hatch --version` will likely be
80
+
different from the output above in this tutorial.*
29
81
30
-
## Configure hatch
82
+
:::{tip}
83
+
Hatch can also be installed directly using pip or conda. We encourage you to
84
+
follow the instructions above because we have found that the Hatch installers
85
+
for Windows and Mac are the easiest and most efficient.
86
+
87
+
Our Linux users have found success installing Hatch with pipx if they already
88
+
use apt install.
89
+
90
+
Both approaches (using a graphical installer on Windows/Mac and pipx) ensure
91
+
that you have Hatch installed globally. A global install means that Hatch is
92
+
available across all of your Python environments on your computer.
93
+
:::
31
94
32
-
Once you have installed Hatch, you will want to customize the configuration.
95
+
## Configure Hatch
33
96
34
-
Hatch stores your configuration information in a [`config.toml` file](https://hatch.pypa.io/latest/config/project-templates/).
97
+
Once you have installed Hatch, you can customize its configuration. This
98
+
includes setting the default name and setup for every package you create. While
99
+
this step is not required, we suggest that you do it.
35
100
36
-
While you can update the `config.toml` file through the command line,
37
-
it might be easier to look at it and update it in a text editor if you are using it for the first time.
101
+
Hatch stores your configuration in a [`config.toml` file](https://hatch.pypa.io/latest/config/project-templates/).
38
102
39
-
### Step 1: Open and edit your `config.toml` file
103
+
While you can update the `config.toml` file through the command line, it might
104
+
be easier to look at and update it in a text editor if you are using it for the
105
+
first time.
40
106
41
-
To open the config file in your file browser, run the following command in your shell:
107
+
### Step 1: Open and Edit Your `config.toml` File
108
+
109
+
To open the config file in your file browser, run the following command in your
110
+
shell:
42
111
43
112
`hatch config explore`
44
113
45
-
This will open up a directory window that will allow you to double click on the file and open it in your favorite text editor.
114
+
This will open up a directory window that allows you to double-click on the file
115
+
and open it in your favorite text editor.
46
116
47
-
You can also retrieve the location of the Hatch config file by running the following command in your shell:
117
+
You can also retrieve the location of the Hatch config file by running the
118
+
following command in your shell:
48
119
49
120
```bash
50
121
hatch config find
@@ -53,7 +124,9 @@ hatch config find
53
124
54
125
### Step 2 - update your email and name
55
126
56
-
Once the file is open, update the [template] table of the `config.toml` file with your name and email. This information will be used in any `pyproject.toml` metadata files that you create using Hatch.
127
+
Once the file is open, update the [template] table of the `config.toml` file
128
+
with your name and email. This information will be used in any `pyproject.toml`
129
+
metadata files that you create using Hatch.
57
130
58
131
```toml
59
132
[template]
@@ -110,7 +183,8 @@ src-layout = true
110
183
111
184
Also notice that the default license option is MIT. While we will discuss
112
185
license in more detail in a later lesson, the MIT license is the
113
-
recommended permissive license from [choosealicense.com](https://www.choosealicense.com) and as such we will
186
+
recommended permissive license from
187
+
[choosealicense.com](https://www.choosealicense.com) and as such we will
114
188
use it for this tutorial series.
115
189
116
190
You are of course welcome to select another license.
@@ -125,7 +199,9 @@ Once you have completed the steps above run the following command in your shell.
125
199
126
200
`hatch config show`
127
201
128
-
`hatch config show` will print out the contents of your `config.toml` file in your shell. look at the values and ensure that your name, email is set. Also make sure that `tests=false`.
202
+
`hatch config show` will print out the contents of your `config.toml` file in
203
+
your shell. look at the values and ensure that your name, email is set. Also
204
+
make sure that `tests=false`.
129
205
130
206
## Hatch features
131
207
@@ -141,14 +217,12 @@ and maintaining your Python package easier.
141
217
142
218
A few features that Hatch offers
143
219
144
-
145
220
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
146
221
))
147
222
2. It will help you by storing configuration information for publishing to PyPI after you've entered it once.
148
223
149
224
Use `hatch -h` to see all of the available commands.
150
225
151
-
152
226
## What's next
153
227
154
228
In the next lesson you'll learn how to package and make your code installable using Hatch.
0 commit comments