feat: add docs/uv.md (#972)

#967
This commit is contained in:
zine yu
2025-06-06 22:49:22 +08:00
committed by GitHub
parent 78f60f418c
commit 6b8fdb3366
3 changed files with 330 additions and 205 deletions

View File

@ -245,6 +245,7 @@ Quick Reference
[pip](./docs/pip.md)<!--rehype:style=background: rgb(24 147 209);&class=tag&data-lang=Python&class=contributing--> [pip](./docs/pip.md)<!--rehype:style=background: rgb(24 147 209);&class=tag&data-lang=Python&class=contributing-->
[YUM](./docs/yum.md)<!--rehype:style=background: rgb(86 86 123);--> [YUM](./docs/yum.md)<!--rehype:style=background: rgb(86 86 123);-->
[SDKMAN](./docs/sdkman.md)<!--rehype:style=background: rgb(0 118 198);--> [SDKMAN](./docs/sdkman.md)<!--rehype:style=background: rgb(0 118 198);-->
[uv](./docs/uv.md)<!--rehype:style=background: rgb(26 35 126);&class=tag&data-lang=Python&class=contributing-->
<!--rehype:class=home-card--> <!--rehype:class=home-card-->
## Git 版本控制 ## Git 版本控制

3
assets/uv.svg Normal file
View File

@ -0,0 +1,3 @@
<svg width="41" height="41" viewBox="0 0 41 41" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M-5.28619e-06 0.168629L0.0843098 20.1685L0.151762 36.1683C0.161075 38.3774 1.95947 40.1607 4.16859 40.1514L20.1684 40.084L30.1684 40.0418L31.1852 40.0375C33.3877 40.0282 35.1683 38.2026 35.1683 36V36L37.0003 36L37.0003 39.9992L40.1683 39.9996L39.9996 -9.94653e-07L21.5998 0.0775689L21.6774 16.0185L21.6774 25.9998L20.0774 25.9998L18.3998 25.9998L18.4774 16.032L18.3998 0.0910593L-5.28619e-06 0.168629Z" fill="#DE5FE9"/>
</svg>

After

Width:  |  Height:  |  Size: 531 B

121
docs/uv.md Normal file
View File

@ -0,0 +1,121 @@
uv 备忘清单
===
一个用 Rust 编写的极快的 Python 包和项目管理工具
安装
---
### 使用独立安装程序安装
#### macOS or Linux
```sh
curl -LsSf https://astral.sh/uv/install.sh | sh
```
#### Windows
```sh
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
```
### 通过PyPI
```sh
# pip
pip install uv
```
```sh
# pipx
pipx install uv
```
入门
---
### 创建新项目
<!--rehype:wrap-class=row-span-2-->
```sh
# 创建一个目录作为项目的根目录
uv init project_name
```
```sh
# 将当前目录作为项目的根目录
uv init
```
#### 项目的结构
```sh
.
├── .venv # 项目的虚拟环境
│ ├── bin
│ ├── lib
│ └── pyvenv.cfg
├── .python-version # 项目的 Python 版本
├── README.md
├── main.py
├── pyproject.toml # 项目的元数据
└── uv.lock # 项目的锁定文件, 用于锁定依赖版本,不应手动编辑
```
### 管理项目依赖
<!--rehype:wrap-class=row-span-2-->
#### 添加依赖
```sh
uv add requests
```
#### 指定依赖版本或替代来源
```sh
# 指定版本
uv add 'requests==2.28.1'
# 指定来源
uv add git+https://github.com/psf/requests
```
#### 从`requirements.txt`迁移
```sh
uv add -r requirements.txt
```
#### 删除一个包
```sh
uv remove requests
```
#### 升级一个包
```sh
uv lock --upgrade-package requests
```
### 运行脚本
指定脚本运行
```sh
uv run main.py
```
指定Python版本运行
```sh
uv run --python 3.10 main.py
```
### 构建项目
```sh
uv build
```
构建结果存储在`dist`目录下