Skip to content

Commit c76da92

Browse files
Update 4_project_metadata.md
1 parent f2290d4 commit c76da92

File tree

1 file changed

+16
-67
lines changed

1 file changed

+16
-67
lines changed

episodes/4_project_metadata.md

Lines changed: 16 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,14 @@ exercises: 10
2020

2121
## Introduction
2222

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.
2424
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.
2525

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-
```
4726
## The `[build-system]` table
4827

4928
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`).
5029

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.
5231
It has two main keys:
5332

5433
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:
5938
requires = ["hatchling"]
6039
build-backend = "hatchling.build"
6140
```
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
6346

6447
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.
6548

@@ -68,83 +51,49 @@ Projects may be installed in editable mode, which allows you to make changes to
6851
greet_me = { path = ".", editable = true }
6952
```
7053

71-
- Dependency Management
54+
## Dependency Management
7255
For dependency handling, the pyproject.toml file should include the requires-python field, which specifies the supported Python versions. For example:
7356
```toml
7457
requires-python = ">=3.11, <3.12"
7558
```
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:
7960
`[tool.pixi.workspace]`: Defines project-wide settings, including package sources and target platforms for resolution.
8061
`[tool.pixi.pypi-dependencies]` : Declares the dependencies to be installed from PyPI (or equivalent sources). These are the external libraries required by the project.
8162

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-
```
9463
You can specify a range or multiple supported Python versions using the syntax below.
9564
```toml
9665
requires-python = ">=3.11, <3.12"
9766
```
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.
113-
114-
```toml
115-
[tool.pixi.tasks]
116-
# This command will only be defined on Windows
117-
greet = { cmd = "echo 'Happy Python Packaging!'" }
118-
```
11967
Final `pyproject.toml` should look like this below, for reference.
12068

12169
```toml
12270
[project]
12371
authors = [{name = "Priyanka O"}]
12472
dependencies = []
125-
name = "po_greet_me"
73+
name = "greet_me"
12674
requires-python = ">= 3.11"
12775
version = "0.1.2"
12876
description = "greet_me Pixi-managed package"
77+
readme = "README.md"
12978

13079
[build-system]
13180
build-backend = "hatchling.build"
13281
requires = ["hatchling"]
13382

134-
[tool.hatch.build.targets.wheel]
135-
packages = ["my_package"]
136-
13783
[tool.pixi.workspace]
13884
channels = ["conda-forge"]
13985
platforms = ["linux-64"]
14086

14187
[tool.pixi.pypi-dependencies]
142-
greet_me = { path = ".", editable = true }
14388
requests = ">=2.32.5,<3"
89+
greet_me = { path = ".", editable = true }
14490

14591
[tool.pixi.tasks]
146-
greet = { cmd = "echo 'Happy Python Packaging!'" }
92+
start = "python -c 'from greet_me import happy; print(happy.greet_happy())'"
14793
```
94+
95+
For insipiration, also check [here](https://github.com/prefix-dev/parselmouth/blob/main/pyproject.toml)
96+
14897
## Lockfiles
14998
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.
15099

0 commit comments

Comments
 (0)