跳转到主要内容

从主分支回滚CPython更改到维护分支。

项目描述

使用方法(从复制的CPython目录中)

cherry_picker [--pr-remote REMOTE] [--upstream-remote REMOTE] [--dry-run] [--config-path CONFIG-PATH] [--status] [--abort/--continue] [--push/--no-push] [--auto-pr/--no-auto-pr] <commit_sha1> <branches>

pyversion status pypi status github actions status

关于

此工具用于将CPython的更改从main分支回移植到维护分支之一或多个(3.63.52.7)。

cherry_picker可以配置为将其他具有类似工作流程的项目回移植。有关更多详细信息,请参阅以下配置文件选项。

维护分支名称应包含某种版本号(X.Y)。例如:3.63.52.7stable-2.62.5-lts,都是支持的分支名称。

它将在提交信息前添加分支名,例如[3.6],然后打开拉取请求页面。

测试应使用pytest编写。

设置信息

需要Python 3.8+。

$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ python -m pip install cherry_picker

cherry picking脚本假设如果定义了upstream远程,则应将其用作上游更改的来源和cherry-pick分支的基。否则,使用origin来完成此目的。您可以使用--upstream-remote选项来覆盖此行为(例如,使用名为python的远程,请使用--upstream-remote python)。

验证是否已将upstream远程设置为CPython存储库

$ git remote -v
...
upstream    https://github.com/python/cpython (fetch)
upstream    https://github.com/python/cpython (push)

如有必要,创建upstream远程

$ git remote add upstream https://github.com/python/cpython.git

默认情况下,用于提交拉取请求的PR分支会推送到origin。如果这不正确,则需要使用--pr-remote选项指定正确的远程(例如,使用名为pr的远程,请使用--pr-remote pr)。

Cherry-picking 🐍🍒⛏️

(先设置!请参阅上一节)

从克隆的CPython目录

(venv) $ cherry_picker [--pr-remote REMOTE] [--upstream-remote REMOTE] [--dry-run] [--config-path CONFIG-PATH] [--abort/--continue] [--status] [--push/--no-push] [--auto-pr/--no-auto-pr] <commit_sha1> <branches>

提交sha1

用于cherry-picking的提交sha1是合并到main分支的压缩提交。在合并的拉取请求中,滚动到页面底部。找到类似以下的事件:

<coredeveloper> merged commit <commit_sha1> into python:main <sometime> ago.

通过点击<commit_sha1>链接,您将获得完整的提交哈希。请使用完整的提交哈希为cherry_picker.py

选项

--dry-run                 Dry Run Mode.  Prints out the commands, but not executed.
--pr-remote REMOTE        Specify the git remote to push into.  Default is 'origin'.
--upstream-remote REMOTE  Specify the git remote to use for upstream branches.
                          Default is 'upstream' or 'origin' if the former doesn't exist.
--status                  Do `git status` in cpython directory.

其他选项

--abort        Abort current cherry-pick and clean up branch
--continue     Continue cherry-pick, push, and clean up branch
--no-push      Changes won't be pushed to remote
--no-auto-pr   PR creation page won't be automatically opened in the web browser or
               if GH_AUTH is set, the PR won't be automatically opened through API.
--config-path  Path to config file
               (`.cherry_picker.toml` from project root by default)

配置文件示例

team = "aio-libs"
repo = "aiohttp"
check_sha = "f382b5ffc445e45a110734f5396728da7914aeb6"
fix_commit_msg = false
default_branch = "devel"

可用的配置选项

team            github organization or individual nick,
                e.g "aio-libs" for https://github.com/aio-libs/aiohttp
                ("python" by default)

repo            github project name,
                e.g "aiohttp" for https://github.com/aio-libs/aiohttp
                ("cpython" by default)

check_sha       A long hash for any commit from the repo,
                e.g. a sha1 hash from the very first initial commit
                ("7f777ed95a19224294949e1b4ce56bbffcb1fe9f" by default)

fix_commit_msg  Replace # with GH- in cherry-picked commit message.
                It is the default behavior for CPython because of external
                Roundup bug tracker (https://bugs.python.org) behavior:
                #xxxx should point on issue xxxx but GH-xxxx points
                on pull-request xxxx.
                For projects using GitHub Issues, this option can be disabled.

default_branch  Project's default branch name,
                e.g "devel" for https://github.com/ansible/ansible
                ("main" by default)

为其他项目自定义工具

  1. 在项目的根文件夹(与.git文件夹一起)中创建一个名为.cherry_picker.toml的文件。

  2. 添加如上所述的teamrepofix_commit_msgcheck_shadefault_branch配置值。

  3. 使用git add .cherry_picker.toml / git commit将配置添加到git中。

  4. cherry_picker添加到开发依赖项或通过pip install cherry_picker进行安装。

  5. 现在一切准备就绪,使用cherry_picker <commit_sha> <branch1> <branch2><commit_sha>中的更改cherry-picking到维护分支。分支名称应至少包含主版本号和次版本号,并可能有一些前缀或后缀。提取版本时,仅匹配版本字符串中的第一个类似版本子字符串。

演示

  • 安装:[链接](https://asciinema.org/a/125254)

  • 回移植:[链接](https://asciinema.org/a/125256)

示例

例如,要将 6de2b7817f-some-commit-sha1-d064 cherry-pick 到 3.53.6,请在克隆的 CPython 目录中运行以下命令

(venv) $ cherry_picker 6de2b7817f-some-commit-sha1-d064 3.5 3.6

这将执行的操作

(venv) $ git fetch upstream

(venv) $ git checkout -b backport-6de2b78-3.5 upstream/3.5
(venv) $ git cherry-pick -x 6de2b7817f-some-commit-sha1-d064
(venv) $ git push origin backport-6de2b78-3.5
(venv) $ git checkout main
(venv) $ git branch -D backport-6de2b78-3.5

(venv) $ git checkout -b backport-6de2b78-3.6 upstream/3.6
(venv) $ git cherry-pick -x 6de2b7817f-some-commit-sha1-d064
(venv) $ git push origin backport-6de2b78-3.6
(venv) $ git checkout main
(venv) $ git branch -D backport-6de2b78-3.6

如果发生合并冲突或错误,将显示以下消息

Failed to cherry-pick 554626ada769abf82a5dabe6966afa4265acb6a6 into 2.7 :frowning_face:
... Stopping here.

To continue and resolve the conflict:
    $ cherry_picker --status  # to find out which files need attention
    # Fix the conflict
    $ cherry_picker --status  # should now say 'all conflict fixed'
    $ cherry_picker --continue

To abort the cherry-pick and cleanup:
    $ cherry_picker --abort

传递 --dry-run 选项将导致脚本打印出它将执行的所有步骤,而实际上并不执行任何操作。例如

$ cherry_picker --dry-run --pr-remote pr 1e32a1be4a1705e34011770026cb64ada2d340b5 3.6 3.5
Dry run requested, listing expected command sequence
fetching upstream ...
dry_run: git fetch origin
Now backporting '1e32a1be4a1705e34011770026cb64ada2d340b5' into '3.6'
dry_run: git checkout -b backport-1e32a1b-3.6 origin/3.6
dry_run: git cherry-pick -x 1e32a1be4a1705e34011770026cb64ada2d340b5
dry_run: git push pr backport-1e32a1b-3.6
dry_run: Create new PR: https://github.com/python/cpython/compare/3.6...ncoghlan:backport-1e32a1b-3.6?expand=1
dry_run: git checkout main
dry_run: git branch -D backport-1e32a1b-3.6
Now backporting '1e32a1be4a1705e34011770026cb64ada2d340b5' into '3.5'
dry_run: git checkout -b backport-1e32a1b-3.5 origin/3.5
dry_run: git cherry-pick -x 1e32a1be4a1705e34011770026cb64ada2d340b5
dry_run: git push pr backport-1e32a1b-3.5
dry_run: Create new PR: https://github.com/python/cpython/compare/3.5...ncoghlan:backport-1e32a1b-3.5?expand=1
dry_run: git checkout main
dry_run: git branch -D backport-1e32a1b-3.5

–pr-remote选项

这将通过除了 origin 之外的远程服务器生成 pull request(例如 pr

–upstream-remote选项

这将从除了 upstream/origin 之外的远程服务器生成分支(例如 python

–status选项

这将对 CPython 目录执行 git status

–abort选项

取消当前的 cherry-pick 并清理 cherry-pick 分支。

–continue选项

继续当前的 cherry-pick,提交,将当前分支推送到 origin,打开 PR 页面,并清理分支。

–no-push选项

更改不会被推送到远程。这允许您进行测试和做出更多更改。一旦您对本地更改满意,请使用 --continue 完成回滚,或使用 --abort 取消并清理分支。您还可以通过以下方式 cherry-pick 其他提交

$ git cherry-pick -x <commit_sha1>

–no-auto-pr选项

PR 创建页面不会在网页浏览器中自动打开,或者如果设置了 GH_AUTH,则通过 API 自动打开 PR。如果您的终端无法打开有用的网页浏览器,或者如果您使用与 GitHub 不同的 Git 托管服务,这可能会很有用。

–config-path选项

允许使用自定义路径覆盖默认配置文件路径(<PROJ-ROOT>/.cherry_picker.toml)。这允许 cherry_picker 回滚除 CPython 之外的项目。

创建拉取请求

当 cherry-pick 成功应用后,此脚本将打开一个指向 pull request 创建页面的浏览器标签。

pull request 页面的网址类似于以下内容

https://github.com/python/cpython/compare/3.5...<username>:backport-6de2b78-3.5?expand=1

点击 Create Pull Request 按钮。

Bedevere 将从针对 main 的原始 pull request 中删除 needs backport to ... 标签。

运行测试

安装 pytest: pip install -U pytest

$ pytest

测试要求您的本地 git 版本为 2.28.0+

发布到PyPI

  • 创建一个新的发布分支。

  • __init__.pyreadme.rst 中更新版本信息,删除 .dev

  • 将分支标记为 cherry-picker-vX.Y.Z

本地安装

安装了 flit 的,在存在 pyproject.toml 的目录中

$ flit install

变更日志

2.2.0

  • 添加日志信息

  • 冲突处理的修复,正确获取状态。(PR 88

  • 停止支持 Python 3.7(《a href="https://github.com/python/cherry-picker/pull/90" rel="nofollow">PR 90)

2.1.0

  • 混合修复:#28、#29、#31、#32、#33、#34、#36。

2.0.0

  • 默认支持 main 分支。(PR 23)要使用不同的默认分支,请在该 .cherry-picker.toml 文件中进行配置。

  • cherry-picker 的默认分支重命名为 main

1.3.2

  • 在获取上游时使用 --no-tags 选项。(PR 319

1.3.1

  • 更新 cherry_picker 的 pyproject.toml 文件。(PR #316

  • 删除 BACKPORT_COMPLETE 状态。当回端口完成后取消设置状态。(PR #315

  • 在 Windows 上运行 Travis CI 测试。(PR #311

1.3.0

  • 实现状态机,并使用提交哈希和本地 Git 配置存储回端口过程开始时使用的配置引用。(PR #295

1.2.2

  • 放宽 click 依赖。(PR #302

1.2.1

  • 使用 --continue 验证要操作的分支名称,如果分支无法由 cherry_picker 创建,则尽早失败。(PR #266

  • 错误修复:允许 --continue 支持包含破折号的版本分支。这是对 1.2.0 中引入的附加分支版本方案的错误修复。(PR #265

  • 错误修复:明确指定要推送 cherry pick 的远程分支名称。这允许 cherry_picker 在用户有除默认配置之外的 git push 策略时正确工作。(PR #264

1.2.0

  • 添加 default_branch 配置项。默认为 master,它是 CPython 的默认分支。它可以配置为其他分支,如 develdevelop。默认分支是 cherry_picker 在回端口后返回的分支。(PR #254问题 #250

  • 支持额外的分支版本方案,例如 something-X.YX.Y-somethingelse。(PR #253问题 #251

1.1.1

  • subprocess 的调用更改为使用列表而不是字符串。这修复了影响 Windows 用户的问题。(PR #238

1.1.0

  • 添加 fix_commit_msg 配置项。将 fix_commit_msg 设置为 true 将替换提交消息中的问题编号,从 #GH-。这是 CPython 的默认行为。其他项目可以通过将其设置为 false 来选择退出。(PR #233aiohttp 问题 #2853

1.0.0

  • 通过使用 --config-path 选项或添加 .cherry-picker.toml 文件到项目的根目录来支持配置文件。(问题 #225

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

cherry_picker-2.2.0.tar.gz (29.3 kB 查看散列值)

上传时间

构建分布

cherry_picker-2.2.0-py3-none-any.whl (26.4 kB 查看散列值)

上传时间 Python 3

由以下提供支持