Using Python UV with Editable Source Code Dependencies in a Project TOML
Introduction
UV is a fast Python package manager that simplifies dependency management. For more details, refer to the official UV documentation. This guide covers how to set up an editable AutoClean source within a pyproject.toml
configuration using UV.
Setting Up a Basic pyproject.toml
Before proceeding, ensure that your project has a pyproject.toml
file. If one does not exist, create it with the following minimal configuration:
[project]
name = "autoclean_example_project"
version = "0.1.0"
description = "Autoclean Example Project"
requires-python = ">=3.10"
This file provides UV with a structure to modify when adding dependencies.
Prerequisites
Ensure you have:
Python 3.10+ installed
UV installed (
pip install uv
)AutoClean source code in your project structure
Steps to Configure an Editable Installation
1. Add an Editable Dependency
Download your source code to a local folder. To add an editable dependency, run the following command:
uv add --editable /path/to/your/local/package
This command will automatically update pyproject.toml
with the necessary configuration:
[project]
dependencies = [
...
"autocleaneeg",
]
[tool.uv.sources]
autocleaneeg = { path = "../autoclean_preprocessing", editable = true }
2. Sync Dependencies
Then, run UV to synchronize dependencies:
uv sync
This will ensure that AutoClean and all other dependencies are correctly installed.
3. Running the Project with Editable Mode
If debugging or making changes to your source code, you can use breakpoints with pdb
to inspect the execution:
import pdb; pdb.set_trace()
# add to code
breakpoint()
This allows you to pause execution and interactively debug your code.
If making changes to AutoClean’s source, use:
If debugging or making changes to AutoClean’s source, use:
uv run your_script.py
This allows live updates to AutoClean without reinstalling.
Conclusion
Using UV with editable dependencies enables efficient debugging and iterative development.