Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: project_model
{
"version": "1",
"data": {
"name": "python_bindings",
"name": "cpp_math",
"version": "0.1.0",
"description": null,
"authors": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: project_model
{
"version": "1",
"data": {
"name": "python_bindings",
"name": "cpp_math",
"version": "0.1.0",
"description": null,
"authors": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: project_model
{
"version": "1",
"data": {
"name": "rich_example",
"name": "python_rich",
"version": "0.1.0",
"description": null,
"authors": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: project_model
{
"version": "1",
"data": {
"name": "rich_example",
"name": "python_rich",
"version": "0.1.0",
"description": null,
"authors": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: project_model
{
"version": "1",
"data": {
"name": "rich_example",
"name": "python_rich",
"version": "0.1.0",
"description": null,
"authors": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: project_model
{
"version": "1",
"data": {
"name": "rich_example",
"name": "python_rich",
"version": "0.1.0",
"description": null,
"authors": null,
Expand Down
2 changes: 1 addition & 1 deletion docs/build/advanced_cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Now that we've defined a `pixi` task which allows us to check that our package c

```toml
[tasks]
start = "python -c 'import python_bindings as b; print(b.add(1, 2))'"
start = "python -c 'import cpp_math as b; print(b.add(1, 2))'"
```

Executing the tasks works as expected
Expand Down
14 changes: 7 additions & 7 deletions docs/build/cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ We'll later combine this example together with a Python package.
To get started, create a new workspace with pixi:

```bash
pixi init python_bindings
pixi init cpp_math
```

This should give you the basic `pixi.toml` to get started.

We'll now create the following source directory structure:
```bash
python_bindings/
cpp_math/
├── CMakeLists.txt
├── pixi.toml
├── .gitignore
└── src
└── bindings.cpp
└── math.cpp
```

## Creating the workspace files
Next up we'll create the:

- `pixi.toml` file that will be used to configure pixi.
- `CMakeLists.txt` file that will be used to build the bindings.
- `src/bindings.cpp` file that will contain the bindings.
- `src/math.cpp` file that will contain the bindings.

### The `pixi.toml` file
Use the following `pixi.toml` file, you can hover over the annotations to see why each step was added.
Expand Down Expand Up @@ -68,12 +68,12 @@ Next lets add the `CMakeList.txt` file:
5. Use our bindings file as the source file.
6. Install the bindings into the designated prefix.

### The `src/bindings.cpp` file
### The `src/math.cpp` file

Next lets add the `src/bindings.cpp` file, this one is quite simple:
Next lets add the `src/math.cpp` file, this one is quite simple:

```cpp
--8<-- "docs/source_files/pixi_workspaces/pixi_build/cpp/src/bindings.cpp"
--8<-- "docs/source_files/pixi_workspaces/pixi_build/cpp/src/math.cpp"
```

1. We define a function that will be used to add two numbers together.
Expand Down
4 changes: 2 additions & 2 deletions docs/build/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ In this example, we are using `pixi-build-python` backend in order to build a Py
```


We need to add our package `rich_example` as source dependency to the workspace.
We need to add our package `python_rich` as source dependency to the workspace.

!!! hint
Pixi dependencies fall into two main categories: `binary` and `source` dependencies.
Expand All @@ -75,7 +75,7 @@ Source dependencies are defined in one of two ways:
```


`rich_example` uses `hatchling` as Python build backend, so this needs to be mentioned in `host-dependencies`.
`python_rich` uses `hatchling` as Python build backend, so this needs to be mentioned in `host-dependencies`.

Python PEP517 backends like `hatchling` know how to build a Python package.
So `hatchling` creates a Python package, and `pixi-build-python` turns the Python package into a conda package.
Expand Down
12 changes: 6 additions & 6 deletions docs/build/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ In this tutorial we will focus on point 1.
## Let's Get Started

First, we create a simple Python package with a `pyproject.toml` and a single Python file.
The package will be called `rich_example`, so we will create the following structure:
The package will be called `python_rich`, so we will create the following structure:

```shell
├── src # (1)!
│ └── rich_example
│ └── python_rich
│ └── __init__.py
└── pyproject.toml
```
Expand All @@ -34,8 +34,8 @@ The package will be called `rich_example`, so we will create the following struc
The Python package has a single function `main`.
Calling that, will print a table containing the name, age and city of three people.

```py title="src/rich_example/__init__.py"
--8<-- "docs/source_files/pixi_workspaces/pixi_build/python/src/rich_example/__init__.py"
```py title="src/python_rich/__init__.py"
--8<-- "docs/source_files/pixi_workspaces/pixi_build/python/src/python_rich/__init__.py"
```


Expand All @@ -46,7 +46,7 @@ The metadata of the Python package is defined in `pyproject.toml`.
```

1. We use the `rich` package to print the table in the terminal.
2. By specifying a script, the executable `rich-example-main` will be available in the environment. When being called it will in return call the `main` function of the `rich_example` module.
2. By specifying a script, the executable `rich-example-main` will be available in the environment. When being called it will in return call the `main` function of the `python_rich` module.
3. One can choose multiple backends to build a Python package, we choose `hatchling` which works well without additional configuration.


Expand Down Expand Up @@ -74,7 +74,7 @@ We pass `--format pixi` in order to communicate to pixi, that we want a `pixi.to

```shell
├── src
│ └── rich_example
│ └── python_rich
│ └── __init__.py
├── .gitignore
├── pixi.toml
Expand Down
34 changes: 17 additions & 17 deletions docs/build/variants.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ Some might call this functionality, build matrix, build configurations or parame
## Why is This Useful?

When we depend on a Pixi package, the dependency versions of the package itself are already set.
For example, in the [C++ tutorial](cpp.md) the `python_bindings` package we built depended on Python 3.12.
Pixi would report a version conflict, if we'd add use both Python 3.11 and `python_bindings` to our workspace.
For example, in the [C++ tutorial](cpp.md) the `cpp_math` package we built depended on Python 3.12.
Pixi would report a version conflict, if we'd add use both Python 3.11 and `cpp_math` to our workspace.
By using variants, we can add a set of allowed versions for a specific dependency.
Pixi will then resolve the package with all the different variants.

## Let's Get Started

In this tutorial we will continue with the result of the [workspace tutorial](workspace.md) so we can test it against multiple Python versions.
As a reminder, we ended up with a top-level `pixi.toml` containing the workspace and the Python package `rich_example`.
Our workspace then depended on `rich_example` and `python_bindings`.
As a reminder, we ended up with a top-level `pixi.toml` containing the workspace and the Python package `python_rich`.
Our workspace then depended on `python_rich` and `cpp_math`.

```toml title="pixi.toml"
--8<-- "docs/source_files/pixi_workspaces/pixi_build/workspace_variants/pixi.toml:dependencies"
Expand All @@ -28,23 +28,23 @@ The file tree looks like this:
```shell
.
├── packages
│ └── python_bindings
│ └── cpp_math
│ ├── CMakeLists.txt
│ ├── pixi.toml
│ └── src
│ └── bindings.cpp
│ └── math.cpp
├── pixi.lock
├── pixi.toml
├── pyproject.toml
└── src
└── rich_example
└── python_rich
└── __init__.py
```

In order to allow multiple Python versions we first have to change the Python version requirement of `python_bindings` from `3.12.*` to `*`.
In order to allow multiple Python versions we first have to change the Python version requirement of `cpp_math` from `3.12.*` to `*`.

```toml title="packages/python_bindings/pixi.toml" hl_lines="4"
--8<-- "docs/source_files/pixi_workspaces/pixi_build/workspace_variants/packages/python_bindings/pixi.toml:host-dependencies"
```toml title="packages/cpp_math/pixi.toml" hl_lines="4"
--8<-- "docs/source_files/pixi_workspaces/pixi_build/workspace_variants/packages/cpp_math/pixi.toml:host-dependencies"
```

1. Used to be "3.12.*"
Expand All @@ -66,9 +66,9 @@ In our case this allows us to test our setup against both Python 3.11 and 3.12.
```

By running `pixi list` we can see the Python version used in each environment.
You can also see that the `Build` string of `python_bindings` differ between `py311` and `py312`.
You can also see that the `Build` string of `cpp_math` differ between `py311` and `py312`.
That means that a different package has been built for each variant.
Since `rich_example` only contains Python source code, a single build can be used for multiple Python versions.
Since `python_rich` only contains Python source code, a single build can be used for multiple Python versions.
The package is `noarch`.
Therefore, the build string is the same.

Expand All @@ -77,23 +77,23 @@ Therefore, the build string is the same.
$ pixi list --environment py311
Package Version Build Size Kind Source
python 3.11.11 h9e4cc4f_1_cpython 29.2 MiB conda python
python_bindings 0.1.0 py311h43a39b2_0 conda python_bindings
rich_example 0.1.0 pyhbf21a9e_0 conda rich_example
cpp_math 0.1.0 py311h43a39b2_0 conda cpp_math
python_rich 0.1.0 pyhbf21a9e_0 conda python_rich
```

```pwsh
$ pixi list --environment py312
Package Version Build Size Kind Source
python 3.12.8 h9e4cc4f_1_cpython 30.1 MiB conda python
python_bindings 0.1.0 py312h2078e5b_0 conda python_bindings
rich_example 0.1.0 pyhbf21a9e_0 conda rich_example
cpp_math 0.1.0 py312h2078e5b_0 conda cpp_math
python_rich 0.1.0 pyhbf21a9e_0 conda python_rich
```


## Conclusion

In this tutorial, we showed how to use variants to build multiple versions of a single package.
We built `python_bindings` for Python 3.12 and 3.13, which allows us to test whether it works properly on both Python versions.
We built `cpp_math` for Python 3.12 and 3.13, which allows us to test whether it works properly on both Python versions.
Variants are not limited to a single dependency, you could for example try to test multiple versions of `nanobind`.

Thanks for reading! Happy Coding 🚀
Expand Down
30 changes: 15 additions & 15 deletions docs/build/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@ Or if you need the changes of an unreleased version of one of your dependencies.
## Let's Get Started

In this tutorial we will showcase how to develop two packages in one workspace.
For that we will use the `rich_example` Python package developed in chapter [Building a Python package](python.md) and let it depend on the `python_binding` C++ package developed in chapter [Building a C++ package](cpp.md).
For that we will use the `python_rich` Python package developed in chapter [Building a Python package](python.md) and let it depend on the `python_binding` C++ package developed in chapter [Building a C++ package](cpp.md).

We will start with the original setup of `rich_example` and copy `python_binding` into a folder called `packages`.
We will start with the original setup of `python_rich` and copy `python_binding` into a folder called `packages`.
The source directory structure now looks like this:

```shell
.
├── packages
│ └── python_bindings
│ └── cpp_math
│ ├── CMakeLists.txt
│ ├── pixi.toml
│ └── src
│ └── bindings.cpp
│ └── math.cpp
├── pixi.lock
├── pixi.toml
├── pyproject.toml
└── src
└── rich_example
└── python_rich
└── __init__.py
```

Within a Pixi manifest, you can manage a workspace and/or describe a package.
In the case of `rich_example` we choose to do both, so the only thing we have to add is the dependency on the `python_bindings`.
In the case of `python_rich` we choose to do both, so the only thing we have to add is the dependency on the `cpp_math`.

```py title="pixi.toml"
--8<-- "docs/source_files/pixi_workspaces/pixi_build/workspace/pixi.toml:workspace"
```

We only want to use the `workspace` table of the top-level manifest.
Therefore, we can remove the workspace section in the manifest of `python_bindings`.
Therefore, we can remove the workspace section in the manifest of `cpp_math`.

```diff title="packages/python_bindings/pixi.toml"
```diff title="packages/cpp_math/pixi.toml"
-[workspace]
-channels = [
- "https://prefix.dev/pixi-build-backends",
Expand All @@ -56,14 +56,14 @@ Therefore, we can remove the workspace section in the manifest of `python_bindin
-preview = ["pixi-build"]
-
-[dependencies]
-python_bindings = { path = "." }
-cpp_math = { path = "." }
-
-[tasks]
-start = "python -c 'import python_bindings as b; print(b.add(1, 2))'"
-start = "python -c 'import cpp_math as b; print(b.add(1, 2))'"
```


There is actually one problem with `rich_example`.
There is actually one problem with `python_rich`.
The age of every person is off by one year!

```
Expand All @@ -77,11 +77,11 @@ The age of every person is off by one year!
```

We need to add one year to the age of every person.
Luckily `python_bindings` exposes a function `add` which allows us to do exactly that.
Luckily `cpp_math` exposes a function `add` which allows us to do exactly that.


```py title="src/rich_example/__init__.py"
--8<-- "docs/source_files/pixi_workspaces/pixi_build/workspace/src/rich_example/__init__.py"
```py title="src/python_rich/__init__.py"
--8<-- "docs/source_files/pixi_workspaces/pixi_build/workspace/src/python_rich/__init__.py"
```

If you run `pixi run start`, the age of each person should now be accurate:
Expand All @@ -99,7 +99,7 @@ If you run `pixi run start`, the age of each person should now be accurate:
## Conclusion

In this tutorial, we created a Pixi workspace containing two packages.
The manifest of `rich_example` describes the workspace as well as the package, with `python_bindings` only the `package` section is used.
The manifest of `python_rich` describes the workspace as well as the package, with `cpp_math` only the `package` section is used.
Feel free to add more packages, written in different languages to this workspace!

Thanks for reading! Happy Coding 🚀
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.20...3.27)
project(python_bindings)
project(cpp_math)

find_package(Python 3.8 COMPONENTS Interpreter Development.Module REQUIRED) # (1)!

Expand All @@ -16,7 +16,7 @@ execute_process(

find_package(nanobind CONFIG REQUIRED) # (4)!

nanobind_add_module(${PROJECT_NAME} src/bindings.cpp) # (5)!
nanobind_add_module(${PROJECT_NAME} src/math.cpp) # (5)!

install( # (6)!
TARGETS ${PROJECT_NAME}
Expand Down
Loading