Skip to content

Commit db69973

Browse files
authored
Merge pull request #3 from DavidVujic/hatch-docs
docs: add Hatch-specific documentation
2 parents 3ac4b0c + 4635cf5 commit db69973

File tree

11 files changed

+278
-22
lines changed

11 files changed

+278
-22
lines changed

docs/commands.md

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
## Create a workspace
66
This will create a Polylith workspace, with a basic Polylith folder structure.
77

8+
### Poetry
89
``` shell
910
poetry poly create workspace --name my_example_namespace --theme loose
1011
```
1112

13+
### Hatch
14+
``` shell
15+
hatch run poly create workspace --name my_example_namespace --theme loose
16+
```
17+
1218
### Options
1319
`--name` (required) the workspace name, that will be used as the single top namespace for all bricks. __Choose the name wisely.__
1420
Have a look in [PEP-423](https://peps.python.org/pep-0423/#respect-ownership) for naming guidelines.
@@ -32,10 +38,16 @@ These are added for any initial commits of the folder structure, and can safely
3238
## Create a component
3339
This command will create a component - i.e. a Python package in a namespaced folder.
3440

41+
### Poetry
3542
``` shell
3643
poetry poly create component --name my_example_component
3744
```
3845

46+
### Hatch
47+
``` shell
48+
hatch run poly create component --name my_example_component
49+
```
50+
3951
### Options
4052
`--name` (required) the name of the component.
4153

@@ -45,10 +57,16 @@ It will also be added in the README, when enabled in the configuration. See [con
4557
## Create a base
4658
This command will create a base - i.e. a Python package in a namespaced folder.
4759

60+
### Poetry
4861
``` shell
4962
poetry poly create base --name my_example_base
5063
```
5164

65+
### Hatch
66+
``` shell
67+
hatch run poly create base --name my_example_base
68+
```
69+
5270
### Options
5371
`--name` (required) the name of the base.
5472

@@ -58,10 +76,16 @@ It will also be added in the README, when enabled in the configuration. See [con
5876
## Create a project
5977
This command will create a project - i.e. a pyproject.toml in a project folder.
6078

79+
### Poetry
6180
``` shell
6281
poetry poly create project --name my_example_project
6382
```
6483

84+
### Hatch
85+
``` shell
86+
hatch run poly create project --name my_example_project
87+
```
88+
6589
### Options
6690
`--name` (required) the name of the project.
6791

@@ -71,20 +95,32 @@ poetry poly create project --name my_example_project
7195
## Info
7296
Show info about the workspace:
7397

98+
### Poetry
7499
``` shell
75100
poetry poly info
76101
```
77102

103+
### Hatch
104+
``` shell
105+
hatch run poly info
106+
```
107+
78108
### Options
79109
`--short` Display a view that is better adjusted to Workspaces with many projects.
80110

81111
## Diff
82112
Shows what has changed since the most recent stable point in time:
83113

114+
### Poetry
84115
``` shell
85116
poetry poly diff
86117
```
87118

119+
### Hatch
120+
``` shell
121+
hatch run poly diff
122+
```
123+
88124
The `diff` command will compare the current state of the repository, compared to a `git tag`.
89125
The tool will look for the latest tag according to a certain pattern, such as `stable-*`.
90126
The pattern can be configured in `workspace.toml`.
@@ -94,22 +130,53 @@ It is also useful when running tests for changed bricks only.
94130

95131

96132
### Testing
97-
Example, how to run __pytest__ for changed bricks only:
133+
Example, how to run __pytest__ for changed bricks only.
134+
135+
### Poetry
98136
``` shell
99137
# store the comma-separated list of bricks in a bash variable
100138
changes="$(poetry poly diff --bricks --short)"
101139

102140
# transform it into a pytest query,
103141
# i.e. from "hello,world,something" to "hello or world or something"
104142
query="${changes//,/ or }"
143+
```
144+
145+
Run the test, filtered by keyword expression
105146

106-
# run the test, filtered by keyword expression
147+
``` shell
107148
poetry run pytest -k <<< echo "$query"
149+
```
150+
151+
or run the test, filtered by pytest markers
108152

109-
# or run the test, filtered by pytest markers
153+
``` shell
110154
poetry run pytest -m <<< echo "$query"
111155
```
112156

157+
### Hatch
158+
``` shell
159+
# store the comma-separated list of bricks in a bash variable
160+
changes="$(hatch run poly diff --bricks --short)"
161+
162+
# transform it into a pytest query,
163+
# i.e. from "hello,world,something" to "hello or world or something"
164+
query="${changes//,/ or }"
165+
```
166+
167+
Run the test, filtered by keyword expression
168+
169+
``` shell
170+
hatch run pytest -k <<< echo "$query"
171+
```
172+
173+
or run the test, filtered by pytest markers
174+
175+
``` shell
176+
hatch run pytest -m <<< echo "$query"
177+
178+
```
179+
113180
### Options
114181
`--short` Useful for determining what projects has been affected by the changes in CI.
115182

@@ -118,13 +185,20 @@ poetry run pytest -m <<< echo "$query"
118185
`--since` Useful for displaying changes since a `stable` or `release` tag.
119186

120187
Example:
188+
#### Poetry
121189
``` shell
122190
poetry poly diff --since release
123191
```
124192

193+
#### Hatch
194+
``` shell
195+
hatch run poly diff --since release
196+
```
197+
125198
## Libs
126199
Show info about the third-party libraries used in the workspace:
127200

201+
### Poetry
128202
``` shell
129203
poetry poly libs
130204
```
@@ -135,6 +209,12 @@ If missing, there is a Poetry command available:
135209
poetry lock --directory path/to-project
136210
```
137211

212+
### Hatch
213+
``` shell
214+
hatch run poly libs
215+
```
216+
217+
138218
### Options
139219
`--directory`
140220
Show info about libraries used in a specific project.
@@ -155,13 +235,18 @@ Using `--alias opencv-python=cv2` will make the command treat the alias as a thi
155235
## Check
156236
Validates the Polylith workspace, checking for any missing dependencies (bricks and third-party libraries):
157237

238+
### Poetry
158239
``` shell
159240
poetry poly check
160241
```
161242

162-
This feature is built on top of the `poetry poly libs` command,
163-
and expects a `poetry.lock` of a project to be present.
243+
This feature is built on top of the `poly libs` command,
244+
and for expects a `poetry.lock` of a `Poetry` project to be present.
164245

246+
### Hatch
247+
``` shell
248+
hatch run poly check
249+
```
165250

166251
### Options
167252
`--directory`
@@ -183,10 +268,16 @@ Using `--alias opencv-python=cv2` will make the command treat the alias as a thi
183268
## Sync
184269
Keep projects in sync with the actual usage of bricks in source code.
185270

271+
### Poetry
186272
``` shell
187273
poetry poly sync
188274
```
189275

276+
### Hatch
277+
``` shell
278+
hatch run poly sync
279+
```
280+
190281
This feature is useful for keeping projects in sync. The command will analyze code and add any missing bricks to the projects, including the development project.
191282

192283
- projects: will add missing bricks to the project specific _pyproject.toml_, when imported by any of the already added bricks.

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The Polylith Workspace is configured using a __workspace.toml__ file at the root
44

55
A default configuration is created when running the `poetry poly create workspace` command (see the [commands](commands.md) section).
66

7-
An example of a workspace configuration:
7+
Example of a workspace configuration:
88

99
``` toml
1010
[tool.polylith]

docs/dependencies.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Each project has its own `pyproject.toml`,
44
where the project-specific dependencies are defined.
55

66
## Bricks (your Python code)
7-
Bricks are added to the `packages` section of `[tool.poetry]`,
7+
Bricks are added to the `packages` section of `[tool.poetry]` or the `[tool.hatch.build.force-include]`,
88
described in [Projects & pyproject.toml](projects.md).
99

1010
To keep a project up-to-date with needed bricks, there is a `poly sync` command available.
1111
Usage is described in [commands](commands.md). The command is there for convenience, you can also add the bricks manually.
1212

1313
## Libraries (third-party dependencies)
14-
The recommended workflow for Polylith is to use `poetry add` to install the needed libraries to the __Development__ `pyproject.toml`.
14+
The recommended workflow for Polylith is to use `poetry add`, or manually adding, to install the needed libraries to the __Development__ `pyproject.toml`.
1515
The Development `pyproject.toml` is located at the Workspace root.
1616
The Development environment should have __all__ dependencies added: all bricks and all the third-party libraries.
1717
The dev-dependencies (such as Mypy, Black, Flake8, Ruff etc.) are also added to the Development `pyproject.toml`.
@@ -27,6 +27,12 @@ Use the `poly libs` and/or `poly check` [command](commands.md) to verify all tha
2727
Both commands support the `--directory` option (coming from Poetry).
2828
This means that you can run the commands from the workspace root, but for a specific project:
2929

30+
### Poetry
3031
``` shell
3132
poetry poly check --directory projects/my-project
3233
```
34+
35+
### Hatch
36+
``` shell
37+
hatch run poly check --directory projects/my-project
38+
```

docs/deployment.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Packaging & deploying
22

3+
## Poetry
34
Packaging and deploying Polylith projects is done by using the Poetry Multiproject plugin command (see [installation](installation.md)).
45

56
The `poetry build-project` command will make it possible to use relative package includes as how components and bases are added to Python Polylith projects.
67
Relative includes are currently not possible by default in __Poetry__, that is where the __Multiproject__ plugin comes in.
78

9+
## Hatch
10+
Hatch supports relative includes via the `force-include` configuration. Nothing extra needed!
11+
812
## Packaging
913
To collect the components and bases that are needed for a specific project, the tool introduces a _build_ step.
1014
The tool will build a _wheel_ and an _sdist_ from the source code of a project.
@@ -13,12 +17,21 @@ This is the preferred way for Polylith projects.
1317

1418
### Packaging a service or app
1519

20+
#### Poetry
1621
``` shell
1722
poetry build-project --directory path/to/project
1823
```
1924

25+
#### Hatch
26+
``` shell
27+
cd path/to_project
28+
29+
hatch build
30+
```
31+
32+
2033
This command will create a project specific _dist_ folder containing a _wheel_ and an _sdist_.
21-
You can use the default __poetry build__ options with this command too.
34+
You can use the available __build__ options with this command too.
2235

2336
## Deploying
2437
You can use the built artifacts to install your service in your preffered way, just by running
@@ -28,6 +41,11 @@ pip install the-built-artifact.whl
2841
```
2942

3043
### Packaging a Library
44+
45+
__NOTE:__ only supported for Poetry.
46+
47+
_Hatch support for packaging libraries is currently being developed._
48+
3149
The plugin has support for building libraries to be published at PyPI, even if it isn't the main use case.
3250
But why? By default, the code in one library will share the same top namespace with other libraries that are
3351
built from the same Polylith Monorepo.

docs/ide.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,30 @@ extraPaths = ["bases", "components"]
3838

3939
## .venv
4040
It is recommended to create the virtual environment locally, for a great code editor experience.
41-
By default, `Poetry` will create a `venv` outside of the repo. You can override that behaviour by adding a configuration in a `poetry.toml` file:
41+
By default, both `Poetry` and `Hatch` will create a `venv` outside of the repo.
42+
You can override that behaviour by adding a configuration.
43+
44+
### Poetry
45+
Add this in a `poetry.toml` file:
4246

4347
``` toml
4448
[virtualenvs]
4549
path = ".venv"
4650
in-project = true
4751
```
4852

53+
### Hatch
54+
``` toml
55+
[tool.hatch.envs.default]
56+
type = "virtual"
57+
path = ".venv"
58+
```
59+
60+
4961
## PyCharm
5062
Make sure that you have a local virtual environment configuration (see above).
5163

52-
Run `poetry install` in a shell.
64+
Run `poetry install` or `hatch env create` in a shell.
5365

5466
This will install the dependencies, and make the environment aware of the `bases` and `components` folders.
5567
PyCharm will ask about what interpreter to use when opening a Python file. Make sure to choose the local one in the `.venv` folder.

docs/index.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ In short, Polylith is about:
4343
- Keeping it simple
4444

4545
## Polylith for Python?
46-
The __Python tools for the Polylith Architecture__ is built as a __Poetry__ plugin. The plugin will add Polylith specific features to Poetry.
46+
The __Python tools for the Polylith Architecture__ is available as two options:
47+
48+
- A __Poetry__ plugin. The plugin will add Polylith specific features to Poetry.
49+
- ⭐ New! ⭐ A standalone CLI, currently supporting __Hatch__ (and Poetry).
4750

4851
### Use cases
4952

@@ -67,7 +70,7 @@ See [The Polylith Workspace](workspace.md) for how such a structure looks like.
6770

6871
![polylith developer experience](img/polylith-and-the-developer-experience.png)
6972

70-
### It is all about the bricks
73+
### Simple is better
7174
The main takeaway is to view code as small, reusable bricks, that ideally does one thing only.
7275
A brick is not the same thing as a library. So, what's the difference? Well, a library is a full blown feature. A brick can be a single function, or a parser. It can also be a thin wrapper around a third party tool.
7376

docs/installation.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Installation
22

3-
## Install Poetry & plugins
4-
With the `Poetry` version 1.2 or later installed, you can add plugins.
5-
6-
Add the [Multiproject](https://github.com/DavidVujic/poetry-multiproject-plugin) plugin,
3+
## Poetry
4+
### Add Poetry plugins
5+
With the `Poetry` version 1.2 or later installed, you can add plugins. First, add the [Multiproject](https://github.com/DavidVujic/poetry-multiproject-plugin) plugin,
76
that will enable the very important __Workspace__ support to Poetry.
87
``` shell
98
poetry self add poetry-multiproject-plugin
@@ -15,3 +14,8 @@ poetry self add poetry-polylith-plugin
1514
```
1615

1716
Done!
17+
18+
## Hatch
19+
20+
No external tools needed other than project-specific dependencies (see the [Projects & pyproject.toml](projects.md) section),
21+
and the (soon released) build plugin to add support for packaging libraries.

0 commit comments

Comments
 (0)