Skip to content

Commit a9ac65f

Browse files
committed
add docs about the support for Hatch Libraries, by using the hatch-polylith-bricks build hook plugin
1 parent d7ccf98 commit a9ac65f

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

docs/deployment.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,13 @@ pip install the-built-artifact.whl
4242

4343
### Packaging a Library
4444

45-
__NOTE:__ only supported for Poetry.
45+
The _Python tools for the Polylith Architecture_ has support for building libraries to be published at PyPI,
46+
even if it isn't the main use case.
4647

47-
_Hatch support for packaging libraries is currently being developed._
48-
49-
The plugin has support for building libraries to be published at PyPI, even if it isn't the main use case.
50-
But why? By default, the code in one library will share the same top namespace with other libraries that are
51-
built from the same Polylith Monorepo.
52-
53-
To solve this, there's a feature available that will organize code according to a custom top namespace and re-write the imports.
48+
Important note: by default, the code in one library will share the same top namespace with other libraries that are
49+
built from the same Polylith Monorepo. To solve this, there's a feature available that will organize code according to a custom top namespace and re-write the imports.
5450

51+
#### Poetry
5552
You can choose a custom namespace to be used in the build process, by using the `--with-top-namespace` flag.
5653
This is available for __Python 3.9__ and above.
5754

@@ -61,7 +58,26 @@ The `build-project` command, with a custom top namespace:
6158
poetry build-project --with-top-namespace my_custom_namespace
6259
```
6360

64-
By using the `--with-top-namespace` flag, the built artifact will look something like this:
61+
#### Hatch
62+
There is a Build Hook plugin for Polylith - `hatch-polylith-bricks` - that is added like this:
63+
``` toml
64+
[build-system]
65+
requires = ["hatchling", "hatch-polylith-bricks"]
66+
build-backend = "hatchling.build"
67+
```
68+
69+
As described in the [Projects & pyproject.toml](projects.md) section,
70+
the project-specific bricks are added in the `[tool.polylith.bricks]` section for libraries.
71+
72+
A custom top namespace is defined in the hook configuration of `pyproject.toml`:
73+
74+
``` toml
75+
[tool.hatch.build.hooks.polylith-bricks]
76+
top-namespace = "my_custom_namespace"
77+
```
78+
79+
#### Result
80+
By using the Poetry build-project flag or the Hatch Build Hook, the built artifact will look something like this:
6581
```shell
6682
my_custom_namespace/
6783
/my_package

docs/projects.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,26 @@ Bricks are added in the _tool.hatch.build.force-include_ section:
5757

5858
The `bases` and `components` folders are located at the workspace root.
5959
The project-specific `pyproject.toml` file is located in a subfolder of the `projects` folder.
60+
61+
62+
### Library setup for Hatch: the project-specific pyproject.toml file(s)
63+
There is a special setup to avoid namespace collision,
64+
when more than one library is packaged and published from the same Polylith Workspace.
65+
66+
This includes a Hatch Build Hook plugin that is made for Polylith: `hatch-polylith-bricks`
67+
68+
``` toml
69+
[build-system]
70+
requires = ["hatchling", "hatch-polylith-bricks"]
71+
build-backend = "hatchling.build"
72+
```
73+
74+
Add bricks to a project by using `tool.polylith.bricks`;
75+
``` toml
76+
[tool.polylith.bricks]
77+
"../../bases/my_namespace/my_base" = "my_namespace/my_base"
78+
"../../components/my_namespace/my_component" = "my_namespace/my_component"
79+
"../../components/my_namespace/my_other_component" = "my_namespace/my_other_component"
80+
```
81+
82+
NOTE: this setup works for other artifacts too, but also needs the `hatch-polylith-bricks` plugin.

0 commit comments

Comments
 (0)