Add your description here
Project description
使用UV工具编写Tool项目
安装
Linux、MacOS
使用 curl 下载脚本,并使用 sh 执行它:
curl -LsSf https://astral.sh/uv/install.sh | sh
如果系统中没有 curl,可以使用 wget:
wget -qO- https://astral.sh/uv/install.sh | sh
Windows
使用 irm 下载脚本,并使用 iex 执行它:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
创建新项目
您可以使用 uv init 命令创建一个新的 Python 项目:
uv init hello-world
cd hello-world
或者,你可以在工作目录中初始化一个项目:
mkdir hello-world
cd hello-world
uv init
uv 将创建以下文件:
├── .gitignore
├── .python-version
├── README.md
├── main.py
└── pyproject.toml
main.py 文件包含一个简单的“Hello world”程序。使用 uv run 尝试运行它:
uv run main.py
项目结构
一个项目由几个重要的部分组成,这些部分协同工作,使 uv 能够管理你的项目。除了uv init创建的文件外,uv 还会创建一个虚拟环境和uv.lock文件。 在项目根目录下首次运行项目命令(例如:uv run)时,会生成一个文件。 uv sync,或 uv lock。
完整列表如下:
├── .venv
│ ├── bin
│ ├── lib
│ └── pyvenv.cfg
├── .python-version
├── README.md
├── main.py
├── pyproject.toml
└── uv.lock
pyproject.toml
pyproject.toml 文件包含了关于您项目的元数据:
[project]
name = "uv-hello-world"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = []
本地运行
uv run 运行
uv run main.py
修改项目为Tool类型
修改pyproject.toml项目配置,增加入口函数
[project.scripts]
uv-hello-world = "main:hello"
使用uvx 运行
uvx --from . uv-hello-world
构建
uv build
发布到pypi
使用 --token 或 UV_PUBLISH_TOKEN 设置 PyPI 密钥
使用 --password 或 UV_PUBLISH_PASSWORD设置密码
uv publish
Project details
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 uv_hello_world-0.1.7.tar.gz.
File metadata
- Download URL: uv_hello_world-0.1.7.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3358d6b5980e08394665b43834f70f42d27a8bf9bc271def344d7bd1cdada151
|
|
| MD5 |
15f10c36c6c7618fee2235b522313f0e
|
|
| BLAKE2b-256 |
d1a2c1ab6b7df4b968851c62f5e11985ef23f2ff006bfc087cb30f3f17db16ca
|
File details
Details for the file uv_hello_world-0.1.7-py3-none-any.whl.
File metadata
- Download URL: uv_hello_world-0.1.7-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3091ef477aa47c733dcc7d91a31977da806d32e99ad20b7ce80859d38fc2a7cc
|
|
| MD5 |
520b28be63bb22d98b3982642a35e980
|
|
| BLAKE2b-256 |
8586cda4a9012a0d9e03013b4643531aee120658c51b3adc19b0e9db246e77de
|