Skip to content

Commit 4e85bda

Browse files
authored
Merge pull request #13 from DavidVujic/add-maturin-docs
Add docs about Maturin
2 parents d8b3ce9 + e937808 commit 4e85bda

8 files changed

+261
-35
lines changed

docs/commands.md

+112-30
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ rye run poly create workspace --name my_example_namespace --theme loose
3030
uv run poly create workspace --name my_example_namespace --theme loose
3131
```
3232

33+
#### Maturin
34+
35+
``` shell
36+
# if not already activated a virtual environment
37+
source .venv/bin/activate
38+
39+
poly create workspace --name my_example_namespace --theme loose
40+
```
41+
3342
### Options
3443
`--name` (required) the workspace name, that will be used as the single top namespace for all bricks. __Choose the name wisely.__
3544
Have a look in [PEP-423](https://peps.python.org/pep-0423/#respect-ownership) for naming guidelines.
@@ -78,6 +87,14 @@ rye run poly create component --name my_example_component
7887
uv run poly create component --name my_example_component
7988
```
8089

90+
#### Maturin
91+
``` shell
92+
# if not already activated a virtual environment
93+
source .venv/bin/activate
94+
95+
poly create component --name my_example_component
96+
```
97+
8198
### Options
8299
`--name` (required) the name of the component.
83100

@@ -112,6 +129,14 @@ rye run poly create base --name my_example_base
112129
uv run poly create base --name my_example_base
113130
```
114131

132+
#### Maturin
133+
``` shell
134+
# if not already activated a virtual environment
135+
source .venv/bin/activate
136+
137+
poly create base --name my_example_base
138+
```
139+
115140
### Options
116141
`--name` (required) the name of the base.
117142

@@ -146,6 +171,14 @@ rye run poly create project --name my_example_project
146171
uv run poly create project --name my_example_project
147172
```
148173

174+
#### Maturin
175+
``` shell
176+
# if not already activated a virtual environment
177+
source .venv/bin/activate
178+
179+
poly create project --name my_example_project
180+
```
181+
149182
### Options
150183
`--name` (required) the name of the project.
151184

@@ -180,11 +213,26 @@ rye run poly info
180213
uv run poly info
181214
```
182215

216+
#### Maturin
217+
``` shell
218+
# if not already activated a virtual environment
219+
source .venv/bin/activate
220+
221+
poly info
222+
```
223+
183224
### Options
184225
`--short` Display a view that is better adjusted to Workspaces with many projects.
185226

186227
## Diff
187-
Shows what has changed since the most recent stable point in time:
228+
Shows what has changed since the most recent stable point in time.
229+
230+
The `diff` command will compare the current state of the repository, compared to a `git tag`.
231+
The tool will look for the latest tag according to a certain pattern, such as `stable-*`.
232+
The pattern can be configured in the Workspace [configuration](configuration.md).
233+
234+
The `diff` command is useful in a CI environment, to determine if a project should be deployed or not.
235+
It is also useful when running tests for changed bricks only.
188236

189237
#### Poetry
190238
``` shell
@@ -211,37 +259,12 @@ rye run poly diff
211259
uv run poly diff
212260
```
213261

214-
The `diff` command will compare the current state of the repository, compared to a `git tag`.
215-
The tool will look for the latest tag according to a certain pattern, such as `stable-*`.
216-
The pattern can be configured in the Workspace [configuration](configuration.md).
217-
218-
The `diff` command is useful in a CI environment, to determine if a project should be deployed or not.
219-
It is also useful when running tests for changed bricks only.
220-
221-
Example:
222-
#### Poetry
223-
``` shell
224-
poetry poly diff --since release
225-
```
226-
227-
#### Hatch
228-
``` shell
229-
hatch run poly diff --since release
230-
```
231-
232-
#### PDM
233-
``` shell
234-
pdm run poly diff --since release
235-
```
236-
237-
#### Rye
262+
#### Maturin
238263
``` shell
239-
rye run poly diff --since release
240-
```
264+
# if not already activated a virtual environment
265+
source .venv/bin/activate
241266

242-
#### Rye
243-
``` shell
244-
uv run poly diff --since release
267+
poly diff
245268
```
246269

247270
### Options
@@ -289,6 +312,14 @@ rye run poly libs
289312
uv run poly libs
290313
```
291314

315+
#### Maturin
316+
``` shell
317+
# if not already activated a virtual environment
318+
source .venv/bin/activate
319+
320+
poly libs
321+
```
322+
292323
### Options
293324
`--directory`
294325
Show info about libraries used in a specific project.
@@ -337,6 +368,14 @@ rye run poly check
337368
uv run poly check
338369
```
339370

371+
#### Maturin
372+
``` shell
373+
# if not already activated a virtual environment
374+
source .venv/bin/activate
375+
376+
poly check
377+
```
378+
340379
### Options
341380
`--directory`
342381
Show info about libraries used in a specific project.
@@ -383,6 +422,14 @@ rye run poly sync
383422
uv run poly sync
384423
```
385424

425+
#### Maturin
426+
``` shell
427+
# if not already activated a virtual environment
428+
source .venv/bin/activate
429+
430+
poly sync
431+
```
432+
386433
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.
387434

388435
- projects: will add missing bricks to the project specific _pyproject.toml_, when imported by any of the already added bricks.
@@ -421,6 +468,14 @@ rye run poly deps
421468
uv run poly deps
422469
```
423470

471+
#### Maturin
472+
``` shell
473+
# if not already activated a virtual environment
474+
source .venv/bin/activate
475+
476+
poly deps
477+
```
478+
424479
### Options
425480
`--directory`
426481
Show brick depencencies for a specific project.
@@ -540,3 +595,30 @@ or run the test, filtered by pytest markers
540595
``` shell
541596
uv run pytest -m <<< echo "$query"
542597
```
598+
599+
#### Maturin
600+
``` shell
601+
# if not already activated a virtual environment
602+
source .venv/bin/activate
603+
```
604+
605+
``` shell
606+
# store the comma-separated list of bricks in a bash variable
607+
changes="$(poly diff --bricks --short)"
608+
609+
# transform it into a pytest query,
610+
# i.e. from "hello,world,something" to "hello or world or something"
611+
query="${changes//,/ or }"
612+
```
613+
614+
Run the test, filtered by keyword expression
615+
616+
``` shell
617+
pytest -k <<< echo "$query"
618+
```
619+
620+
or run the test, filtered by pytest markers
621+
622+
``` shell
623+
pytest -m <<< echo "$query"
624+
```

docs/dependencies.md

+8
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,11 @@ rye run poly check --directory projects/my-project
5151
``` shell
5252
uv run poly check --directory projects/my-project
5353
```
54+
55+
### Maturin
56+
``` shell
57+
# if not already activated a virtual environment
58+
source .venv/bin/activate
59+
60+
poly check --directory projects/my-project
61+
```

docs/deployment.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ packages = ["<your top namespace here>"]
2828
includes = ["<your top namespace here>/"]
2929
```
3030

31+
#### Maturin
32+
``` toml
33+
[tool.maturin]
34+
include = ["<your top namespace here>/**/*"]
35+
```
36+
3137
## Packaging
3238
To collect the components and bases that are needed for a specific project, the tool introduces a _build_ step.
3339
The tool will build a _wheel_ and an _sdist_ from the source code of a project.
@@ -67,6 +73,20 @@ rye build --wheel
6773
uv build --wheel projects/the_project
6874
```
6975

76+
#### Maturin
77+
``` shell
78+
cd projects/the_project
79+
80+
# if not already activated a virtual environment
81+
source .venv/bin/activate
82+
83+
poly build setup
84+
85+
maturin build
86+
87+
poly build teardown
88+
```
89+
7090
This command will create a project specific _dist_ folder containing a _wheel_ with all the needed bricks.
7191

7292
## Deploying
@@ -94,7 +114,7 @@ The `build-project` command, with a custom top namespace:
94114
poetry build-project --with-top-namespace my_custom_namespace
95115
```
96116

97-
#### Hatch, PDM, Rye and uv
117+
#### uv, Hatch, PDM, Rye and Maturin
98118
A custom top namespace is defined in the project-specific `pyproject.toml`:
99119

100120
``` toml

docs/installation.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# Installation
23

34
## Poetry
@@ -15,7 +16,7 @@ poetry self add poetry-polylith-plugin
1516

1617
Done!
1718

18-
## Hatch, PDM, Rye, Pantsbuild and uv
19+
## uv, Hatch, PDM, Rye, Pantsbuild and Maturin
1920

2021
No globally added tools needed. Add the project-specific dependencies (see the [Setup](setup.md) and [Projects & pyproject.toml](projects.md) section),
2122
and the build hook plugins to add support for the Polylith structure and when packaging libraries.

docs/migrating.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ packages = [
2020
# insert the needed 3rd party libraries here
2121
```
2222

23-
## Hatch, PDM, Rye and uv
23+
## uv, Hatch, PDM, Rye and Maturin
2424
``` toml
2525
[project]
2626
dependencies = [] # insert the needed 3rd party libraries here
@@ -76,7 +76,18 @@ rye build --sdist
7676
``` shell
7777
cd path/to_project
7878

79-
uvx --from build pyproject-build --installer uv
79+
uv build
80+
```
81+
82+
### Maturin
83+
``` shell
84+
cd path/to_project
85+
86+
poly build setup
87+
88+
maturin build
89+
90+
poly build teardown
8091
```
8192

8293
The output is a `wheel` and, more importantly, an `sdist` (a source distribution). It is essentially a _zip_ file containing all source code used in the project.

docs/projects.md

+39
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,42 @@ Polylith bricks are added in the `[tool.polylith.bricks]` section:
203203

204204
The `bases` and `components` folders are located at the workspace root.
205205
The project-specific `pyproject.toml` file is located in a subfolder of the `projects` folder.
206+
207+
208+
## Maturin
209+
210+
### The pyproject.toml in the Workspace (i.e. the one in the root folder)
211+
Add the `polylith-cli` to the workspace `pyproject.toml` configuration.
212+
213+
``` toml
214+
[project.optional-dependencies]
215+
tests = [
216+
"polylith-cli",
217+
]
218+
```
219+
220+
Make Maturin aware of the way Polylith organizes source code:
221+
``` toml
222+
[tool.maturin]
223+
dev-mode-dirs = ["components", "bases", "development", "."]
224+
```
225+
226+
227+
### The project-specific pyproject.toml file(s)
228+
Prepare the project top folder for building wheels and sdists, by include the top namespace.
229+
``` toml
230+
[tool.maturin]
231+
include = ["my_namespace/**/*"]
232+
```
233+
234+
Polylith bricks are added in the `[tool.polylith.bricks]` section:
235+
236+
``` toml
237+
[tool.polylith.bricks]
238+
"../../bases/my_namespace/my_base" = "my_namespace/my_base"
239+
"../../components/my_namespace/my_component" = "my_namespace/my_component"
240+
"../../components/my_namespace/my_other_component" = "my_namespace/my_other_component"
241+
```
242+
243+
The `bases` and `components` folders are located at the workspace root.
244+
The project-specific `pyproject.toml` file is located in a subfolder of the `projects` folder.

0 commit comments

Comments
 (0)