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
15 changes: 6 additions & 9 deletions episodes/1_intoduction_python_packaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ Software development is a creative pursuit, and it is satisfying to write code t

By packaging code, you address several important challenges, including ensuring reproducibility, achieving cross-platform compatibility, and supporting multiple environments. Distributing code as a package offers many advantages over merely sharing source files, for example via GitHub:

Dependency management: A package can explicitly declare its dependencies. Tools such as pip (or uv) can then automatically install them for the user.

Versioning: You may version your package and distribute multiple versions, thereby supporting backwards compatibility.

Standardisation: Packaging is the established method of distributing code via recognised repositories such as PyPI.

Metadata: Packages include project-specific metadata, which is essential for end users.
- Dependency management: A package can explicitly declare its dependencies. Tools such as pip (or uv) can then automatically install them for the user.
- Versioning: You may version your package and distribute multiple versions, thereby supporting backwards compatibility.
- Standardisation: Packaging is the established method of distributing code via recognised repositories such as PyPI.
- Metadata: Packages include project-specific metadata, which is essential for end users.

## Python Package Structure Hierarchy

Expand Down Expand Up @@ -67,7 +64,7 @@ Metadata: Packages include project-specific metadata, which is essential for end
Any .py files (modules) or directories with __init__.py (packages) can be packaged.


## What Is __init__.Py File in Python?
## What Is __init__.py File in Python?
The __init__.py file is a Python file that is executed when a package is imported.
It serves two main purposes:

Expand All @@ -78,7 +75,7 @@ It serves two main purposes:

## What is PyPI

PyPI is the repository where all released Python packages are made available for end users. You may explore it here: [PyPI](https://pypi.org/).
[PyPI](https://pypi.org/) is the repository where all released Python packages are made available for end users.
There is also [TestPyPI](https://test.pypi.org/), a repository which allows us to experiment with distribution tools and procedures without affecting the live PyPI. In this course, we will publish our package to TestPyPI.

## What is a Build ?
Expand Down
13 changes: 7 additions & 6 deletions episodes/2_why_pixi.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ Pixi is a fast, modern and reproducible package management tool. It has lots of

Key features include:

- **Support for both PyPI and Conda packages** : enabling flexibility in sourcing dependencies.
- **Performance** :lightweight and modern, designed for speed.
- **Multi-language dependency management** : e.g. Python with Rust, or Python with C/C++.
- **Integration with `uv`** : leveraging a high-performance package installer.
- **Support for both PyPI and Conda packages**: enabling flexibility in sourcing dependencies.
- **Performance**: lightweight and modern, designed for speed.
- **Multi-language dependency management**: e.g. Python with Rust, or Python with C/C++.
- **Integration with `uv`**: leveraging a high-performance package installer.
- **Reproducibility**: guaranteed through the use of `pixi.lock`.
- **Configuration via TOML files**: supports both `pixi.toml` and `pyproject.toml`.

Expand All @@ -44,9 +44,10 @@ Pixi allows you to define dependencies for specific operating systems (e.g. Wind

## pyproject.toml
For this demo, we will mainly focus on `pyproject.toml` file.
We make this choice due to following specifications and recomendations : [PEP 621](https://peps.python.org/pep-0621/), [PEP 517](https://peps.python.org/pep-0517/), and [PEP 660](https://peps.python.org/pep-0660/)
We make this choice due to following specifications and recomendations : [PEP 621](https://peps.python.org/pep-0621/), [PEP 517](https://peps.python.org/pep-0517/), and [PEP 660](https://peps.python.org/pep-0660/).

You can also read at these links:

You can also read at these links :
- https://pixi.sh/v0.40.1/reference/pixi_manifest/#pypi-dependencies
- https://pixi.sh/v0.40.1/advanced/pyproject_toml/

Expand Down
14 changes: 9 additions & 5 deletions episodes/3_project_structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ greet_me = { path = ".", editable = true }
[tool.pixi.tasks]
```

To add libraries via Pixi:
To add libraries via Pixi use the `pixi add` command. Add the `requests` library:
```bash
pixi add requests
```
Expand Down Expand Up @@ -111,13 +111,15 @@ Added these as pypi-dependencies.
Check the `pyproject.toml` file. These get added under the `[project]` section
```toml
[project]
authors = [{name = "Priyanka Demo", email = "[email protected]"}]
dependencies = ["requests>=2.32.5,<3"]
name = "greet_me"
```
Please note : this wont create a problem when uploading the build but can create problems, when installing the builds.
Please note: this won't create a problem when uploading the build but can create problems when installing the builds.
So best to keep it empty for now and move this to `[tool.pixi.pypi-dependencies]` section , for all projects which need to come from via PyPI namely **build** and **twine** which are used to create and upload build respectively.
```toml
[project]
authors = [{name = "Priyanka Demo", email = "[email protected]"}]
dependencies = []
name = "greet_me"
...
Expand Down Expand Up @@ -173,9 +175,11 @@ def greet_sad():
The overall project structure should then resemble:
```
greet_me/
├── .pixi
├── .gitattributes
├── .gitignore
├── LICENSE
├── pyproject.toml
├── README.md
├── pixi.lock # auto-generated, do not edit
└── src/greet_me/
├── __init__.py
Expand All @@ -187,7 +191,7 @@ greet_me/

## Running a Task

Task is a command alias that you can execute easily via the CLI (e.g., pixi run <task-name>).
`task` is a command alias that you can execute easily via the CLI (e.g., pixi run task-name).

Run the following command to add a task and observe the changes in `pyproject.toml` file:
```bash
Expand Down Expand Up @@ -215,6 +219,6 @@ You can read more about tasks [here](https://pixi.sh/dev/workspace/advanced_task
- Follow the appropriate folder structure.
- Always include the `__init__.py` file in packages.
- Sequence of Pixi commands: **init** → **add** → **run** → **lock** → **install** → **update**.
- Define / check `[project]`, `[dependencies]` and `[tasks]` in your `pyproject.toml` file .
- Define / check `[project]`, `[dependencies]` and `[tasks]` in your `pyproject.toml` file.

::::::::::::::::::::::::::::::::::::::::::::::::
2 changes: 1 addition & 1 deletion episodes/4_project_metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Please note, for projects managed with Pixi, either `pyproject.toml` or `pixi.to

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

This section was introduced by **[PEP 518]**(https://peps.python.org/pep-0518/) and is essential for modern Python packaging.
This section was introduced by **[PEP 518](https://peps.python.org/pep-0518/)** and is essential for modern Python packaging.
It has two main keys:

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.
Expand Down
2 changes: 1 addition & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ It is a roughly 2 hour course.
- Structure a Python project following modern best practices.
- Define clear and complete project metadata in pyproject.toml / pixi.toml.
- Manage dependencies and lockfiles using Pixi to ensure consistent environments.
- Build source and wheel distributions of a Python package..
- Build source and wheel distributions of a Python package.
- Publish a package to Test Python Package Index (TestPyPI) using Twine.
- Install a package from TestPyPI using pip.

Expand Down
9 changes: 4 additions & 5 deletions learners/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ Your Codespace environment will be **Linux-based**, so we will be using standard

:::::::::::::::::::::::::::::::::::::::::::::::::::

## Create a repository
### Create a repository

- Log into [GitHub](https://github.com) and create a new repository for this lesson called `greet_me` and add a Licence File when creating the repository.
- Log into [GitHub](https://github.com) and create a new repository for this lesson called `greet_me` and add a Licence File when creating the repository. In this case it doesn't matter which licence (this is just a practice repo) - we just need something to initialise the repo, and a licence to satisfy the TestPyPI requirements.

- From the repository page, open the **Code** dropdown menu, select the **Codespaces** tab, and click **Create codespace on main**.

<img width="416" height="353" alt="image" src="https://github.com/user-attachments/assets/15167dca-b8c3-4701-87ac-3d6cb2b1022b" />

If you get an error (e.g. "Oh no, it looks like you are offline!") try a different browser or incognito mode.

- Once your Codespace has been created, open the terminal inside it and run the following commands.

:::::::::::::::: spoiler

### Install Pixi

Expand Down Expand Up @@ -71,5 +71,4 @@ pixi --version
```output
pixi 0.57.0
```
::::::::::::::::::::::::