如何使用uv修改python包版本?

问题描述 投票:0回答:1

Poetry 有 version 命令来增加包版本。 uv包管理器有类似的人吗?

python python-packaging uv
1个回答
0
投票

目前

uv
包管理器没有像 poerty 的
version
命令那样的内置命令来更改包版本。您可以手动
pyproject.toml
或使用脚本自动化

例如:

import toml

def bump_version(file_path, part="patch"):
    with open(file_path, "r") as f:
        pyproject = toml.load(f)
    
    version = pyproject["tool"]["poetry"]["version"]
    major, minor, patch = map(int, version.split("."))

    if part == "major":
        major += 1
        minor = 0
        patch = 0
    elif part == "minor":
        minor += 1
        patch = 0
    elif part == "patch":
        patch += 1

    pyproject["tool"]["poetry"]["version"] = f"{major}.{minor}.{patch}"

    with open(file_path, "w") as f:
        toml.dump(pyproject, f)

    print(f"Version bumped to {major}.{minor}.{patch}")

希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.