Skip to content

Commit 303b2a9

Browse files
authored
Merge pull request #10 from DavidVujic/uv-support
add docs about supporting uv and the uv-specific commands
2 parents ee1a69a + 4af5de5 commit 303b2a9

File tree

10 files changed

+223
-9
lines changed

10 files changed

+223
-9
lines changed

docs/commands.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ pdm run poly create workspace --name my_example_namespace --theme loose
2525
rye run poly create workspace --name my_example_namespace --theme loose
2626
```
2727

28+
#### uv
29+
``` shell
30+
uv run poly create workspace --name my_example_namespace --theme loose
31+
```
32+
2833
### Options
2934
`--name` (required) the workspace name, that will be used as the single top namespace for all bricks. __Choose the name wisely.__
3035
Have a look in [PEP-423](https://peps.python.org/pep-0423/#respect-ownership) for naming guidelines.
@@ -68,6 +73,11 @@ pdm run poly create component --name my_example_component
6873
rye run poly create component --name my_example_component
6974
```
7075

76+
#### uv
77+
``` shell
78+
uv run poly create component --name my_example_component
79+
```
80+
7181
### Options
7282
`--name` (required) the name of the component.
7383

@@ -97,6 +107,11 @@ pdm run poly create base --name my_example_base
97107
rye run poly create base --name my_example_base
98108
```
99109

110+
#### uv
111+
``` shell
112+
uv run poly create base --name my_example_base
113+
```
114+
100115
### Options
101116
`--name` (required) the name of the base.
102117

@@ -126,6 +141,11 @@ pdm run poly create project --name my_example_project
126141
rye run poly create project --name my_example_project
127142
```
128143

144+
#### uv
145+
``` shell
146+
uv run poly create project --name my_example_project
147+
```
148+
129149
### Options
130150
`--name` (required) the name of the project.
131151

@@ -155,6 +175,11 @@ pdm run poly info
155175
rye run poly info
156176
```
157177

178+
#### uv
179+
``` shell
180+
uv run poly info
181+
```
182+
158183
### Options
159184
`--short` Display a view that is better adjusted to Workspaces with many projects.
160185

@@ -181,6 +206,11 @@ pdm run poly diff
181206
rye run poly diff
182207
```
183208

209+
#### uv
210+
``` shell
211+
uv run poly diff
212+
```
213+
184214
The `diff` command will compare the current state of the repository, compared to a `git tag`.
185215
The tool will look for the latest tag according to a certain pattern, such as `stable-*`.
186216
The pattern can be configured in the Workspace [configuration](configuration.md).
@@ -209,6 +239,11 @@ pdm run poly diff --since release
209239
rye run poly diff --since release
210240
```
211241

242+
#### Rye
243+
``` shell
244+
uv run poly diff --since release
245+
```
246+
212247
### Options
213248
`--short` Useful for determining what projects has been affected by the changes in CI.
214249

@@ -247,6 +282,11 @@ pdm run poly libs
247282
rye run poly libs
248283
```
249284

285+
#### uv
286+
``` shell
287+
uv run poly libs
288+
```
289+
250290
### Options
251291
`--directory`
252292
Show info about libraries used in a specific project.
@@ -290,6 +330,11 @@ pdm run poly check
290330
rye run poly check
291331
```
292332

333+
#### uv
334+
``` shell
335+
uv run poly check
336+
```
337+
293338
### Options
294339
`--directory`
295340
Show info about libraries used in a specific project.
@@ -331,6 +376,11 @@ pdm run poly sync
331376
rye run poly sync
332377
```
333378

379+
#### uv
380+
``` shell
381+
uv run poly sync
382+
```
383+
334384
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.
335385

336386
- projects: will add missing bricks to the project specific _pyproject.toml_, when imported by any of the already added bricks.
@@ -364,6 +414,11 @@ pdm run poly deps
364414
rye run poly deps
365415
```
366416

417+
#### uv
418+
``` shell
419+
uv run poly deps
420+
```
421+
367422
### Options
368423
`--directory`
369424
Show brick depencencies for a specific project.
@@ -461,3 +516,25 @@ or run the test, filtered by pytest markers
461516
``` shell
462517
rye run pytest -m <<< echo "$query"
463518
```
519+
520+
#### uv
521+
``` shell
522+
# store the comma-separated list of bricks in a bash variable
523+
changes="$(uv run poly diff --bricks --short)"
524+
525+
# transform it into a pytest query,
526+
# i.e. from "hello,world,something" to "hello or world or something"
527+
query="${changes//,/ or }"
528+
```
529+
530+
Run the test, filtered by keyword expression
531+
532+
``` shell
533+
uv run pytest -k <<< echo "$query"
534+
```
535+
536+
or run the test, filtered by pytest markers
537+
538+
``` shell
539+
uv run pytest -m <<< echo "$query"
540+
```

docs/dependencies.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ pdm run poly check --directory projects/my-project
4646
``` shell
4747
rye run poly check --directory projects/my-project
4848
```
49+
50+
### uv
51+
``` shell
52+
uv run poly check --directory projects/my-project
53+
```

docs/deployment.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Packaging and deploying Polylith projects is done by using the Poetry Multiproje
66
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.
77
Relative includes are currently not possible by default in __Poetry__, that is where the __Multiproject__ plugin comes in.
88

9-
## Hatch, PDM and Rye
10-
Hatch and PDM support relative includes via the `[tool.poetry.bricks]` configuration.
9+
## Hatch, PDM, Rye and uv
10+
Hatch, PDM, Rye and uv support relative includes via the `[tool.poetry.bricks]` configuration.
1111
Nothing extra needed other than the build hooks.
1212

1313
### Building source distributions (sdist)?
@@ -16,7 +16,7 @@ you will need to add the path in the project-specific `pyroject.toml`.
1616

1717
If you only provide `wheel` distributions, this is optional.
1818

19-
#### Hatch and Rye
19+
#### Hatch, Rye and uv
2020
```toml
2121
[tool.hatch.build.targets.wheel]
2222
packages = ["<your top namespace here>"]
@@ -64,6 +64,14 @@ rye build --wheel
6464
rye build --sdist
6565
```
6666

67+
#### uv
68+
``` shell
69+
cd path/to_project
70+
71+
uvx --from build pyproject-build --installer uv
72+
```
73+
74+
6775
This command will create a project specific _dist_ folder containing a _wheel_ and an _sdist_.
6876
You can use the available __build__ options with this command too.
6977

@@ -92,7 +100,7 @@ The `build-project` command, with a custom top namespace:
92100
poetry build-project --with-top-namespace my_custom_namespace
93101
```
94102

95-
#### Hatch, PDM and Rye
103+
#### Hatch, PDM, Rye and uv
96104
A custom top namespace is defined in the project-specific `pyproject.toml`:
97105

98106
``` toml

docs/examples.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Here are some examples of how to setup __Python__ with the Polylith Architecture
99
- [for PDM](https://github.com/DavidVujic/python-polylith-example-pdm)
1010
- [for Rye](https://github.com/DavidVujic/python-polylith-example-rye)
1111
- [for Pants](https://github.com/DavidVujic/python-polylith-example-pants)
12+
- [for uv](https://github.com/DavidVujic/python-polylith-example-uv)
1213
- [Python Polylith Microservices Example](https://github.com/ttamg/python-polylith-microservices-example) by Matt Gosden
1314
- [Aws CDK App with Polylith](https://github.com/ybenitezf/cdk_polylith) by Yoel Benítez Fonseca
1415

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ In short, Polylith is about:
4646
The __Python tools for the Polylith Architecture__ is available as two options:
4747

4848
- A __Poetry__ plugin. The plugin will add Polylith specific features to Poetry.
49-
- A standalone CLI supporting __Hatch__, __PDM__, __Rye__ and __Pantsbuild__ (and Poetry).
49+
- A standalone CLI supporting __Hatch__, __PDM__, __Rye__, __Pantsbuild__ and __uv__ (and Poetry).
5050

5151
### Use cases
5252

docs/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ poetry self add poetry-polylith-plugin
1515

1616
Done!
1717

18-
## Hatch, PDM, Rye and Pantsbuild
18+
## Hatch, PDM, Rye, Pantsbuild and uv
1919

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

docs/migrating.md

Lines changed: 9 additions & 2 deletions
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 and Rye
23+
## Hatch, PDM, Rye and uv
2424
``` toml
2525
[project]
2626
dependencies = [] # insert the needed 3rd party libraries here
@@ -65,13 +65,20 @@ cd path/to/project
6565
pdm build
6666
```
6767

68-
#### Rye
68+
### Rye
6969
``` shell
7070
cd path/to_project
7171

7272
rye build --sdist
7373
```
7474

75+
### uv
76+
``` shell
77+
cd path/to_project
78+
79+
uvx --from build pyproject-build --installer uv
80+
```
81+
7582
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.
7683

7784
That's all!

docs/projects.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,59 @@ dev-mode-dirs = ["components", "bases", "development", "."]
123123
```
124124

125125

126+
### The project-specific pyproject.toml file(s)
127+
``` toml
128+
[build-system]
129+
requires = ["hatchling", "hatch-polylith-bricks"]
130+
build-backend = "hatchling.build"
131+
132+
[tool.hatch.build.hooks.polylith-bricks]
133+
# this section is needed to enable the hook in the build process, even if empty.
134+
```
135+
136+
Polylith bricks are added in the `[tool.polylith.bricks]` section:
137+
138+
``` toml
139+
[tool.polylith.bricks]
140+
"../../bases/my_namespace/my_base" = "my_namespace/my_base"
141+
"../../components/my_namespace/my_component" = "my_namespace/my_component"
142+
"../../components/my_namespace/my_other_component" = "my_namespace/my_other_component"
143+
```
144+
145+
The `bases` and `components` folders are located at the workspace root.
146+
The project-specific `pyproject.toml` file is located in a subfolder of the `projects` folder.
147+
148+
## uv
149+
150+
### The pyproject.toml in the Workspace (i.e. the one in the root folder)
151+
Add the `polylith-cli` to the workspace `pyproject.toml` configuration.
152+
153+
Add it manually, or by running `uv add polylith-cli --dev`:
154+
155+
``` toml
156+
[tool.uv]
157+
dev-dependencies = ["polylith-cli"]
158+
```
159+
160+
The default build backend for uv is Hatch.
161+
Add the `hatch-polylith-bricks` build hook plugin to the `pyproject.toml` file.
162+
163+
``` toml
164+
[build-system]
165+
requires = ["hatchling", "hatch-polylith-bricks"]
166+
build-backend = "hatchling.build"
167+
168+
[tool.hatch.build.hooks.polylith-bricks]
169+
# this section is needed to enable the hook in the build process, even if empty.
170+
```
171+
172+
Make uv (and Hatch) aware of the way Polylith organizes source code:
173+
``` toml
174+
[tool.hatch.build]
175+
dev-mode-dirs = ["components", "bases", "development", "."]
176+
```
177+
178+
126179
### The project-specific pyproject.toml file(s)
127180
``` toml
128181
[build-system]

docs/setup.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Make Rye (and Hatch) aware of the way Polylith organizes source code:
157157
dev-mode-dirs = ["components", "bases", "development", "."]
158158
```
159159

160-
Remove the `[project.scripts]` and `[tool.hatch.build.targets.wheel]` sections.
160+
Remove the `[tool.hatch.build.targets.wheel]` section.
161161

162162
Run the `sync` command to update the virtual environment:
163163

@@ -170,6 +170,47 @@ Finally, remove the `src` boilerplate code that was added by Rye in the first st
170170
rm -r src
171171
```
172172

173+
### uv
174+
``` shell
175+
uv init my_repo # name your repo
176+
177+
cd my_repo
178+
179+
uv add polylith-cli --dev
180+
181+
uv sync # create a virtual environment and lock files
182+
```
183+
184+
Create a workspace, with a basic Polylith folder structure.
185+
186+
``` shell
187+
uv run poly create workspace --name my_namespace --theme loose
188+
```
189+
190+
`--name` (required) the workspace name, that will be used as the single top namespace for all bricks.
191+
__Choose the name wisely.__ Have a look in [PEP-423](https://peps.python.org/pep-0423/#respect-ownership) for naming guidelines.
192+
193+
`--theme` the structure of the workspace, `loose` is the recommended structure for Python.
194+
195+
#### Edit the configuration
196+
The default build backend for uv is Hatch.
197+
Make uv (and Hatch) aware of the way Polylith organizes source code:
198+
``` toml
199+
[tool.hatch.build]
200+
dev-mode-dirs = ["components", "bases", "development", "."]
201+
```
202+
203+
Run the `sync` command to update the virtual environment:
204+
205+
``` shell
206+
uv sync
207+
```
208+
209+
Finally, remove the `src` boilerplate code that was added by uv in the first step:
210+
``` shell
211+
rm -r src
212+
```
213+
173214
### Pantsbuild (aka Pants)
174215
Have a look in the Pants-specific [example repository](examples.md) for details on the setup.
175216
You will find examples of combining Pants with Polylith, by using the Hatch build backend in the project-specific configurations.

0 commit comments

Comments
 (0)