Skip to content

Commit 80c4687

Browse files
authored
Add note about workspaces. (#692)
1 parent 8c99cda commit 80c4687

File tree

4 files changed

+78
-8
lines changed

4 files changed

+78
-8
lines changed

docs/source/how_to_guides/bp_structure_of_a_research_project.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ As an example, look at two repositories from a COVID-19 forecasting project.
2323
- [sid](https://github.com/covid-19-impact-lab/sid) contains the code for the
2424
epidemiological model which is applied in the research project.
2525

26+
```{seealso}
27+
Nowadays, consider using [workspaces](using_workspaces.md) instead of separate repositories.
28+
```
29+
2630
Separating the model code from the research project provided several benefits.
2731

2832
- The model code is isolated and has its own test suite. Assessing and ensuring the code

docs/source/how_to_guides/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ provisional_nodes_and_task_generators
2323
writing_custom_nodes
2424
extending_pytask
2525
the_data_catalog
26+
using_workspaces
2627
```
2728

2829
## Best Practice Guides
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Using workspaces
2+
3+
There are situations where you want to structure your project as a multi-package
4+
workspace. Reasons are
5+
6+
- You are developing a scientific package alongside the project that you want to publish
7+
later.
8+
- The code for dealing with the dataset should be reused in other projects.
9+
- You want to strictly separate the pytask tasks from the remaining code to be able to
10+
switch to another build system.
11+
12+
In those instances, a workspace might be the right choice.
13+
14+
```text
15+
project
16+
├── packages
17+
│ ├── data
18+
│ │ ├── pyproject.toml
19+
│ │ └── src
20+
│ │ └── data
21+
│ │ ├── __init__.py
22+
│ │ └── ...
23+
│ ├── analysis
24+
│ │ ├── pyproject.toml
25+
│ │ └── src
26+
│ │ └── analysis
27+
│ │ ├── __init__.py
28+
│ │ └── ...
29+
│ └── tasks
30+
│ ├── pyproject.toml
31+
│ └── src
32+
│ └── tasks
33+
│ ├── __init__.py
34+
│ └── ...
35+
36+
├── pyproject.toml
37+
├── README.md
38+
├── ...
39+
```
40+
41+
## Using workspaces with uv
42+
43+
uv provides excellent support for workspaces which you can read more about in the
44+
[uv documentation](https://docs.astral.sh/uv/concepts/projects/workspaces).
45+
46+
## Using workspaces with pixi
47+
48+
pixi is still working on a native workspace experience, but there are workarounds.
49+
50+
- [https://github.com/prefix-dev/pixi/discussions/387](https://github.com/prefix-dev/pixi/discussions/387)
51+
- [https://github.com/Andre-Medina/python-pixi-mono-template](https://github.com/Andre-Medina/python-pixi-mono-template)

docs/source/tutorials/set_up_a_project.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ tutorial explains the minimal setup.
66
If you want to use pytask with a collection of scripts, you can skip this lesson and
77
move to the next section of the tutorials.
88

9+
```{seealso}
10+
In case you are thinking about developing multiple packages in the project that should be separated (one for dealing with the data, one for the analysis and a package for the pytask tasks), consider using a [workspace](../how_to_guides/using_workspaces.md).
11+
```
12+
13+
## The directory structure
14+
915
The following directory tree gives an overview of the project's different parts.
1016

1117
```text
@@ -83,6 +89,10 @@ version = "0.1.0"
8389
requires-python = ">=3.9"
8490
dependencies = ["pytask"]
8591
92+
[build-system]
93+
requires = ["uv_build"]
94+
build-backend = "uv_build"
95+
8696
[tool.pytask.ini_options]
8797
paths = ["src/my_project"]
8898
```
@@ -104,6 +114,10 @@ requires-python = ">=3.9"
104114
channels = ["conda-forge"]
105115
platforms = ["linux-64", "osx-64", "osx-arm64", "win-64"]
106116
117+
[build-system]
118+
requires = ["hatchling"]
119+
build-backend = "hatchling.build"
120+
107121
[dependencies]
108122
pytask = "*"
109123
python = ">=3.9"
@@ -120,16 +134,16 @@ paths = ["src/my_project"]
120134
Create a `pyproject.toml` file for project configuration:
121135
122136
```toml
123-
[build-system]
124-
requires = ["hatchling"]
125-
build-backend = "hatchling.build"
126-
127137
[project]
128138
name = "my_project"
129139
version = "0.1.0"
130140
requires-python = ">=3.9"
131141
dependencies = ["pytask"]
132142
143+
[build-system]
144+
requires = ["hatchling"]
145+
build-backend = "hatchling.build"
146+
133147
[tool.pytask.ini_options]
134148
paths = ["src/my_project"]
135149
```
@@ -162,15 +176,15 @@ dependencies:
162176
And a `pyproject.toml` file for project configuration:
163177
164178
```toml
165-
[build-system]
166-
requires = ["hatchling"]
167-
build-backend = "hatchling.build"
168-
169179
[project]
170180
name = "my_project"
171181
version = "0.1.0"
172182
requires-python = ">=3.9"
173183
184+
[build-system]
185+
requires = ["hatchling"]
186+
build-backend = "hatchling"
187+
174188
[tool.pytask.ini_options]
175189
paths = ["src/my_project"]
176190
```

0 commit comments

Comments
 (0)