This manual explains how to turn a Python application into a tool using the uv package manager. We'll go through each step in detail, explaining what each component does and why it's needed.
- Python 3.8 or higher installed
- uv installed (see uv installation guide)
- Basic understanding of Python
First, we need to organize our code into a proper Python package structure:
concat-tool/ # Root directory
├── concat_tool/ # Package directory (note the underscore)
│ ├── __init__.py # Makes the directory a Python package
│ └── cli.py # Main implementation
├── pyproject.toml # Project metadata and build configuration
└── README.md # Project documentation
- The root directory can have dashes (
concat-tool), but the package directory should use underscores (concat_tool) as per PEP 8 __init__.pymarks the directory as a Python package (see Python Packages)pyproject.tomlis the modern way to configure Python projects (see PEP 621)
This is the main configuration file. Let's break down each section:
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"- This section tells uv how to build the package
- We're using
hatchlingas our build backend (see uv build backends) - Reference: uv Publishing Guide
[project]
name = "concat-tool"
version = "0.1.0"
description = "A CLI tool that concatenates multiple files into one output, separated by filename headers."
requires-python = ">=3.8"
authors = [
{ name = "Your Name", email = "your.email@example.com" }
]
dependencies = []- Basic metadata about your project
name: The package name (used when installing)requires-python: Minimum Python version neededdependencies: List of required packages (empty in our case)- Reference: uv Project Metadata
[project.scripts]
concat-files = "concat_tool.cli:main"- Defines command-line entry points
- Format:
command-name = "package.module:function" - This makes
concat-filesavailable as a command after installation - Reference: uv Entry Points
[tool.hatch.build.targets.wheel]
packages = ["concat_tool"]- Tells hatchling which packages to include in the build
- Reference: Hatch Build Configuration
"""
concat-tool - A CLI tool for concatenating multiple files with headers.
"""
__version__ = "0.1.0"- Minimal initialization file
- Version should match pyproject.toml
- Contains the main implementation
- Uses
argparsefor command-line argument handling - Has a
main()function that serves as the entry point
uv build- Creates both source distribution (.tar.gz) and wheel (.whl) files in
dist/ - Reference: uv Build Command
uv tool install dist/*.whl- Installs the built wheel as a tool
- Makes the command available system-wide
- Reference: uv Tool Installation
uv tool install --editable .- Installs the package in "editable" mode
- Changes to the source code are immediately reflected
- Reference: uv Editable Installs
- Create virtual environment:
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install build dependencies:
uv pip install hatchling- Build and install:
uv build
uv tool install --editable .- Test the tool:
concat-files --helpWhile this tool is private, you could distribute it in several ways:
- Direct from source directory
- From a wheel file
- From a private Git repository
- Through a private PyPI server
Reference: uv Tool Installation Sources
-
"No executables are provided":
- Check
[project.scripts]section in pyproject.toml - Ensure the referenced function exists
- Check
-
Import errors after installation:
- Check package structure
- Verify
packagesin[tool.hatch.build.targets.wheel]
-
Command not found:
- Ensure tool installation was successful
- Check if uv's bin directory is in your PATH