You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: episodes/4_project_metadata.md
+16-67Lines changed: 16 additions & 67 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,35 +20,14 @@ exercises: 10
20
20
21
21
## Introduction
22
22
23
-
In the previous lesson, we briefly introduced `pixi.toml`. In this lesson, we shall focus on `pyproject.toml`, which is the most widely used configuration format for Python projects.
23
+
In the previous lesson, we briefly looked into `pyproject.toml`. In this lesson, we shall focus a bit more in detail on `pyproject.toml`, which is the most widely used configuration format for Python projects.
24
24
Please note, for projects managed with Pixi, either `pyproject.toml` or `pixi.toml` may be employed. The primary distinction lies in syntax, so you need only ensure that you follow the appropriate conventions.
25
25
26
-
To initialise a project using `pyproject.toml`, run the following command:
27
-
```bash
28
-
pixi init --format pyproject
29
-
```
30
-
```output
31
-
✔ Created .../greet_me/pyproject.toml
32
-
```
33
-
## Whats inside `pyproject.toml`
34
-
35
-
- Manifest metadata
36
-
```toml
37
-
[project]
38
-
name = "greet_me"
39
-
version = "0.1.0"
40
-
description = "greet_me Pixi-managed package"
41
-
authors = [{ name = "Priyanka", email = "" }]
42
-
readme = "README.md"
43
-
license = { text = "MIT" }
44
-
requires-python = ">=3.11"
45
-
dependencies = []
46
-
```
47
26
## The `[build-system]` table
48
27
49
28
This section of a `pyproject.toml` file informs packaging tools such as `pip` which software is required to build your project. It specifies the **build backend** responsible for producing distributable packages such as wheels (`.whl`) or source distributions (`.sdist`).
50
29
51
-
This section was introduced by **PEP 518** and is essential for modern Python packaging.
30
+
This section was introduced by **[PEP 518]**(https://peps.python.org/pep-0518/) and is essential for modern Python packaging.
52
31
It has two main keys:
53
32
54
33
1.`requires`: A list of packages required to build the project. These are downloaded and installed into a temporary, isolated environment prior to the build process. The build backend itself must also be listed here.
@@ -59,7 +38,11 @@ It has two main keys:
59
38
requires = ["hatchling"]
60
39
build-backend = "hatchling.build"
61
40
```
62
-
- Editable Installation
41
+
Some other build tools to read are
42
+
-[pdm.backend](https://backend.pdm-project.org)
43
+
-[mesonpy](https://mesonbuild.com/meson-python/)
44
+
45
+
## Editable Installation
63
46
64
47
Projects may be installed in editable mode, which allows you to make changes to the source code and have them reflected immediately in the environment without reinstallation. For example, the `greet_me` package can be added as an editable dependency.
65
48
@@ -68,83 +51,49 @@ Projects may be installed in editable mode, which allows you to make changes to
68
51
greet_me = { path = ".", editable = true }
69
52
```
70
53
71
-
- Dependency Management
54
+
##Dependency Management
72
55
For dependency handling, the pyproject.toml file should include the requires-python field, which specifies the supported Python versions. For example:
73
56
```toml
74
57
requires-python = ">=3.11, <3.12"
75
58
```
76
-
In a `pixi.toml` file, the syntax would differ slightly, but the purpose remains the same.
77
-
78
-
Additional sections in `pyproject.toml` may include:
59
+
Additional sections in `pyproject.toml` may include:
79
60
`[tool.pixi.workspace]`: Defines project-wide settings, including package sources and target platforms for resolution.
80
61
`[tool.pixi.pypi-dependencies]` : Declares the dependencies to be installed from PyPI (or equivalent sources). These are the external libraries required by the project.
81
62
82
-
```toml
83
-
[project]
84
-
name = "greet_me"
85
-
requires-python = ">=3.11"
86
-
87
-
[tool.pixi.workspace]
88
-
channels = ["conda-forge"]
89
-
platforms = ["linux-64", "win-64"]
90
-
91
-
[tool.pixi.pypi-dependencies]
92
-
requests = ">=2.31.0,<3"
93
-
```
94
63
You can specify a range or multiple supported Python versions using the syntax below.
95
64
```toml
96
65
requires-python = ">=3.11, <3.12"
97
66
```
98
-
If you were using `pixi.toml` file, the equivalent syntax would be
99
-
```toml
100
-
[tool.pixi.workspace]
101
-
name = "greet_me"
102
-
channels = ["conda-forge"]
103
-
platforms = ["linux-64", "win-64"]
104
-
105
-
[tool.pixi.pypi-dependencies]
106
-
python = ">=3.11"
107
-
108
-
[tool.pixi.tasks]
109
-
```
110
-
- Tasks
111
-
112
-
The `tasks` section allows you to define custom commands or scripts that should be executed before packaging. These tasks may specify inputs, outputs, or dependencies, enabling you to automate steps in your workflow. You can specify `inputs`, `outputs` or `depends-on` tasks.
For insipiration, also check [here](https://github.com/prefix-dev/parselmouth/blob/main/pyproject.toml)
96
+
148
97
## Lockfiles
149
98
A **lockfile** contains the complete set of dependencies, including specific versions, required to reproduce the project environment. It is automatically generated based on the dependencies listed in the `.toml` file, ensuring that builds remain consistent and reproducible.
0 commit comments