-
-
Notifications
You must be signed in to change notification settings - Fork 278
修复uv换源 #373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mikachu2333
wants to merge
14
commits into
RubyMetric:dev
Choose a base branch
from
Mikachu2333:fix/uv
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
修复uv换源 #373
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d0806d7
更新 Mikachu2333 的邮箱
Mikachu2333 0fa9e34
排除clangd扩展的干扰
Mikachu2333 8ad3c02
重构 uv 源配置写入逻辑,新增 uv-helper 模块
Mikachu2333 abcf789
支持在 pyproject.toml 中配置 uv 换源,并新增 CNB 仓库
Mikachu2333 712b47f
忽略 .pdb 调试符号文件
Mikachu2333 bd26fb6
增强 uv 配置改写器的转义与带引号键支持,增加edge测试
Mikachu2333 fc45c52
格式化python镜像列表
Mikachu2333 ff1a281
修复copilot提到的问题
Mikachu2333 033939e
移除 uv-helper-test
Mikachu2333 4f89e3f
移动 uv 相关到独立目录
Mikachu2333 f7f7218
移动 `uv` 实现文档
ccmywish f5ed704
Merge branch 'dev' into fix/uv
Mikachu2333 bc3adab
格式改进
Mikachu2333 77ff0fa
复用xy提供的解析函数,简化uv配置写入与换行处理
Mikachu2333 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| *.out | ||
| *.exe | ||
| *.res | ||
| *.pdb | ||
|
|
||
|
|
||
| ############################## | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
|
Mikachu2333 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| <!-- ----------------------------------------------------------- | ||
| ! SPDX-License-Identifier: GFDL-1.3-or-later | ||
| ! ------------------------------------------------------------- | ||
| ! Doc Type : Markdown | ||
| ! Doc Name : uv换源实现说明.md | ||
| ! Created On : <2026-08-02> | ||
| ! Last Modified : <2026-08-02> | ||
| ! ---------------------------------------------------------- --> | ||
|
|
||
| # uv 换源实现说明 | ||
|
|
||
| `chsrc set uv` 同时配置两类下载地址: | ||
|
|
||
| 1. Python 包索引,即 `uv.toml` 的 `[[index]]` 或 `pyproject.toml` 的 `[[tool.uv.index]]` | ||
| 2. uv 管理的 CPython 下载地址,即 `python-install-mirror` | ||
|
|
||
| <br> | ||
|
|
||
| ## 配置文件选择 | ||
|
|
||
| 项目作用域只修改当前目录,不向父目录查找并修改配置: | ||
|
|
||
| 1. 当前目录存在 `uv.toml` 时修改 `uv.toml` | ||
| 2. 否则,当前目录存在 `pyproject.toml` 时修改其中的 `[tool.uv]` | ||
| 3. 两者都不存在时创建 `uv.toml` | ||
|
|
||
| 这个顺序与 uv 的行为一致:同一目录同时存在 `uv.toml` 与 `pyproject.toml` 的 `[tool.uv]` 时,uv 优先使用 `uv.toml` 中的对应字段。 | ||
|
|
||
| 用户作用域使用 uv 的用户配置目录:Windows 为 `%APPDATA%\uv\uv.toml`,Linux 和 macOS 优先使用 `$XDG_CONFIG_HOME/uv/uv.toml`,未设置时使用 `~/.config/uv/uv.toml`。 | ||
|
|
||
| <br> | ||
|
|
||
| ## Python 包索引 | ||
|
|
||
| 索引 URL 必须指向兼容 Python Simple Repository API 的地址,通常以 `/simple` 结尾;uv 不要求 URL 必须以 `/` 结尾。 | ||
|
|
||
| `default = true` 表示该 index 替代 uv 内置的 PyPI,并且始终具有最低 index 优先级。它不表示“文本中的第一个”或“最高优先级”。配置中存在多个 index 时,chsrc 优先更新 `default = true` 的 index;没有 default index 时才更新第一个 index。 | ||
|
|
||
| 默认的 `first-index` 策略会在第一个包含目标包的 index 停止搜索。私有源与公共镜像并存时,不应把它理解成跨所有 index 选择全局最新版本。 | ||
|
|
||
| <br> | ||
|
|
||
| ## Python 下载镜像 | ||
|
|
||
| `python-install-mirror` 是 `https://github.com/astral-sh/python-build-standalone/releases/download` 的替换前缀。配置值必须是镜像侧对应的 `releases/download` 基址,不能是仓库主页、某个具体构建日期或某个归档文件。uv 会在其后追加构建日期和 | ||
| 归档文件名。 | ||
|
|
||
| 官方示例使用不带尾部 `/` 的基址,chsrc 内置源也遵循该形式。 | ||
|
|
||
| <br> | ||
|
|
||
| ## reset 与备份 | ||
|
|
||
| `chsrc set uv` 修改已有配置前会创建 `.bak` 备份。 | ||
|
|
||
| `chsrc reset uv` 把 chsrc 管理的 index 与 `python-install-mirror` 写回默认上游:index 恢复为 `https://pypi.org/simple`, | ||
| `python-install-mirror` 恢复为 `https://github.com/astral-sh/python-build-standalone/releases/download`。 | ||
| 其他用户配置原样保留,不依赖 `.bak` 恢复旧 URL。 | ||
|
|
||
| 指定镜像代码时,若该代码同时提供 PyPI 与 Python 下载镜像(例如 `nju`),两部分使用同一镜像代码;仅提供其中一类时,另一类自动测速。用户自定义 URL 只解释为 PyPI index URL,因为 Python 下载镜像要求完全不同的 releases 目录布局。 | ||
|
|
||
| `default = true` 的 index(不存在时取第一个)被视为 PyPI 替代源,reset 只修改这一处;私有 index 不受影响。 | ||
|
|
||
| <br> | ||
|
|
||
| ## 实现边界 | ||
|
|
||
| 配置改写器只解析 chsrc 使用的 TOML 子集,但支持常见的行首缩进、CRLF、行尾注释、多个 index,以及位于 `[tool.uv.sources]` 等子表之后的 `[[tool.uv.index]]`。读取时换行统一为 LF 处理,写入时按系统平台输出行尾(Windows 为 CRLF,其余为 LF)。多行字符串和完整 TOML 转义语义不属于该轻量改写器的支持范围。 | ||
|
|
||
| 参考: | ||
|
|
||
| - [uv index 设置](https://docs.astral.sh/uv/reference/settings/#index) | ||
| - [uv python-install-mirror 设置](https://docs.astral.sh/uv/reference/settings/#python-install-mirror) | ||
| - [uv 配置文件](https://docs.astral.sh/uv/concepts/configuration-files/) | ||
| - [uv package indexes](https://docs.astral.sh/uv/concepts/indexes/) | ||
|
|
||
| <br> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.