A simple Python package demonstrating uv packaging
Project description
Simple Package
一个用于演示 uv 打包过程的简单 Python 包。
功能特性
- 简单的计算器类,支持基本数学运算
- 实用工具函数(字符串处理、邮箱验证等)
- 命令行接口 (CLI)
- 完整的测试套件
- 使用现代 Python 打包工具 (pyproject.toml + uv)
安装
使用 uv 安装(推荐)
# 从本地目录安装
uv pip install .
# 开发模式安装
uv pip install -e .
# 安装开发依赖
uv pip install -e ".[dev]"
使用 pip 安装
# 从本地目录安装
pip install .
# 开发模式安装
pip install -e .
使用方法
作为 Python 库
from simple_package import Calculator, greet, format_number
# 使用计算器
calc = Calculator()
result = calc.add(5, 3)
print(f"5 + 3 = {result}")
# 查看历史记录
history = calc.get_history()
print("计算历史:", history)
# 使用其他函数
greeting = greet("Alice")
print(greeting) # Hello, Alice!
formatted = format_number(3.14159, 2)
print(formatted) # 3.14
使用命令行接口
# 问候
simple-cli hello --name Alice
# 计算
simple-cli calc 5 3 --operation add
simple-cli calc 10 2 --operation divide
# 查看帮助
simple-cli --help
开发
设置开发环境
# 克隆或进入项目目录
cd simple_uv_project
# 使用 uv 创建虚拟环境并安装依赖
uv venv
source .venv/bin/activate # Linux/Mac
# 或 .venv\Scripts\activate # Windows
# 安装项目及开发依赖
uv pip install -e ".[dev]"
运行测试
# 运行所有测试
pytest
# 运行测试并查看覆盖率
pytest --cov=simple_package
代码格式化
# 格式化代码
black src/ tests/
# 检查代码风格
flake8 src/ tests/
# 类型检查
mypy src/
项目结构
simple_uv_project/
├── src/
│ └── simple_package/
│ ├── __init__.py
│ ├── core.py # 核心功能
│ ├── utils.py # 实用工具
│ └── cli.py # 命令行接口
├── tests/
│ ├── __init__.py
│ ├── test_core.py
│ └── test_utils.py
├── pyproject.toml # 项目配置
├── README.md
└── LICENSE
使用 uv 进行打包
构建包
# 确保在项目根目录
cd /home/yz/learn_llm/simple_uv_project
# 使用 uv 构建
uv build
# 或者使用 build 工具
python -m build
这将在 dist/ 目录中生成:
simple_package-0.1.0.tar.gz(源代码分发包)simple_package-0.1.0-py3-none-any.whl(wheel 包)
发布到 PyPI
# 安装 twine
uv pip install twine
# 发布到 TestPyPI
twine upload --repository testpypi dist/*
# 发布到 PyPI
twine upload dist/*
许可证
MIT License
贡献
欢迎提交 Issue 和 Pull Request!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file example_package_yzqq-0.1.0.tar.gz.
File metadata
- Download URL: example_package_yzqq-0.1.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3292a4fe13d452ee3d7fe21e78e89c7c32a4b2a4f9b15371c4944a6422a92280
|
|
| MD5 |
edf8c115f1a5d5a2aef8278a2c844690
|
|
| BLAKE2b-256 |
55f4721cbbcc7b2953d7d3ef52c2bdcf3c6b614a217e4c54000c701d7ac07599
|
File details
Details for the file example_package_yzqq-0.1.0-py3-none-any.whl.
File metadata
- Download URL: example_package_yzqq-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3a11ff64b27f70bfd1f513f10e96f4a5df59c815305a6b26a03e7b1d25b871e
|
|
| MD5 |
cd2c94c1cc5c3571d2da43f3f00949ce
|
|
| BLAKE2b-256 |
09f8b1b990bc0b35ee5498e307904a9456b510cbd083ea79fc4ac9ae52f08e5d
|