From 9ab4f632e174b35067e65a9df2299a544d4bd6a8 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 4 Oct 2022 15:01:54 -0700 Subject: [PATCH 01/45] Upgrade to GitHub-native Dependabot (#22) * Upgrade to GitHub-native Dependabot * Update .github/dependabot.yml Co-authored-by: Hugo van Kemenade Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Mariatta Wijaya Co-authored-by: Jelle Zijlstra Co-authored-by: Hugo van Kemenade --- .github/dependabot.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..c990752 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: +- package-ecosystem: pip + directory: "/" + schedule: + interval: monthly + open-pull-requests-limit: 10 From 9c64d2c2cec425cc659c004af849fd181c55fca0 Mon Sep 17 00:00:00 2001 From: uddmorningsun Date: Wed, 5 Oct 2022 06:20:31 +0800 Subject: [PATCH 02/45] Fix --dry-run option incorrect behaviour (#75) ``` # No setting upstream, so output command sequence should print origin root@2ec8214d91c9:/tmp/cpython# git remote get-url upstream error: No such remote 'upstream' ``` ``` root@2ec8214d91c9:/tmp/cpython# cherry_picker --dry-run ab5b56ba6d 3.7 ... ... Dry run requested, listing expected command sequence dry-run: git remote get-url upstream dry-run: git fetch upstream --no-tags Now backporting 'ab5b56ba6d' into '3.7' dry-run: git remote get-url upstream dry-run: git checkout -b backport-ab5b56b-3.7 upstream/3.7 dry-run: git cherry-pick -x ab5b56ba6d dry-run: git show -s --format=%B ab5b56ba6d Traceback (most recent call last): ... ... File "/usr/local/lib/python3.10/dist-packages/cherry_picker/cherry_picker.py", line 645, in cherry_pick_cli cherry_picker.backport() File "/usr/local/lib/python3.10/dist-packages/cherry_picker/cherry_picker.py", line 387, in backport commit_message = self.amend_commit_message(cherry_pick_branch) File "/usr/local/lib/python3.10/dist-packages/cherry_picker/cherry_picker.py", line 269, in amend_commit_message updated_commit_message = f"""{commit_prefix}{self.get_commit_message(self.commit_sha1)} File "/usr/local/lib/python3.10/dist-packages/cherry_picker/cherry_picker.py", line 211, in get_commit_message message = self.run_cmd(cmd).strip() AttributeError: 'NoneType' object has no attribute 'strip' ``` Signed-off-by: Chenyang Yan Signed-off-by: Chenyang Yan --- cherry_picker/cherry_picker.py | 12 ++++++------ cherry_picker/test_cherry_picker.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 4512581..3a7458f 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -173,7 +173,7 @@ def upstream(self): cmd[-1] = self.upstream_remote try: - self.run_cmd(cmd) + self.run_cmd(cmd, required_real_result=True) except subprocess.CalledProcessError: if self.upstream_remote is not None: raise ValueError(f"There is no remote with name {cmd[-1]!r}.") @@ -196,7 +196,7 @@ def sorted_branches(self): @property def username(self): cmd = ["git", "config", "--get", f"remote.{self.pr_remote}.url"] - result = self.run_cmd(cmd) + result = self.run_cmd(cmd, required_real_result=True) # implicit ssh URIs use : to separate host from user, others just use / username = result.replace(":", "/").split("/")[-2] return username @@ -214,9 +214,9 @@ def fetch_upstream(self): self.run_cmd(cmd) set_state(WORKFLOW_STATES.FETCHED_UPSTREAM) - def run_cmd(self, cmd): + def run_cmd(self, cmd, required_real_result=False): assert not isinstance(cmd, str) - if self.dry_run: + if not required_real_result and self.dry_run: click.echo(f" dry-run: {' '.join(cmd)}") return output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) @@ -252,7 +252,7 @@ def get_commit_message(self, commit_sha): """ cmd = ["git", "show", "-s", "--format=%B", commit_sha] try: - message = self.run_cmd(cmd).strip() + message = self.run_cmd(cmd, required_real_result=True).strip() except subprocess.CalledProcessError as err: click.echo(f"Error getting commit message for {commit_sha}") click.echo(err.output) @@ -665,7 +665,7 @@ def is_mirror(self) -> bool: cmd = ["git", "config", "--local", "--get", "remote.origin.mirror"] try: - out = self.run_cmd(cmd) + out = self.run_cmd(cmd, required_real_result=True) except subprocess.CalledProcessError: return False return out.startswith("true") diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index b76616d..a450a99 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -741,7 +741,7 @@ def test_start_end_states(method_name, start_state, end_state, tmp_git_repo_dir) cherry_picker.remember_previous_branch() assert get_state() == WORKFLOW_STATES.UNSET - def _fetch(cmd): + def _fetch(cmd, *args, **kwargs): assert get_state() == start_state with mock.patch.object(cherry_picker, "run_cmd", _fetch): From b68184fdf076d8389a771e9e50b019e82713e65b Mon Sep 17 00:00:00 2001 From: Jakub Kuczys Date: Wed, 5 Oct 2022 00:26:34 +0200 Subject: [PATCH 03/45] Update project configuration to use PEP 621 (#77) --- pyproject.toml | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b531444..efa08c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,22 +1,34 @@ [build-system] -requires = ["flit"] -build-backend = "flit.buildapi" +requires = ["flit_core>=3.2,<4"] +build-backend = "flit_core.buildapi" -[tool.flit.metadata] -module = "cherry_picker" -author = "Mariatta Wijaya" -author-email = "mariatta@python.org" -maintainer = "Python Core Developers" -maintainer-email = "core-workflow@python.org" -home-page = "https://github.com/python/cherry_picker" -requires = ["click>=6.0", "gidgethub", "requests", "tomli>=1.1.0;python_version<'3.11'"] -description-file = "readme.rst" -classifiers = ["Programming Language :: Python :: 3.7", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License"] +[project] +name = "cherry_picker" +authors = [{ name = "Mariatta Wijaya", email = "mariatta@python.org" }] +maintainers = [{ name = "Python Core Developers", email = "core-workflow@python.org" }] +dependencies = [ + "click>=6.0", + "gidgethub", + "requests", + "tomli>=1.1.0;python_version<'3.11'", +] +readme = "readme.rst" +classifiers = [ + "Programming Language :: Python :: 3.7", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", +] requires-python = ">=3.7" +dynamic = ["version", "description"] +[project.urls] +"Homepage" = "https://github.com/python/cherry_picker" -[tool.flit.scripts] +[project.scripts] cherry_picker = "cherry_picker.cherry_picker:cherry_pick_cli" -[tool.flit.metadata.requires-extra] -dev = ["pytest", "pytest-cov"] +[project.optional-dependencies] +dev = [ + "pytest", + "pytest-cov", +] From 2c1f6b9f52162f157373f8815bd23643f00e432b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 4 Oct 2022 16:36:04 -0700 Subject: [PATCH 04/45] Remove filtered warning after fixed dependency released (#74) Co-authored-by: Mariatta Wijaya --- pytest.ini | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pytest.ini b/pytest.ini index af8028e..bdb4f56 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,9 +3,5 @@ norecursedirs = dist docs build .git .eggs .tox addopts = --durations=10 -v -rxXs --doctest-modules filterwarnings = error - # 3.11: Pending release of https://github.com/certifi/python-certifi/pull/199 - ignore:path is deprecated. Use files\(\) instead.*:DeprecationWarning - # 3.11: Pending release of https://github.com/brettcannon/gidgethub/pull/185 - ignore:'cgi' is deprecated and slated for removal in Python 3.13:DeprecationWarning junit_duration_report = call junit_suite_name = cherry_picker_test_suite From 49747549b88b88738c2df4c7af71f49ed99bea08 Mon Sep 17 00:00:00 2001 From: Rafael Fontenelle Date: Sat, 22 Apr 2023 15:25:23 -0300 Subject: [PATCH 05/45] Add 3.12 env, enable in GH workflow (#79) --- .github/workflows/main.yml | 3 ++- tox.ini | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 48c10e6..9a518f7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,8 @@ jobs: - 3.8 - 3.9 - "3.10" - - "3.11-dev" + - "3.11" + - "3.12-dev" platform: - ubuntu-latest - macos-latest diff --git a/tox.ini b/tox.ini index b5ddc4c..1fac32c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{311, 310, 39, 38, 37} + py{312, 311, 310, 39, 38, 37} isolated_build = true [testenv] From 05c8f91a426320a2d7635cda61dc140b6ff81d12 Mon Sep 17 00:00:00 2001 From: Rafael Fontenelle Date: Fri, 5 May 2023 11:43:43 -0300 Subject: [PATCH 06/45] Fixes to lint CI (#81) --- .github/workflows/lint_python.yml | 5 +++-- cherry_picker/cherry_picker.py | 2 +- cherry_picker/test_cherry_picker.py | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index ec8e540..2fcbc77 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -10,8 +10,9 @@ jobs: cache: pip cache-dependency-path: .github/workflows/lint_python.yml - run: pip install --upgrade pip wheel - - run: pip install bandit black codespell flake8 flake8-bugbear - flake8-comprehensions isort mypy pyupgrade safety + # TODO: remove setuptools installation when safety==2.4.0 is released + - run: pip install --upgrade bandit black codespell flake8 flake8-bugbear + flake8-comprehensions isort mypy pyupgrade safety setuptools - run: bandit --recursive --skip B101,B404,B603 . - run: black --diff . - run: codespell --ignore-words-list="commitish" diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 3a7458f..628012d 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -440,7 +440,7 @@ def create_gh_pr(self, base_branch, head_branch, *, commit_message, gh_auth): "maintainer_can_modify": True, } url = CREATE_PR_URL_TEMPLATE.format(config=self.config) - response = requests.post(url, headers=request_headers, json=data) + response = requests.post(url, headers=request_headers, json=data, timeout=10) if response.status_code == requests.codes.created: response_data = response.json() click.echo(f"Backport PR created at {response_data['html_url']}") diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index a450a99..45a2562 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -135,6 +135,7 @@ def tmp_git_repo_dir(tmpdir, cd, git_init, git_commit, git_config): warnings.warn( "You need git 2.28.0 or newer to run the full test suite.", UserWarning, + stacklevel=2, ) git_config("--local", "user.name", "Monty Python") git_config("--local", "user.email", "bot@python.org") From 30942cfdf9db3e1b1783858c7c3949d6584c439a Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 5 May 2023 17:49:15 +0300 Subject: [PATCH 07/45] Update homepage link (#82) --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index efa08c0..6a0c0ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ requires-python = ">=3.7" dynamic = ["version", "description"] [project.urls] -"Homepage" = "https://github.com/python/cherry_picker" +"Homepage" = "https://github.com/python/cherry-picker" [project.scripts] cherry_picker = "cherry_picker.cherry_picker:cherry_pick_cli" From 3e48d193d8ae19001883a25ccb825c39a7f36522 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 5 May 2023 19:02:08 +0300 Subject: [PATCH 08/45] Test Python 3.12 pre-releases (#83) --- .github/workflows/main.yml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9a518f7..283f29e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,21 +7,12 @@ env: jobs: test: + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - python: - - 3.7 - - 3.8 - - 3.9 - - "3.10" - - "3.11" - - "3.12-dev" - platform: - - ubuntu-latest - - macos-latest - - windows-latest - runs-on: ${{ matrix.platform }} + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + os: [windows-latest, macos-latest, ubuntu-latest] steps: - uses: actions/checkout@v3 with: @@ -31,7 +22,8 @@ jobs: - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python }} + python-version: ${{ matrix.python-version }} + allow-prereleases: true cache: pip cache-dependency-path: pyproject.toml - name: Install tox @@ -55,7 +47,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: "3.x" cache: pip cache-dependency-path: .github/workflows/main.yml - name: Install tools From e4ece758fec984d94d7d8e0a9f2e9e63e170bffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Tue, 15 Aug 2023 22:26:02 +0200 Subject: [PATCH 09/45] Unset backport branch's remote from upstream (#85) This way the user can easily commit and push further changes to the backport, if needed, without having to remember to append their fork's remote name to `git push`. The branch sets the upstream as the remote during `git checkout -b`. This isn't a useful default as we push the resulting backport to the user's fork anyway and it is never intended to either merge further upstream changes nor to push to upstream directly. --- cherry_picker/cherry_picker.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 628012d..0427f94 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -109,7 +109,6 @@ def __init__( chosen_config_path=None, auto_pr=True, ): - self.chosen_config_path = chosen_config_path """The config reference used in the current runtime. @@ -239,11 +238,11 @@ def checkout_branch(self, branch_name, *, create_branch=False): try: self.run_cmd(cmd) except subprocess.CalledProcessError as err: - click.echo( - f"Error checking out the branch {checked_out_branch!r}." - ) + click.echo(f"Error checking out the branch {checked_out_branch!r}.") click.echo(err.output) raise BranchCheckoutException(checked_out_branch) + if create_branch: + self.unset_upstream(checked_out_branch) def get_commit_message(self, commit_sha): """ @@ -485,6 +484,13 @@ def cleanup_branch(self, branch): click.echo(f"branch {branch} has been deleted.") set_state(WORKFLOW_STATES.REMOVED_BACKPORT_BRANCH) + def unset_upstream(self, branch): + cmd = ["git", "branch", "--unset-upstream", branch] + try: + return self.run_cmd(cmd) + except subprocess.CalledProcessError as cpe: + click.echo(cpe.output) + def backport(self): if not self.branches: raise click.UsageError("At least one branch must be specified.") From e4f927d85b084d2097514973afdf739acaf2cdd7 Mon Sep 17 00:00:00 2001 From: Mariatta Date: Tue, 10 Oct 2023 16:01:49 +0200 Subject: [PATCH 10/45] When raising error, show the current state vs expected state (#87) --- cherry_picker/cherry_picker.py | 4 +++- cherry_picker/test_cherry_picker.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 0427f94..ec5ddc4 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -541,7 +541,9 @@ def abort_cherry_pick(self): run `git cherry-pick --abort` and then clean up the branch """ if self.initial_state != WORKFLOW_STATES.BACKPORT_PAUSED: - raise ValueError("One can only abort a paused process.") + raise ValueError( + f"One can only abort a paused process. Current state: {self.initial_state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}" + ) try: validate_sha("CHERRY_PICK_HEAD") diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index 45a2562..0cdd96b 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -1,5 +1,6 @@ import os import pathlib +import re import subprocess import warnings from collections import ChainMap @@ -1141,7 +1142,7 @@ def test_continue_cherry_pick_invalid_state(tmp_git_repo_dir): assert get_state() == WORKFLOW_STATES.UNSET - with pytest.raises(ValueError, match=r"^One can only continue a paused process.$"): + with pytest.raises(ValueError, match=re.compile(r"^One can only continue a paused process.")): cherry_picker.continue_cherry_pick() assert get_state() == WORKFLOW_STATES.UNSET # success @@ -1167,7 +1168,7 @@ def test_abort_cherry_pick_invalid_state(tmp_git_repo_dir): assert get_state() == WORKFLOW_STATES.UNSET - with pytest.raises(ValueError, match=r"^One can only abort a paused process.$"): + with pytest.raises(ValueError, match=re.compile(r"^One can only abort a paused process.")): cherry_picker.abort_cherry_pick() From b471da1bebb6de160e34f7127ceaa5b20b600434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Wed, 11 Oct 2023 11:49:17 +0200 Subject: [PATCH 11/45] Remove `initial_state` as it gets out of sync with what's in .git/config (#88) Run get_state_and_verify() as part of check_repo() --- cherry_picker/cherry_picker.py | 18 +++++++++++------- cherry_picker/test_cherry_picker.py | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index ec5ddc4..c3c6e60 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -119,7 +119,6 @@ def __init__( self.config = config self.check_repo() # may raise InvalidRepoException - self.initial_state = self.get_state_and_verify() """The runtime state loaded from the config. Used to verify that we resume the process from the valid @@ -540,9 +539,10 @@ def abort_cherry_pick(self): """ run `git cherry-pick --abort` and then clean up the branch """ - if self.initial_state != WORKFLOW_STATES.BACKPORT_PAUSED: + state = self.get_state_and_verify() + if state != WORKFLOW_STATES.BACKPORT_PAUSED: raise ValueError( - f"One can only abort a paused process. Current state: {self.initial_state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}" + f"One can only abort a paused process. Current state: {state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}" ) try: @@ -572,8 +572,11 @@ def continue_cherry_pick(self): open the PR clean up branch """ - if self.initial_state != WORKFLOW_STATES.BACKPORT_PAUSED: - raise ValueError("One can only continue a paused process.") + state = self.get_state_and_verify() + if state != WORKFLOW_STATES.BACKPORT_PAUSED: + raise ValueError( + f"One can only continue a paused process. Current state: {state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}" + ) cherry_pick_branch = get_current_branch() if cherry_pick_branch.startswith("backport-"): @@ -637,8 +640,9 @@ def check_repo(self): """ try: validate_sha(self.config["check_sha"]) - except ValueError: - raise InvalidRepoException() + self.get_state_and_verify() + except ValueError as ve: + raise InvalidRepoException(ve.args[0]) def get_state_and_verify(self): """Return the run progress state stored in the Git config. diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index 0cdd96b..d99ea81 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -862,7 +862,7 @@ class tested_state: ) with mock.patch( "cherry_picker.cherry_picker.validate_sha", return_value=True - ), pytest.raises(ValueError, match=expected_msg_regexp): + ), pytest.raises(InvalidRepoException, match=expected_msg_regexp): cherry_picker = CherryPicker("origin", "xxx", []) From f59f7b7d10eb816762eff506c349ff4ab0df06d4 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 11 Oct 2023 12:49:03 +0200 Subject: [PATCH 12/45] Drop support for EOL Python 3.7 (#90) --- .github/workflows/lint_python.yml | 2 +- .github/workflows/main.yml | 2 +- pyproject.toml | 4 ++-- readme.rst | 2 +- tox.ini | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 2fcbc77..49d832c 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -21,5 +21,5 @@ jobs: - run: isort --check-only --profile black . - run: pip install --editable . - run: mypy --ignore-missing-imports --install-types --non-interactive . - - run: shopt -s globstar && pyupgrade --py37-plus **/*.py || true + - run: shopt -s globstar && pyupgrade --py38-plus **/*.py || true - run: safety check diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 283f29e..7e9197b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] os: [windows-latest, macos-latest, ubuntu-latest] steps: - uses: actions/checkout@v3 diff --git a/pyproject.toml b/pyproject.toml index 6a0c0ee..e47b7eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,11 +14,11 @@ dependencies = [ ] readme = "readme.rst" classifiers = [ - "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", ] -requires-python = ">=3.7" +requires-python = ">=3.8" dynamic = ["version", "description"] [project.urls] diff --git a/readme.rst b/readme.rst index 6028338..32392d2 100644 --- a/readme.rst +++ b/readme.rst @@ -30,7 +30,7 @@ Tests are to be written using `pytest `_. Setup Info ========== -Requires Python 3.7. +Requires Python 3.8+. .. code-block:: console diff --git a/tox.ini b/tox.ini index 1fac32c..d41abed 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{312, 311, 310, 39, 38, 37} + py{312, 311, 310, 39, 38} isolated_build = true [testenv] From 1957e38b635bb98738fa7b33a3879e896455f96c Mon Sep 17 00:00:00 2001 From: Mariatta Date: Wed, 11 Oct 2023 13:40:33 +0200 Subject: [PATCH 13/45] v2.2.0 release (#89) --- cherry_picker/__init__.py | 2 +- readme.rst | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cherry_picker/__init__.py b/cherry_picker/__init__.py index bc80576..5636972 100644 --- a/cherry_picker/__init__.py +++ b/cherry_picker/__init__.py @@ -1,2 +1,2 @@ """Backport CPython changes from main to maintenance branches.""" -__version__ = "2.1.0" +__version__ = "2.2.0" diff --git a/readme.rst b/readme.rst index 32392d2..7724ce5 100644 --- a/readme.rst +++ b/readme.rst @@ -367,6 +367,13 @@ in the directory where ``pyproject.toml`` exists: Changelog ========= +2.2.0 +----- + +- Add log messages +- Fix for conflict handling, get the state correctly. (`PR 88 `_) +- Drop support for Python 3.7 (`PR 90 `_) + 2.1.0 ----- From 38fcdad507d96b00338acdb84f965367c594614c Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Thu, 12 Oct 2023 10:14:19 +0200 Subject: [PATCH 14/45] Publish to PyPI using Trusted Publishers (#94) Co-authored-by: Mariatta --- .github/workflows/deploy.yml | 71 ++++++++++++++++++++++++++++++++++++ cherry_picker/__init__.py | 4 +- pyproject.toml | 58 ++++++++++++++++++----------- 3 files changed, 110 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..fb242cc --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,71 @@ +name: Build package + +on: + push: + pull_request: + release: + types: + - published + workflow_dispatch: + +permissions: + contents: read + +jobs: + # Always build & lint package. + build-package: + name: Build & verify package + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: hynek/build-and-inspect-python-package@v1 + + # Publish to Test PyPI on every commit on main. + release-test-pypi: + name: Publish in-dev package to test.pypi.org + if: | + github.repository_owner == 'python' + && github.event_name == 'push' + && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + needs: build-package + + permissions: + id-token: write + + steps: + - name: Download packages built by build-and-inspect-python-package + uses: actions/download-artifact@v3 + with: + name: Packages + path: dist + + - name: Publish to Test PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + + # Publish to PyPI on GitHub Releases. + release-pypi: + name: Publish to PyPI + # Only run for published releases. + if: | + github.repository_owner == 'python' + && github.event.action == 'published' + runs-on: ubuntu-latest + needs: build-package + + permissions: + id-token: write + + steps: + - name: Download packages built by build-and-inspect-python-package + uses: actions/download-artifact@v3 + with: + name: Packages + path: dist + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/cherry_picker/__init__.py b/cherry_picker/__init__.py index 5636972..b654ebc 100644 --- a/cherry_picker/__init__.py +++ b/cherry_picker/__init__.py @@ -1,2 +1,4 @@ """Backport CPython changes from main to maintenance branches.""" -__version__ = "2.2.0" +import importlib.metadata + +__version__ = importlib.metadata.version(__name__) diff --git a/pyproject.toml b/pyproject.toml index e47b7eb..1fc22dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,34 +1,48 @@ [build-system] -requires = ["flit_core>=3.2,<4"] -build-backend = "flit_core.buildapi" +build-backend = "hatchling.build" +requires = [ + "hatch-vcs", + "hatchling", +] [project] -name = "cherry_picker" -authors = [{ name = "Mariatta Wijaya", email = "mariatta@python.org" }] +name = "cherry-picker" +readme = "readme.rst" maintainers = [{ name = "Python Core Developers", email = "core-workflow@python.org" }] +authors = [{ name = "Mariatta Wijaya", email = "mariatta@python.org" }] +requires-python = ">=3.8" +classifiers = [ + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +] +dynamic = [ + "description", + "version", +] dependencies = [ - "click>=6.0", - "gidgethub", - "requests", - "tomli>=1.1.0;python_version<'3.11'", + "click>=6", + "gidgethub", + "requests", + 'tomli>=1.1; python_version < "3.11"', ] -readme = "readme.rst" -classifiers = [ - "Programming Language :: Python :: 3.8", - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", +[project.optional-dependencies] +dev = [ + "pytest", + "pytest-cov", ] -requires-python = ">=3.8" -dynamic = ["version", "description"] - [project.urls] "Homepage" = "https://github.com/python/cherry-picker" - [project.scripts] cherry_picker = "cherry_picker.cherry_picker:cherry_pick_cli" -[project.optional-dependencies] -dev = [ - "pytest", - "pytest-cov", -] +[tool.hatch] +version.source = "vcs" + +[tool.hatch.version.raw-options] +local_scheme = "no-local-version" From cbf5660a53f86a845da6ee9fc234963a34a4495b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 13 Oct 2023 17:16:58 +0200 Subject: [PATCH 15/45] Fetch tags so hatch-vcs can set the version number (#95) --- .github/workflows/deploy.yml | 2 ++ .github/workflows/main.yml | 24 ------------------------ pyproject.toml | 6 ++++-- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fb242cc..6a79750 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,6 +19,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: hynek/build-and-inspect-python-package@v1 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7e9197b..2eaf4f9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,27 +36,3 @@ jobs: with: flags: ${{ matrix.os }} name: ${{ matrix.os }} Python ${{ matrix.python-version }} - - release: - needs: test - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: "3.x" - cache: pip - cache-dependency-path: .github/workflows/main.yml - - name: Install tools - run: | - python -m pip install build twine - - name: Release - run: | - build . - twine upload dist/* - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} diff --git a/pyproject.toml b/pyproject.toml index 1fc22dc..808cafa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,8 +41,10 @@ dev = [ [project.scripts] cherry_picker = "cherry_picker.cherry_picker:cherry_pick_cli" -[tool.hatch] -version.source = "vcs" +[tool.hatch.version] +source = "vcs" +# Change regex to match tags like "cherry-picker-v2.2.0". +tag-pattern = '^cherry-picker-(?P[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$' [tool.hatch.version.raw-options] local_scheme = "no-local-version" From f458cdfb29713548ead1516d31a60e3033f959fc Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 12 Nov 2023 19:09:27 +0200 Subject: [PATCH 16/45] Add release checklist (#98) Co-authored-by: Ezio Melotti Co-authored-by: Mariatta --- RELEASING.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 RELEASING.md diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..e7b5d7c --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,29 @@ +# Release Checklist + +- [ ] check tests pass on [GitHub Actions](https://github.com/python/cherry-picker/actions) + [![GitHub Actions status](https://github.com/python/cherry-picker/actions/workflows/main.yml/badge.svg)](https://github.com/python/cherry-picker/actions/workflows/main.yml) + +- [ ] Update [changelog](https://github.com/python/cherry-picker#changelog) + +- [ ] Go to [Releases page](https://github.com/python/cherry-picker/releases) and + + - [ ] Click "Draft a new release" + + - [ ] Click "Choose a tag" + + - [ ] Type the next `cherry-picker-vX.Y.Z` version and select "**Create new tag: cherry-picker-vX.Y.Z** on publish" + + - [ ] Leave the "Release title" blank (it will be autofilled) + + - [ ] Click "Generate release notes" and amend as required + + - [ ] Click "Publish release" + +- [ ] Check the tagged [GitHub Actions build] (https://github.com/python/cherry-picker/actions/workflows/deploy.yml) + has deployed to [PyPI] (https://pypi.org/project/cherry_picker/#history) + +- [ ] Check installation: + +```bash +python -m pip uninstall -y cherry_picker && python -m pip install -U cherry_picker && cherry_picker --version +``` From 1b8c9f72fbcf97d2ae2314696bfd4eaf075fa87d Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 31 Dec 2023 17:10:04 +0200 Subject: [PATCH 17/45] Fix Markdown links (#101) Co-authored-by: Alex Waygood --- RELEASING.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/RELEASING.md b/RELEASING.md index e7b5d7c..6f786f6 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -5,7 +5,7 @@ - [ ] Update [changelog](https://github.com/python/cherry-picker#changelog) -- [ ] Go to [Releases page](https://github.com/python/cherry-picker/releases) and +- [ ] Go to the [Releases page](https://github.com/python/cherry-picker/releases) and - [ ] Click "Draft a new release" @@ -19,11 +19,11 @@ - [ ] Click "Publish release" -- [ ] Check the tagged [GitHub Actions build] (https://github.com/python/cherry-picker/actions/workflows/deploy.yml) - has deployed to [PyPI] (https://pypi.org/project/cherry_picker/#history) +- [ ] Check the tagged [GitHub Actions build](https://github.com/python/cherry-picker/actions/workflows/deploy.yml) + has deployed to [PyPI](https://pypi.org/project/cherry_picker/#history) - [ ] Check installation: -```bash -python -m pip uninstall -y cherry_picker && python -m pip install -U cherry_picker && cherry_picker --version -``` + ```bash + python -m pip uninstall -y cherry_picker && python -m pip install -U cherry_picker && cherry_picker --version + ``` From 8b011b21886b87ef9a66ddab612440577e65a594 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 3 Jan 2024 09:05:36 +0200 Subject: [PATCH 18/45] Move changelog to own file (#104) --- CHANGELOG.md | 88 ++++++++++++++++++++++++++++++++++++++++++ RELEASING.md | 2 +- readme.rst | 106 ++------------------------------------------------- 3 files changed, 92 insertions(+), 104 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..09fe12a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,88 @@ +# Changelog + +## 2.2.0 + +- Add log messages +- Fix for conflict handling, get the state correctly ([PR 88](https://github.com/python/cherry-picker/pull/88)) +- Drop support for Python 3.7 ([PR 90](https://github.com/python/cherry-picker/pull/90)) + +## 2.1.0 + +- Mix fixes: #28, #29, #31, #32, #33, #34, #36 + +## 2.0.0 + +- Support the `main` branch by default ([PR 23](https://github.com/python/cherry-picker/pull/23)). + To use a different default branch, please configure it in the + `.cherry-picker.toml` file. + + - Renamed `cherry-picker`'s own default branch to `main` + +## 1.3.2 + +- Use `--no-tags` option when fetching upstream ([PR 319](https://github.com/python/core-workflow/pull/319)) + +## 1.3.1 + +- Modernize cherry_picker's pyproject.toml file ([PR #316](https://github.com/python/core-workflow/pull/316)) + +- Remove the `BACKPORT_COMPLETE` state. Unset the states when backport is completed + ([PR #315](https://github.com/python/core-workflow/pull/315)) + +- Run Travis CI test on Windows ([PR #311](https://github.com/python/core-workflow/pull/311)) + +## 1.3.0 + +- Implement state machine and storing reference to the config + used at the beginning of the backport process using commit sha + and a repo-local Git config. + ([PR #295](https://github.com/python/core-workflow/pull/295)) + +## 1.2.2 + +- Relaxed click dependency ([PR #302](https://github.com/python/core-workflow/pull/302)) + +## 1.2.1 + +- Validate the branch name to operate on with `--continue` and fail early if the branch could not + have been created by cherry_picker ([PR #266](https://github.com/python/core-workflow/pull/266)) + +- Bugfix: Allow `--continue` to support version branches that have dashes in them. This is + a bugfix of the additional branch versioning schemes introduced in 1.2.0. + ([PR #265](https://github.com/python/core-workflow/pull/265)). + +- Bugfix: Be explicit about the branch name on the remote to push the cherry pick to. This allows + cherry_picker to work correctly when the user has a git push strategy other than the default + configured ([PR #264](https://github.com/python/core-workflow/pull/264)). + +## 1.2.0 + +- Add `default_branch` configuration item. The default is `master`, which + is the default branch for CPython. It can be configured to other branches like, + `devel`, or `develop`. The default branch is the branch cherry_picker + will return to after backporting ([PR #254](https://github.com/python/core-workflow/pull/254) + and [Issue #250](https://github.com/python/core-workflow/issues/250)). + +- Support additional branch versioning schemes, such as `something-X.Y`, + or `X.Y-somethingelse`. ([PR #253](https://github.com/python/core-workflow/pull/253) + and [Issue #251](https://github.com/python/core-workflow/issues/251)). + +## 1.1.1 + +- Change the calls to `subprocess` to use lists instead of strings. This fixes + the bug that affects users in Windows + ([PR #238](https://github.com/python/core-workflow/pull/238)). + +## 1.1.0 + +- Add `fix_commit_msg` configuration item. Setting fix_commit_msg to `true` + will replace the issue number in the commit message, from `#` to `GH-`. + This is the default behavior for CPython. Other projects can opt out by + setting it to `false` ([PR #233](https://github.com/python/core-workflow/pull/233) + and [aiohttp issue #2853](https://github.com/aio-libs/aiohttp/issues/2853)). + +## 1.0.0 + +- Support configuration file by using `--config-path` option, or by adding + `.cherry-picker.toml` file to the root of the project + ([Issue #225](https://github.com/python/core-workflow/issues/225)) diff --git a/RELEASING.md b/RELEASING.md index 6f786f6..bd3fecd 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -3,7 +3,7 @@ - [ ] check tests pass on [GitHub Actions](https://github.com/python/cherry-picker/actions) [![GitHub Actions status](https://github.com/python/cherry-picker/actions/workflows/main.yml/badge.svg)](https://github.com/python/cherry-picker/actions/workflows/main.yml) -- [ ] Update [changelog](https://github.com/python/cherry-picker#changelog) +- [ ] Update [changelog](https://github.com/python/cherry-picker/blob/main/CHANGELOG.md) - [ ] Go to the [Releases page](https://github.com/python/cherry-picker/releases) and diff --git a/readme.rst b/readme.rst index 7724ce5..8815a90 100644 --- a/readme.rst +++ b/readme.rst @@ -337,11 +337,7 @@ Tests require your local version of ``git`` to be ``2.28.0+``. Publishing to PyPI ================== -- Create a new release branch. - -- Update the version info in ``__init__.py`` and ``readme.rst``, dropping the ``.dev``. - -- Tag the branch as ``cherry-picker-vX.Y.Z``. +- See the `release checklist `_. Local installation @@ -352,7 +348,7 @@ in the directory where ``pyproject.toml`` exists: .. code-block:: console - $ flit install + $ pip install .. |pyversion status| image:: https://img.shields.io/pypi/pyversions/cherry-picker.svg @@ -367,100 +363,4 @@ in the directory where ``pyproject.toml`` exists: Changelog ========= -2.2.0 ------ - -- Add log messages -- Fix for conflict handling, get the state correctly. (`PR 88 `_) -- Drop support for Python 3.7 (`PR 90 `_) - -2.1.0 ------ - -- Mix fixes: #28, #29, #31, #32, #33, #34, #36. - -2.0.0 ------ - -- Support the ``main`` branch by default. (`PR 23 `_) - To use a different default branch, please configure it in the - ``.cherry-picker.toml`` file. - -- Renamed ``cherry-picker``'s own default branch to ``main``. - -1.3.2 ------ - -- Use ``--no-tags`` option when fetching upstream. (`PR 319 `_) - -1.3.1 ------ - -- Modernize cherry_picker's pyproject.toml file. (`PR #316 `_) - -- Remove the ``BACKPORT_COMPLETE`` state. Unset the states when backport is completed. - (`PR #315 `_) - -- Run Travis CI test on Windows (`PR #311 `_). - -1.3.0 ------ - -- Implement state machine and storing reference to the config - used at the beginning of the backport process using commit sha - and a repo-local Git config. - (`PR #295 `_). - -1.2.2 ------ - -- Relaxed click dependency (`PR #302 `_). - -1.2.1 ------ - -- Validate the branch name to operate on with ``--continue`` and fail early if the branch could not - have been created by cherry_picker. (`PR #266 `_). - -- Bugfix: Allow ``--continue`` to support version branches that have dashes in them. This is - a bugfix of the additional branch versioning schemes introduced in 1.2.0. - (`PR #265 `_). - -- Bugfix: Be explicit about the branch name on the remote to push the cherry pick to. This allows - cherry_picker to work correctly when the user has a git push strategy other than the default - configured. (`PR #264 `_). - -1.2.0 ------ - -- Add ``default_branch`` configuration item. The default is ``master``, which - is the default branch for CPython. It can be configured to other branches like, - ``devel``, or ``develop``. The default branch is the branch cherry_picker - will return to after backporting. (`PR #254 `_ - and `Issue #250 `_). - -- Support additional branch versioning schemes, such as ``something-X.Y``, - or ``X.Y-somethingelse``. (`PR #253 `_ - and `Issue #251 `_). - -1.1.1 ------ - -- Change the calls to ``subprocess`` to use lists instead of strings. This fixes - the bug that affects users in Windows. (`PR #238 `_). - -1.1.0 ------ - -- Add ``fix_commit_msg`` configuration item. Setting fix_commit_msg to ``true`` - will replace the issue number in the commit message, from ``#`` to ``GH-``. - This is the default behavior for CPython. Other projects can opt out by - setting it to ``false``. (`PR #233 `_ - and `aiohttp Issue #2853 `_). - -1.0.0 ------ - -- Support configuration file by using ``--config-path`` option, or by adding - ``.cherry-picker.toml`` file to the root of the project. (`Issue #225 - `_). +See the `changelog `_. From 05d9990674a7c423d4b59e0821cbe822ce54c0bc Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Mon, 15 Jan 2024 21:59:11 +0100 Subject: [PATCH 19/45] Add GHA ecosystem to `dependabot.yml`. (#103) --- .github/dependabot.yml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c990752..6e9a9f8 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,7 +1,19 @@ version: 2 updates: -- package-ecosystem: pip - directory: "/" - schedule: - interval: monthly - open-pull-requests-limit: 10 + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: monthly + assignees: + - "ezio-melotti" + open-pull-requests-limit: 10 + + # Maintain dependencies for Python + - package-ecosystem: pip + directory: "/" + schedule: + interval: monthly + assignees: + - "ezio-melotti" + open-pull-requests-limit: 10 From 402b34de995bd20b10ec73c259ceea54aff566b4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 23:13:34 +0200 Subject: [PATCH 20/45] Bump actions/setup-python from 3 to 5 (#106) Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3 to 5. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v3...v5) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/lint_python.yml | 2 +- .github/workflows/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 49d832c..cfb6a6c 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v5 with: cache: pip cache-dependency-path: .github/workflows/lint_python.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2eaf4f9..83804db 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: # ref actions/checkout#448 fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} allow-prereleases: true From 405d587ab55bb5f649b3bdd346fda7caf93b246f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 23:30:00 +0200 Subject: [PATCH 21/45] Bump hynek/build-and-inspect-python-package from 1 to 2 and actions/download-artifact from 3 to 4 (#105) * Bump hynek/build-and-inspect-python-package from 1 to 2 Bumps [hynek/build-and-inspect-python-package](https://github.com/hynek/build-and-inspect-python-package) from 1 to 2. - [Release notes](https://github.com/hynek/build-and-inspect-python-package/releases) - [Changelog](https://github.com/hynek/build-and-inspect-python-package/blob/main/CHANGELOG.md) - [Commits](https://github.com/hynek/build-and-inspect-python-package/compare/v1...v2) --- updated-dependencies: - dependency-name: hynek/build-and-inspect-python-package dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * Bump actions/download-artifact to v4 --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6a79750..0903628 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -22,7 +22,7 @@ jobs: with: fetch-depth: 0 - - uses: hynek/build-and-inspect-python-package@v1 + - uses: hynek/build-and-inspect-python-package@v2 # Publish to Test PyPI on every commit on main. release-test-pypi: @@ -39,7 +39,7 @@ jobs: steps: - name: Download packages built by build-and-inspect-python-package - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: Packages path: dist From 8a2de3bd29f618d89134f4b205e47edcb5915bbc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Jan 2024 00:44:31 +0200 Subject: [PATCH 22/45] Bump actions/checkout from 3 to 4 (#107) Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/lint_python.yml | 2 +- .github/workflows/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index cfb6a6c..e82b028 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -4,7 +4,7 @@ jobs: lint_python: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: cache: pip diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 83804db..77b25fe 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,7 @@ jobs: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] os: [windows-latest, macos-latest, ubuntu-latest] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: # fetch all branches and tags # ref actions/checkout#448 From b1f0991c2780dab10e2940109d9e80dca7414e9b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 20 Jan 2024 13:57:32 +0200 Subject: [PATCH 23/45] Fix CI: ignore CVE-2023-5752 (#102) Co-authored-by: Hugo van Kemenade --- .github/workflows/lint_python.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index e82b028..afa4a8a 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -22,4 +22,5 @@ jobs: - run: pip install --editable . - run: mypy --ignore-missing-imports --install-types --non-interactive . - run: shopt -s globstar && pyupgrade --py38-plus **/*.py || true - - run: safety check + # # Ignore CVE-2023-5752, we're not using that pip or feature + - run: safety check --ignore 62044 From c7a504fef3e261aa3c5f22acb96604c86ce96d81 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 20 Jan 2024 18:34:03 +0200 Subject: [PATCH 24/45] Lint on GitHub Actions via pre-commit (#93) Co-authored-by: Ezio Melotti Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Hugo van Kemenade --- .flake8 | 4 ++ .github/workflows/lint.yml | 30 ++++++++++ .github/workflows/lint_python.yml | 26 --------- .pre-commit-config.yaml | 88 +++++++++++++++++++++++++++++ cherry_picker/__init__.py | 2 + cherry_picker/__main__.py | 2 + cherry_picker/cherry_picker.py | 46 ++++++++++----- cherry_picker/test_cherry_picker.py | 71 +++++++++++++++++------ pyproject.toml | 3 + readme.rst | 2 +- 10 files changed, 214 insertions(+), 60 deletions(-) create mode 100644 .flake8 create mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/lint_python.yml create mode 100644 .pre-commit-config.yaml diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..3ed1b92 --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +extend-ignore = C408,E203,F841,W503 +max-complexity = 10 +max-line-length = 88 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..a2bc9cb --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: Lint + +on: [push, pull_request, workflow_dispatch] + +env: + FORCE_COLOR: 1 + +permissions: + contents: read + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + cache: pip + cache-dependency-path: .github/workflows/lint.yml + - uses: pre-commit/action@v3.0.0 + - name: Install dependencies + run: | + python -m pip install --upgrade pip wheel + # TODO: remove setuptools installation when safety==2.4.0 is released + python -m pip install --upgrade safety setuptools + python -m pip install --editable . + # Ignore CVE-2023-5752, we're not using that pip or feature + - run: safety check --ignore 62044 diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml deleted file mode 100644 index afa4a8a..0000000 --- a/.github/workflows/lint_python.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: lint_python -on: [pull_request, push, workflow_dispatch] -jobs: - lint_python: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - cache: pip - cache-dependency-path: .github/workflows/lint_python.yml - - run: pip install --upgrade pip wheel - # TODO: remove setuptools installation when safety==2.4.0 is released - - run: pip install --upgrade bandit black codespell flake8 flake8-bugbear - flake8-comprehensions isort mypy pyupgrade safety setuptools - - run: bandit --recursive --skip B101,B404,B603 . - - run: black --diff . - - run: codespell --ignore-words-list="commitish" - - run: flake8 . --count --ignore=C408,E203,F841,W503 --max-complexity=10 - --max-line-length=143 --show-source --statistics - - run: isort --check-only --profile black . - - run: pip install --editable . - - run: mypy --ignore-missing-imports --install-types --non-interactive . - - run: shopt -s globstar && pyupgrade --py38-plus **/*.py || true - # # Ignore CVE-2023-5752, we're not using that pip or feature - - run: safety check --ignore 62044 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c5fbb02 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,88 @@ +repos: + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 + hooks: + - id: pyupgrade + args: [--py38-plus] + + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 23.12.1 + hooks: + - id: black + + - repo: https://github.com/PyCQA/isort + rev: 5.13.2 + hooks: + - id: isort + args: [--add-import=from __future__ import annotations] + + - repo: https://github.com/PyCQA/bandit + rev: 1.7.6 + hooks: + - id: bandit + args: ["--skip=B101,B404,B603"] + + - repo: https://github.com/PyCQA/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + additional_dependencies: + [ + flake8-2020, + flake8-bugbear, + flake8-comprehensions, + flake8-implicit-str-concat, + flake8-logging, + ] + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 + hooks: + - id: python-check-blanket-noqa + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: check-json + - id: check-toml + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: trailing-whitespace + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.8.0 + hooks: + - id: mypy + args: + [ + --ignore-missing-imports, + --install-types, + --non-interactive, + --pretty, + --show-error-codes, + ., + ] + pass_filenames: false + + - repo: https://github.com/tox-dev/pyproject-fmt + rev: 1.6.0 + hooks: + - id: pyproject-fmt + + - repo: https://github.com/abravalheri/validate-pyproject + rev: v0.15 + hooks: + - id: validate-pyproject + + - repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + args: [--ignore-words-list=commitish] + +ci: + autoupdate_schedule: quarterly diff --git a/cherry_picker/__init__.py b/cherry_picker/__init__.py index b654ebc..9dfa236 100644 --- a/cherry_picker/__init__.py +++ b/cherry_picker/__init__.py @@ -1,4 +1,6 @@ """Backport CPython changes from main to maintenance branches.""" +from __future__ import annotations + import importlib.metadata __version__ = importlib.metadata.version(__name__) diff --git a/cherry_picker/__main__.py b/cherry_picker/__main__.py index cc02b31..b5ff54f 100644 --- a/cherry_picker/__main__.py +++ b/cherry_picker/__main__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from .cherry_picker import cherry_pick_cli if __name__ == "__main__": diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index c3c6e60..66bde15 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +from __future__ import annotations + import collections import enum import os @@ -91,7 +93,6 @@ class InvalidRepoException(Exception): class CherryPicker: - ALLOWED_STATES = WORKFLOW_STATES.BACKPORT_PAUSED, WORKFLOW_STATES.UNSET """The list of states expected at the start of the app.""" @@ -151,7 +152,7 @@ def set_paused_state(self): set_state(WORKFLOW_STATES.BACKPORT_PAUSED) def remember_previous_branch(self): - """Save the current branch into Git config to be able to get back to it later.""" + """Save the current branch into Git config, to be used later.""" current_branch = get_current_branch() save_cfg_vals_to_git_cfg(previous_branch=current_branch) @@ -160,7 +161,8 @@ def upstream(self): """Get the remote name to use for upstream branches Uses the remote passed to `--upstream-remote`. - If this flag wasn't passed, it uses "upstream" if it exists or "origin" otherwise. + If this flag wasn't passed, it uses "upstream" if it exists or "origin" + otherwise. """ # the cached calculated value of the property if self._upstream is not None: @@ -203,7 +205,10 @@ def get_cherry_pick_branch(self, maint_branch): return f"backport-{self.commit_sha1[:7]}-{maint_branch}" def get_pr_url(self, base_branch, head_branch): - return f"https://github.com/{self.config['team']}/{self.config['repo']}/compare/{base_branch}...{self.username}:{head_branch}?expand=1" + return ( + f"https://github.com/{self.config['team']}/{self.config['repo']}" + f"/compare/{base_branch}...{self.username}:{head_branch}?expand=1" + ) def fetch_upstream(self): """git fetch """ @@ -323,7 +328,9 @@ def get_updated_commit_message(self, cherry_pick_branch): commit_prefix = "" if self.prefix_commit: commit_prefix = f"[{get_base_branch(cherry_pick_branch)}] " - updated_commit_message = f"{commit_prefix}{self.get_commit_message(self.commit_sha1)}" + updated_commit_message = ( + f"{commit_prefix}{self.get_commit_message(self.commit_sha1)}" + ) # Add '(cherry picked from commit ...)' to the message # and add new Co-authored-by trailer if necessary. @@ -349,7 +356,9 @@ def get_updated_commit_message(self, cherry_pick_branch): # # This needs to be done because `git interpret-trailers` required us to add `:` # to `cherry_pick_information` when we don't actually want it. - before, after = output.strip().decode().rsplit(f"\n{cherry_pick_information}", 1) + before, after = ( + output.strip().decode().rsplit(f"\n{cherry_pick_information}", 1) + ) if not before.endswith("\n"): # ensure that we still have a newline between cherry pick information # and commit headline @@ -359,7 +368,7 @@ def get_updated_commit_message(self, cherry_pick_branch): return updated_commit_message def amend_commit_message(self, cherry_pick_branch): - """ prefix the commit message with (X.Y) """ + """Prefix the commit message with (X.Y)""" updated_commit_message = self.get_updated_commit_message(cherry_pick_branch) if self.dry_run: @@ -442,7 +451,7 @@ def create_gh_pr(self, base_branch, head_branch, *, commit_message, gh_auth): if response.status_code == requests.codes.created: response_data = response.json() click.echo(f"Backport PR created at {response_data['html_url']}") - self.pr_number = response_data['number'] + self.pr_number = response_data["number"] else: click.echo(response.status_code) click.echo(response.text) @@ -542,7 +551,9 @@ def abort_cherry_pick(self): state = self.get_state_and_verify() if state != WORKFLOW_STATES.BACKPORT_PAUSED: raise ValueError( - f"One can only abort a paused process. Current state: {state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}" + f"One can only abort a paused process. " + f"Current state: {state}. " + f"Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}" ) try: @@ -575,7 +586,9 @@ def continue_cherry_pick(self): state = self.get_state_and_verify() if state != WORKFLOW_STATES.BACKPORT_PAUSED: raise ValueError( - f"One can only continue a paused process. Current state: {state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}" + "One can only continue a paused process. " + f"Current state: {state}. " + f"Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}" ) cherry_pick_branch = get_current_branch() @@ -623,7 +636,8 @@ def continue_cherry_pick(self): else: click.echo( - f"Current branch ({cherry_pick_branch}) is not a backport branch. Will not continue. \U0001F61B" + f"Current branch ({cherry_pick_branch}) is not a backport branch. " + "Will not continue. \U0001F61B" ) set_state(WORKFLOW_STATES.CONTINUATION_FAILED) @@ -635,8 +649,8 @@ def check_repo(self): """ Check that the repository is for the project we're configured to operate on. - This function performs the check by making sure that the sha specified in the config - is present in the repository that we're operating on. + This function performs the check by making sure that the sha specified in the + config is present in the repository that we're operating on. """ try: validate_sha(self.config["check_sha"]) @@ -823,7 +837,8 @@ def get_base_branch(cherry_pick_branch): if prefix != "backport": raise ValueError( - 'branch name is not prefixed with "backport-". Is this a cherry_picker branch?' + 'branch name is not prefixed with "backport-". ' + "Is this a cherry_picker branch?" ) if not re.match("[0-9a-f]{7,40}", sha): @@ -851,7 +866,8 @@ def validate_sha(sha): subprocess.check_output(cmd, stderr=subprocess.STDOUT) except subprocess.SubprocessError: raise ValueError( - f"The sha listed in the branch name, {sha}, is not present in the repository" + f"The sha listed in the branch name, {sha}, " + "is not present in the repository" ) diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index d99ea81..bffb11d 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import pathlib import re @@ -131,7 +133,7 @@ def tmp_git_repo_dir(tmpdir, cd, git_init, git_commit, git_config): except subprocess.CalledProcessError: version = subprocess.run(("git", "--version"), capture_output=True) # the output looks like "git version 2.34.1" - v = version.stdout.decode("utf-8").removeprefix('git version ').split('.') + v = version.stdout.decode("utf-8").removeprefix("git version ").split(".") if (int(v[0]), int(v[1])) < (2, 28): warnings.warn( "You need git 2.28.0 or newer to run the full test suite.", @@ -264,7 +266,9 @@ def test_get_cherry_pick_branch(os_path_exists, config): ("python", "python"), ), ) -def test_upstream_name(remote_name, upstream_remote, config, tmp_git_repo_dir, git_remote): +def test_upstream_name( + remote_name, upstream_remote, config, tmp_git_repo_dir, git_remote +): git_remote("add", remote_name, "https://github.com/python/cpython.git") if remote_name != "origin": git_remote("add", "origin", "https://github.com/miss-islington/cpython.git") @@ -292,10 +296,14 @@ def test_upstream_name(remote_name, upstream_remote, config, tmp_git_repo_dir, g (None, "python", None), ), ) -def test_error_on_missing_remote(remote_to_add, remote_name, upstream_remote, config, tmp_git_repo_dir, git_remote): +def test_error_on_missing_remote( + remote_to_add, remote_name, upstream_remote, config, tmp_git_repo_dir, git_remote +): git_remote("add", "some-remote-name", "https://github.com/python/cpython.git") if remote_to_add is not None: - git_remote("add", remote_to_add, "https://github.com/miss-islington/cpython.git") + git_remote( + "add", remote_to_add, "https://github.com/miss-islington/cpython.git" + ) branches = ["3.6"] with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True): @@ -381,7 +389,8 @@ def test_get_updated_commit_message_without_links_replacement(config): @mock.patch("subprocess.check_output") def test_is_cpython_repo(subprocess_check_output): - subprocess_check_output.return_value = """commit 7f777ed95a19224294949e1b4ce56bbffcb1fe9f + subprocess_check_output.return_value = """\ +commit 7f777ed95a19224294949e1b4ce56bbffcb1fe9f Author: Guido van Rossum Date: Thu Aug 9 14:25:15 1990 +0000 @@ -495,7 +504,8 @@ def test_load_config_no_head_sha(tmp_git_repo_dir, git_add, git_commit): def test_normalize_long_commit_message(): - commit_message = """[3.6] Fix broken `Show Source` links on documentation pages (GH-3113) + commit_message = """\ +[3.6] Fix broken `Show Source` links on documentation pages (GH-3113) The `Show Source` was broken because of a change made in sphinx 1.5.1 In Sphinx 1.4.9, the sourcename was "index.txt". @@ -521,7 +531,8 @@ def test_normalize_long_commit_message(): def test_normalize_short_commit_message(): - commit_message = """[3.6] Fix broken `Show Source` links on documentation pages (GH-3113) + commit_message = """\ +[3.6] Fix broken `Show Source` links on documentation pages (GH-3113) (cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69) @@ -610,7 +621,9 @@ def test_normalize_short_commit_message(): ), ), ) -def test_get_updated_commit_message_with_trailers(commit_message, expected_commit_message): +def test_get_updated_commit_message_with_trailers( + commit_message, expected_commit_message +): cherry_pick_branch = "backport-22a594a-3.6" commit = "b9ff498793611d1c6a9b99df464812931a1e2d69" @@ -625,7 +638,9 @@ def test_get_updated_commit_message_with_trailers(commit_message, expected_commi "cherry_picker.cherry_picker.get_author_info_from_short_sha", return_value="PR Author ", ): - updated_commit_message = cherry_picker.get_updated_commit_message(cherry_pick_branch) + updated_commit_message = cherry_picker.get_updated_commit_message( + cherry_pick_branch + ) assert updated_commit_message == expected_commit_message @@ -764,7 +779,9 @@ def test_cleanup_branch(tmp_git_repo_dir, git_checkout): assert get_current_branch() == "main" -def test_cleanup_branch_checkout_previous_branch(tmp_git_repo_dir, git_checkout, git_worktree): +def test_cleanup_branch_checkout_previous_branch( + tmp_git_repo_dir, git_checkout, git_worktree +): assert get_state() == WORKFLOW_STATES.UNSET with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True): @@ -790,7 +807,9 @@ def test_cleanup_branch_fail(tmp_git_repo_dir): assert get_state() == WORKFLOW_STATES.REMOVING_BACKPORT_BRANCH_FAILED -def test_cleanup_branch_checkout_fail(tmp_git_repo_dir, tmpdir, git_checkout, git_worktree): +def test_cleanup_branch_checkout_fail( + tmp_git_repo_dir, tmpdir, git_checkout, git_worktree +): assert get_state() == WORKFLOW_STATES.UNSET with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True): @@ -845,7 +864,7 @@ class tested_state: set_state(tested_state) expected_msg_regexp = ( - fr"^Run state cherry-picker.state={tested_state.name} in Git config " + rf"^Run state cherry-picker.state={tested_state.name} in Git config " r"is not known." "\n" r"Perhaps it has been set by a newer " @@ -863,7 +882,7 @@ class tested_state: with mock.patch( "cherry_picker.cherry_picker.validate_sha", return_value=True ), pytest.raises(InvalidRepoException, match=expected_msg_regexp): - cherry_picker = CherryPicker("origin", "xxx", []) + CherryPicker("origin", "xxx", []) def test_push_to_remote_fail(tmp_git_repo_dir): @@ -1008,7 +1027,9 @@ def test_backport_cherry_pick_branch_already_exists( pr_remote, scm_revision, cherry_pick_target_branches ) - backport_branch_name = cherry_picker.get_cherry_pick_branch(cherry_pick_target_branches[0]) + backport_branch_name = cherry_picker.get_cherry_pick_branch( + cherry_pick_target_branches[0] + ) git_branch(backport_branch_name) with mock.patch.object(cherry_picker, "fetch_upstream"), pytest.raises( @@ -1055,7 +1076,15 @@ def test_backport_success( @pytest.mark.parametrize("already_committed", (True, False)) @pytest.mark.parametrize("push", (True, False)) def test_backport_pause_and_continue( - tmp_git_repo_dir, git_branch, git_add, git_commit, git_checkout, git_reset, git_remote, already_committed, push + tmp_git_repo_dir, + git_branch, + git_add, + git_commit, + git_checkout, + git_reset, + git_remote, + already_committed, + push, ): cherry_pick_target_branches = ("3.8",) pr_remote = "origin" @@ -1087,7 +1116,9 @@ def test_backport_pause_and_continue( if not already_committed: git_reset("HEAD~1") - assert len(get_commits_from_backport_branch(cherry_pick_target_branches[0])) == 0 + assert ( + len(get_commits_from_backport_branch(cherry_pick_target_branches[0])) == 0 + ) with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True): cherry_picker = CherryPicker(pr_remote, "", [], push=push) @@ -1142,7 +1173,9 @@ def test_continue_cherry_pick_invalid_state(tmp_git_repo_dir): assert get_state() == WORKFLOW_STATES.UNSET - with pytest.raises(ValueError, match=re.compile(r"^One can only continue a paused process.")): + with pytest.raises( + ValueError, match=re.compile(r"^One can only continue a paused process.") + ): cherry_picker.continue_cherry_pick() assert get_state() == WORKFLOW_STATES.UNSET # success @@ -1168,7 +1201,9 @@ def test_abort_cherry_pick_invalid_state(tmp_git_repo_dir): assert get_state() == WORKFLOW_STATES.UNSET - with pytest.raises(ValueError, match=re.compile(r"^One can only abort a paused process.")): + with pytest.raises( + ValueError, match=re.compile(r"^One can only abort a paused process.") + ): cherry_picker.abort_cherry_pick() diff --git a/pyproject.toml b/pyproject.toml index 808cafa..0499ac8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,3 +48,6 @@ tag-pattern = '^cherry-picker-(?P[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)? [tool.hatch.version.raw-options] local_scheme = "no-local-version" + +[tool.isort] +profile = "black" diff --git a/readme.rst b/readme.rst index 8815a90..d6c1322 100644 --- a/readme.rst +++ b/readme.rst @@ -18,7 +18,7 @@ of the maintenance branches (``3.6``, ``3.5``, ``2.7``). workflow as CPython. See the configuration file options below for more details. The maintenance branch names should contain some sort of version number (X.Y). -For example: ``3.6``, ``3.5``, ``2.7``, ``stable-2.6``, ``2.5-lts``, are all +For example: ``3.6``, ``3.5``, ``2.7``, ``stable-2.6``, ``2.5-lts``, are all supported branch names. It will prefix the commit message with the branch, e.g. ``[3.6]``, and then From d7c32647be3060e44c2c1bcece686373a70f1063 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 21 Jan 2024 08:44:28 +0000 Subject: [PATCH 25/45] Resolve usernames when the remote ends with a trailing slash (#110) --- cherry_picker/cherry_picker.py | 2 +- cherry_picker/test_cherry_picker.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 66bde15..3e59f39 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -198,7 +198,7 @@ def username(self): cmd = ["git", "config", "--get", f"remote.{self.pr_remote}.url"] result = self.run_cmd(cmd, required_real_result=True) # implicit ssh URIs use : to separate host from user, others just use / - username = result.replace(":", "/").split("/")[-2] + username = result.replace(":", "/").rstrip("/").split("/")[-2] return username def get_cherry_pick_branch(self, maint_branch): diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index bffb11d..3a9f670 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -343,10 +343,13 @@ def test_get_pr_url(config): [ b"git@github.com:mock_user/cpython.git", b"git@github.com:mock_user/cpython", + b"git@github.com:mock_user/cpython/", b"ssh://git@github.com/mock_user/cpython.git", b"ssh://git@github.com/mock_user/cpython", + b"ssh://git@github.com/mock_user/cpython/", b"https://github.com/mock_user/cpython.git", b"https://github.com/mock_user/cpython", + b"https://github.com/mock_user/cpython/", ], ) def test_username(url, config): From 45e0d09f98c07964e822616a29635c973200fd5e Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Tue, 30 Jan 2024 00:00:22 +0000 Subject: [PATCH 26/45] Optimize `validate_sha()` with `--max-count=1` (#111) Optimize the `validate_sha()` function with `--max-count=1` to prevent printing the git log of every single commit. This makes the function near instant. --- cherry_picker/cherry_picker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 3e59f39..5ff8615 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -861,7 +861,7 @@ def validate_sha(sha): raises ValueError if the sha does not reference a commit within the repo """ - cmd = ["git", "log", "-r", sha] + cmd = ["git", "log", "--max-count=1", "-r", sha] try: subprocess.check_output(cmd, stderr=subprocess.STDOUT) except subprocess.SubprocessError: From 19634f22a5ff4d6722435c928f13432461b0742a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 12 Feb 2024 23:34:19 +0200 Subject: [PATCH 27/45] Make # replacing more strict (GH-115) Only replace "#" with "GH-" with the following conditions: * "#" is separated from the previous word * "#" is followed by at least 5-digit number that does not start with 0 * the number is separated from the following word --- cherry_picker/__init__.py | 1 + cherry_picker/cherry_picker.py | 7 ++++++- cherry_picker/test_cherry_picker.py | 8 ++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cherry_picker/__init__.py b/cherry_picker/__init__.py index 9dfa236..843751f 100644 --- a/cherry_picker/__init__.py +++ b/cherry_picker/__init__.py @@ -1,4 +1,5 @@ """Backport CPython changes from main to maintenance branches.""" + from __future__ import annotations import importlib.metadata diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 5ff8615..715557f 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -261,7 +261,12 @@ def get_commit_message(self, commit_sha): click.echo(err.output) raise CherryPickException(f"Error getting commit message for {commit_sha}") if self.config["fix_commit_msg"]: - return message.replace("#", "GH-") + # Only replace "#" with "GH-" with the following conditions: + # * "#" is separated from the previous word + # * "#" is followed by at least 5-digit number that + # does not start with 0 + # * the number is separated from the following word + return re.sub(r"\B#(?=[1-9][0-9]{4,}\b)", "GH-", message) else: return message diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index 3a9f670..0876440 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -367,12 +367,16 @@ def test_get_updated_commit_message(config): "origin", "22a594a0047d7706537ff2ac676cdc0f1dcb329c", branches, config=config ) with mock.patch( - "subprocess.check_output", return_value=b"bpo-123: Fix Spam Module (#113)" + "subprocess.check_output", + return_value=b"bpo-123: Fix#12345 #1234 #12345Number Sign (#01234) (#11345)", ): actual_commit_message = cp.get_commit_message( "22a594a0047d7706537ff2ac676cdc0f1dcb329c" ) - assert actual_commit_message == "bpo-123: Fix Spam Module (GH-113)" + assert ( + actual_commit_message + == "bpo-123: Fix#12345 #1234 #12345Number Sign (#01234) (GH-11345)" + ) def test_get_updated_commit_message_without_links_replacement(config): From 9aaad23895871bcb9a4a69019ca10dab121cfab1 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 13 Feb 2024 15:25:48 +0200 Subject: [PATCH 28/45] Remove multiple commit prefixes (#118) Multiple commit prefixes "[X.Y] " were added in multilevel backports. Only the leftmost one matters. Others just increase the length of the title. --- cherry_picker/cherry_picker.py | 42 ++++++++++++++--------------- cherry_picker/test_cherry_picker.py | 24 +++++++++++++++++ 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 715557f..f2046ee 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -330,12 +330,11 @@ def get_updated_commit_message(self, cherry_pick_branch): """ # Get the original commit message and prefix it with the branch name # if that's enabled. - commit_prefix = "" + updated_commit_message = self.get_commit_message(self.commit_sha1) if self.prefix_commit: - commit_prefix = f"[{get_base_branch(cherry_pick_branch)}] " - updated_commit_message = ( - f"{commit_prefix}{self.get_commit_message(self.commit_sha1)}" - ) + updated_commit_message = remove_commit_prefix(updated_commit_message) + base_branch = get_base_branch(cherry_pick_branch) + updated_commit_message = f"[{base_branch}] {updated_commit_message}" # Add '(cherry picked from commit ...)' to the message # and add new Co-authored-by trailer if necessary. @@ -443,6 +442,7 @@ def create_gh_pr(self, base_branch, head_branch, *, commit_message, gh_auth): request_headers = sansio.create_headers(self.username, oauth_token=gh_auth) title, body = normalize_commit_message(commit_message) if not self.prefix_commit: + title = remove_commit_prefix(title) title = f"[{base_branch}] {title}" data = { "title": title, @@ -880,19 +880,10 @@ def version_from_branch(branch): """ return version information from a git branch name """ - try: - return tuple( - map( - int, - re.match(r"^.*(?P\d+(\.\d+)+).*$", branch) - .groupdict()["version"] - .split("."), - ) - ) - except AttributeError as attr_err: - raise ValueError( - f"Branch {branch} seems to not have a version in its name." - ) from attr_err + m = re.search(r"\d+(?:\.\d+)+", branch) + if not m: + raise ValueError(f"Branch {branch} seems to not have a version in its name.") + return tuple(map(int, m[0].split("."))) def get_current_branch(): @@ -929,12 +920,21 @@ def normalize_commit_message(commit_message): """ Return a tuple of title and body from the commit message """ - split_commit_message = commit_message.split("\n") - title = split_commit_message[0] - body = "\n".join(split_commit_message[1:]) + title, _, body = commit_message.partition("\n") return title, body.lstrip("\n") +def remove_commit_prefix(commit_message): + """ + Remove prefix "[X.Y] " from the commit message + """ + while True: + m = re.match(r"\[\d+(?:\.\d+)+\] *", commit_message) + if not m: + return commit_message + commit_message = commit_message[m.end() :] + + def is_git_repo(): """Check whether the current folder is a Git repo.""" cmd = "git", "rev-parse", "--git-dir" diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index 0876440..5138c83 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -30,6 +30,7 @@ load_config, load_val_from_git_cfg, normalize_commit_message, + remove_commit_prefix, reset_state, reset_stored_config_ref, set_state, @@ -558,6 +559,19 @@ def test_normalize_short_commit_message(): ) +@pytest.mark.parametrize( + "commit_message, expected", + [ + ("[3.12] Fix something (GH-3113)", "Fix something (GH-3113)"), + ("[3.11] [3.12] Fix something (GH-3113)", "Fix something (GH-3113)"), + ("Fix something (GH-3113)", "Fix something (GH-3113)"), + ("[WIP] Fix something (GH-3113)", "[WIP] Fix something (GH-3113)"), + ], +) +def test_remove_commit_prefix(commit_message, expected): + assert remove_commit_prefix(commit_message) == expected + + @pytest.mark.parametrize( "commit_message,expected_commit_message", ( @@ -626,6 +640,16 @@ def test_normalize_short_commit_message(): Co-authored-by: PR Author Co-authored-by: PR Co-Author """, ), + # ensure the existing commit prefix is replaced + ( + "[3.7] [3.8] Fix broken `Show Source` links on documentation " + "pages (GH-3113) (GH-3114) (GH-3115)", + """[3.6] Fix broken `Show Source` links on documentation """ + """pages (GH-3113) (GH-3114) (GH-3115) +(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69) + +Co-authored-by: PR Author """, + ), ), ) def test_get_updated_commit_message_with_trailers( From 803899496d4fabc090b02a8137acd674796cbe39 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:52:11 +0200 Subject: [PATCH 29/45] Bump pre-commit/action from 3.0.0 to 3.0.1 (#122) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a2bc9cb..0028aca 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,7 +19,7 @@ jobs: python-version: "3.x" cache: pip cache-dependency-path: .github/workflows/lint.yml - - uses: pre-commit/action@v3.0.0 + - uses: pre-commit/action@v3.0.1 - name: Install dependencies run: | python -m pip install --upgrade pip wheel From 0dffdaaf060c5e25bfddb93d8fe672d96e511ccc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Apr 2024 17:18:45 +0300 Subject: [PATCH 30/45] Bump codecov/codecov-action from 3 to 4 (#113) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 77b25fe..b2d29c7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,7 +32,8 @@ jobs: - name: Run tests run: tox -e py - name: Upload coverage - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: flags: ${{ matrix.os }} name: ${{ matrix.os }} Python ${{ matrix.python-version }} + token: ${{ secrets.CODECOV_ORG_TOKEN }} From b31e3bd34f12400a5997d31467b8435b092b4256 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 14 Apr 2024 12:38:36 +0300 Subject: [PATCH 31/45] Convert README to Markdown (#125) Co-authored-by: Ezio Melotti --- README.md | 359 ++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- readme.rst | 366 ------------------------------------------------- 3 files changed, 360 insertions(+), 367 deletions(-) create mode 100644 README.md delete mode 100644 readme.rst diff --git a/README.md b/README.md new file mode 100644 index 0000000..28be5ae --- /dev/null +++ b/README.md @@ -0,0 +1,359 @@ +# cherry_picker + +[![PyPI version](https://img.shields.io/pypi/v/cherry-picker.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/cherry-picker) +[![Supported Python versions](https://img.shields.io/pypi/pyversions/cherry-picker.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/cherry-picker) +[![tests](https://github.com/python/cherry-picker/actions/workflows/main.yml/badge.svg)](https://github.com/python/cherry-picker/actions/workflows/main.yml) + +Usage (from a cloned CPython directory): + +``` +Usage: cherry_picker [OPTIONS] [COMMIT_SHA1] [BRANCHES]... + + cherry-pick COMMIT_SHA1 into target BRANCHES. + +Options: + --version Show the version and exit. + --dry-run Prints out the commands, but not executed. + --pr-remote REMOTE git remote to use for PR branches + --upstream-remote REMOTE git remote to use for upstream branches + --abort Abort current cherry-pick and clean up branch + --continue Continue cherry-pick, push, and clean up branch + --status Get the status of cherry-pick + --push / --no-push Changes won't be pushed to remote + --auto-pr / --no-auto-pr If auto PR is enabled, cherry-picker will + automatically open a PR through API if GH_AUTH + env var is set, or automatically open the PR + creation page in the web browser otherwise. + --config-path CONFIG-PATH Path to config file, .cherry_picker.toml from + project root by default. You can prepend a colon- + separated Git 'commitish' reference. + -h, --help Show this message and exit. +``` + +## About + +This tool is used to backport CPython changes from `main` into one or more +of the maintenance branches (e.g. `3.12`, `3.11`). + +`cherry_picker` can be configured to backport other projects with similar +workflow as CPython. See the configuration file options below for more details. + +The maintenance branch names should contain some sort of version number (`X.Y`). +For example: `3.12`, `stable-3.12`, `1.5`, `1.5-lts`, are all supported branch +names. + +It will prefix the commit message with the branch, e.g. `[3.12]`, and then +open up the pull request page. + +Write tests using [pytest](https://docs.pytest.org/). + + +## Setup info + +Requires Python 3.8+. + +```console +$ python3 -m venv venv +$ source venv/bin/activate +(venv) $ python -m pip install cherry_picker +``` + +The cherry picking script assumes that if an `upstream` remote is defined, then +it should be used as the source of upstream changes and as the base for +cherry-pick branches. Otherwise, `origin` is used for that purpose. +You can override this behavior with the `--upstream-remote` option +(e.g. `--upstream-remote python` to use a remote named `python`). + +Verify that an `upstream` remote is set to the CPython repository: + +```console +$ git remote -v +... +upstream https://github.com/python/cpython (fetch) +upstream https://github.com/python/cpython (push) +``` + +If needed, create the `upstream` remote: + +```console +$ git remote add upstream https://github.com/python/cpython.git +``` + +By default, the PR branches used to submit pull requests back to the main +repository are pushed to `origin`. If this is incorrect, then the correct +remote will need be specified using the `--pr-remote` option (e.g. +`--pr-remote pr` to use a remote named `pr`). + + +## Cherry-picking 🐍🍒⛏️ + +(Setup first! See previous section.) + +From the cloned CPython directory: + +```console +(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 + +The commit sha1 for cherry-picking is the squashed commit that was merged to +the `main` branch. On the merged pull request, scroll to the bottom of the +page. Find the event that says something like: + +``` + merged commit into python:main ago. +``` + +By following the link to ``, you will get the full commit hash. +Use the full commit hash for `cherry_picker.py`. + + +### Options + +``` +--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. +``` + +Additional options: + +``` +--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) +``` + +Configuration file example: + +```toml +team = "aio-libs" +repo = "aiohttp" +check_sha = "f382b5ffc445e45a110734f5396728da7914aeb6" +fix_commit_msg = false +default_branch = "devel" +``` + +Available config options: + +``` +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) +``` + +To customize the tool for used by other project: + +1. Create a file called `.cherry_picker.toml` in the project's root + folder (alongside with `.git` folder). + +2. Add `team`, `repo`, `fix_commit_msg`, `check_sha` and + `default_branch` config values as described above. + +3. Use `git add .cherry_picker.toml` / `git commit` to add the config + into Git. + +4. Add `cherry_picker` to development dependencies or install it + by `pip install cherry_picker` + +5. Now everything is ready, use `cherry_picker + ` for cherry-picking changes from `` into + maintenance branches. + Branch name should contain at least major and minor version numbers + and may have some prefix or suffix. + Only the first version-like substring is matched when the version + is extracted from branch name. + +### Demo + +- Installation: https://asciinema.org/a/125254 + +- Backport: https://asciinema.org/a/125256 + + +### Example + +For example, to cherry-pick `6de2b7817f-some-commit-sha1-d064` into +`3.12` and `3.11`, run the following command from the cloned CPython +directory: + +```console +(venv) $ cherry_picker 6de2b7817f-some-commit-sha1-d064 3.12 3.11 +``` + +What this will do: + +```console +(venv) $ git fetch upstream + +(venv) $ git checkout -b backport-6de2b78-3.12 upstream/3.12 +(venv) $ git cherry-pick -x 6de2b7817f-some-commit-sha1-d064 +(venv) $ git push origin backport-6de2b78-3.12 +(venv) $ git checkout main +(venv) $ git branch -D backport-6de2b78-3.12 + +(venv) $ git checkout -b backport-6de2b78-3.11 upstream/3.11 +(venv) $ git cherry-pick -x 6de2b7817f-some-commit-sha1-d064 +(venv) $ git push origin backport-6de2b78-3.11 +(venv) $ git checkout main +(venv) $ git branch -D backport-6de2b78-3.11 +``` + +In case of merge conflicts or errors, the following message will be displayed: + +``` +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 +``` + +Passing the `--dry-run` option will cause the script to print out all the +steps it would execute without actually executing any of them. For example: + +```console +$ cherry_picker --dry-run --pr-remote pr 1e32a1be4a1705e34011770026cb64ada2d340b5 3.12 3.11 +Dry run requested, listing expected command sequence +fetching upstream ... +dry_run: git fetch origin +Now backporting '1e32a1be4a1705e34011770026cb64ada2d340b5' into '3.12' +dry_run: git checkout -b backport-1e32a1b-3.12 origin/3.12 +dry_run: git cherry-pick -x 1e32a1be4a1705e34011770026cb64ada2d340b5 +dry_run: git push pr backport-1e32a1b-3.12 +dry_run: Create new PR: https://github.com/python/cpython/compare/3.12...ncoghlan:backport-1e32a1b-3.12?expand=1 +dry_run: git checkout main +dry_run: git branch -D backport-1e32a1b-3.12 +Now backporting '1e32a1be4a1705e34011770026cb64ada2d340b5' into '3.11' +dry_run: git checkout -b backport-1e32a1b-3.11 origin/3.11 +dry_run: git cherry-pick -x 1e32a1be4a1705e34011770026cb64ada2d340b5 +dry_run: git push pr backport-1e32a1b-3.11 +dry_run: Create new PR: https://github.com/python/cpython/compare/3.11...ncoghlan:backport-1e32a1b-3.11?expand=1 +dry_run: git checkout main +dry_run: git branch -D backport-1e32a1b-3.11 +``` + +### `--pr-remote` option + +This will generate pull requests through a remote other than `origin` +(e.g. `pr`) + +### `--upstream-remote` option + +This will generate branches from a remote other than `upstream`/`origin` +(e.g. `python`) + +### `--status` option + +This will do `git status` for the CPython directory. + +### `--abort` option + +Cancels the current cherry-pick and cleans up the cherry-pick branch. + +### `--continue` option + +Continues the current cherry-pick, commits, pushes the current branch to +`origin`, opens the PR page, and cleans up the branch. + +### `--no-push` option + +Changes won't be pushed to remote. This allows you to test and make additional +changes. Once you're satisfied with local changes, use `--continue` to complete +the backport, or `--abort` to cancel and clean up the branch. You can also +cherry-pick additional commits, by: + +```console +$ git cherry-pick -x +``` + +### `--no-auto-pr` option + +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. +This can be useful if your terminal is not capable of opening a useful web browser, +or if you use cherry-picker with a different Git hosting than GitHub. + +### `--config-path` option + +Allows to override default config file path +(`/.cherry_picker.toml`) with a custom one. This allows cherry_picker +to backport projects other than CPython. + + +## Creating pull requests + +When a cherry-pick was applied successfully, this script will open up a browser +tab that points to the pull request creation page. + +The url of the pull request page looks similar to the following: + +``` +https://github.com/python/cpython/compare/3.12...:backport-6de2b78-3.12?expand=1 +``` + +Press the `Create Pull Request` button. + +Bedevere will then remove the `needs backport to ...` label from the original +pull request against `main`. + + +## Running tests + +```console +$ # Install pytest +$ pip install -U pytest +$ # Run tests +$ pytest +``` + +Tests require your local version of Git to be 2.28.0+. + +## Publishing to PyPI + +- See the [release checklist](https://github.com/python/cherry-picker/blob/main/RELEASING.md). + + +## Local installation + +In the directory where `pyproject.toml` exists: + +```console +$ pip install +``` + +## Changelog + +See the [changelog](https://github.com/python/cherry-picker/blob/main/CHANGELOG.md). diff --git a/pyproject.toml b/pyproject.toml index 0499ac8..dad5425 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ requires = [ [project] name = "cherry-picker" -readme = "readme.rst" +readme = "README.md" maintainers = [{ name = "Python Core Developers", email = "core-workflow@python.org" }] authors = [{ name = "Mariatta Wijaya", email = "mariatta@python.org" }] requires-python = ">=3.8" diff --git a/readme.rst b/readme.rst deleted file mode 100644 index d6c1322..0000000 --- a/readme.rst +++ /dev/null @@ -1,366 +0,0 @@ -Usage (from a cloned CPython directory) :: - - 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] - -|pyversion status| -|pypi status| -|github actions status| - -.. contents:: - -About -===== - -This tool is used to backport CPython changes from ``main`` into one or more -of the maintenance branches (``3.6``, ``3.5``, ``2.7``). - -``cherry_picker`` can be configured to backport other projects with similar -workflow as CPython. See the configuration file options below for more details. - -The maintenance branch names should contain some sort of version number (X.Y). -For example: ``3.6``, ``3.5``, ``2.7``, ``stable-2.6``, ``2.5-lts``, are all -supported branch names. - -It will prefix the commit message with the branch, e.g. ``[3.6]``, and then -opens up the pull request page. - -Tests are to be written using `pytest `_. - - -Setup Info -========== - -Requires Python 3.8+. - -.. code-block:: console - - $ python3 -m venv venv - $ source venv/bin/activate - (venv) $ python -m pip install cherry_picker - -The cherry picking script assumes that if an ``upstream`` remote is defined, then -it should be used as the source of upstream changes and as the base for -cherry-pick branches. Otherwise, ``origin`` is used for that purpose. -You can override this behavior with the ``--upstream-remote`` option -(e.g. ``--upstream-remote python`` to use a remote named ``python``). - -Verify that an ``upstream`` remote is set to the CPython repository: - -.. code-block:: console - - $ git remote -v - ... - upstream https://github.com/python/cpython (fetch) - upstream https://github.com/python/cpython (push) - -If needed, create the ``upstream`` remote: - -.. code-block:: console - - $ git remote add upstream https://github.com/python/cpython.git - - -By default, the PR branches used to submit pull requests back to the main -repository are pushed to ``origin``. If this is incorrect, then the correct -remote will need be specified using the ``--pr-remote`` option (e.g. -``--pr-remote pr`` to use a remote named ``pr``). - - -Cherry-picking 🐍🍒⛏️ -===================== - -(Setup first! See prev section) - -From the cloned CPython directory: - -.. code-block:: console - - (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 ------------ - -The commit sha1 for cherry-picking is the squashed commit that was merged to -the ``main`` branch. On the merged pull request, scroll to the bottom of the -page. Find the event that says something like:: - - merged commit into python:main ago. - -By following the link to ````, you will get the full commit hash. -Use the full commit hash for ``cherry_picker.py``. - - -Options -------- - -:: - - --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. - - -Additional options:: - - --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) - - -Configuration file example: - -.. code-block:: toml - - team = "aio-libs" - repo = "aiohttp" - check_sha = "f382b5ffc445e45a110734f5396728da7914aeb6" - fix_commit_msg = false - default_branch = "devel" - - -Available config options:: - - 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) - - -To customize the tool for used by other project: - -1. Create a file called ``.cherry_picker.toml`` in the project's root - folder (alongside with ``.git`` folder). - -2. Add ``team``, ``repo``, ``fix_commit_msg``, ``check_sha`` and - ``default_branch`` config values as described above. - -3. Use ``git add .cherry_picker.toml`` / ``git commit`` to add the config - into ``git``. - -4. Add ``cherry_picker`` to development dependencies or install it - by ``pip install cherry_picker`` - -5. Now everything is ready, use ``cherry_picker - `` for cherry-picking changes from ```` into - maintenance branches. - Branch name should contain at least major and minor version numbers - and may have some prefix or suffix. - Only the first version-like substring is matched when the version - is extracted from branch name. - -Demo ----- - -- Installation: https://asciinema.org/a/125254 - -- Backport: https://asciinema.org/a/125256 - - -Example -------- - -For example, to cherry-pick ``6de2b7817f-some-commit-sha1-d064`` into -``3.5`` and ``3.6``, run the following command from the cloned CPython -directory: - -.. code-block:: console - - (venv) $ cherry_picker 6de2b7817f-some-commit-sha1-d064 3.5 3.6 - - -What this will do: - -.. code-block:: console - - (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 - -In case of merge conflicts or errors, the following message will be displayed:: - - 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 - - -Passing the ``--dry-run`` option will cause the script to print out all the -steps it would execute without actually executing any of them. For example: - -.. code-block:: console - - $ 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` option --------------------- - -This will generate pull requests through a remote other than ``origin`` -(e.g. ``pr``) - -`--upstream-remote` option --------------------------- - -This will generate branches from a remote other than ``upstream``/``origin`` -(e.g. ``python``) - -`--status` option ------------------ - -This will do ``git status`` for the CPython directory. - -`--abort` option ----------------- - -Cancels the current cherry-pick and cleans up the cherry-pick branch. - -`--continue` option -------------------- - -Continues the current cherry-pick, commits, pushes the current branch to -``origin``, opens the PR page, and cleans up the branch. - -`--no-push` option ------------------- - -Changes won't be pushed to remote. This allows you to test and make additional -changes. Once you're satisfied with local changes, use ``--continue`` to complete -the backport, or ``--abort`` to cancel and clean up the branch. You can also -cherry-pick additional commits, by: - -.. code-block:: console - - $ git cherry-pick -x - -`--no-auto-pr` option ---------------------- - -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. -This can be useful if your terminal is not capable of opening a useful web browser, -or if you use cherry-picker with a different Git hosting than GitHub. - -`--config-path` option ----------------------- - -Allows to override default config file path -(``/.cherry_picker.toml``) with a custom one. This allows cherry_picker -to backport projects other than CPython. - - -Creating Pull Requests -====================== - -When a cherry-pick was applied successfully, this script will open up a browser -tab that points to the pull request creation page. - -The url of the pull request page looks similar to the following:: - - https://github.com/python/cpython/compare/3.5...:backport-6de2b78-3.5?expand=1 - - -Press the ``Create Pull Request`` button. - -Bedevere will then remove the ``needs backport to ...`` label from the original -pull request against ``main``. - - -Running Tests -============= - -Install pytest: ``pip install -U pytest`` - -.. code-block:: console - - $ pytest - -Tests require your local version of ``git`` to be ``2.28.0+``. - -Publishing to PyPI -================== - -- See the `release checklist `_. - - -Local installation -================== - -With `flit `_ installed, -in the directory where ``pyproject.toml`` exists: - -.. code-block:: console - - $ pip install - - -.. |pyversion status| image:: https://img.shields.io/pypi/pyversions/cherry-picker.svg - :target: https://pypi.org/project/cherry-picker/ - -.. |pypi status| image:: https://img.shields.io/pypi/v/cherry-picker.svg - :target: https://pypi.org/project/cherry-picker/ - -.. |github actions status| image:: https://github.com/python/cherry-picker/actions/workflows/main.yml/badge.svg - :target: https://github.com/python/cherry-picker/actions/workflows/main.yml - -Changelog -========= - -See the `changelog `_. From c9e3a131215c80faca2bb3d331edf4deb51be8ed Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Sun, 30 Jun 2024 17:55:26 +0900 Subject: [PATCH 32/45] Ignore Jinja2 CVE warning in `safety` dep (#129) * Ignore Jinja2 CVE warning in `safety` dep * Specify `--ignore` twice --- .github/workflows/lint.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0028aca..83d6b76 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -26,5 +26,6 @@ jobs: # TODO: remove setuptools installation when safety==2.4.0 is released python -m pip install --upgrade safety setuptools python -m pip install --editable . - # Ignore CVE-2023-5752, we're not using that pip or feature - - run: safety check --ignore 62044 + # Ignore 62044 / CVE-2023-5752, we're not using that pip or feature + # Ignore 70612 / CVE-2019-8341, Jinja2 is a safety dep, not ours + - run: safety check --ignore 62044 --ignore 70612 From d92a15375ccd689fd9f0e635eeae5296cad3746d Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Sun, 30 Jun 2024 18:01:07 +0900 Subject: [PATCH 33/45] Add Python 3.13 to the testing matrix (#127) * Add Python 3.13 to the testing matrix * Try updating cffi * Add comment about cffi and update Python version classifier * Use `>=` instead of `==` for `cffi` * Appease the linter * Halve pre-commit whitespace * Remove 3.13 classifier and update comment --- .github/workflows/main.yml | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b2d29c7..cb8b350 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] os: [windows-latest, macos-latest, ubuntu-latest] steps: - uses: actions/checkout@v4 diff --git a/pyproject.toml b/pyproject.toml index dad5425..0813d12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ dynamic = [ "version", ] dependencies = [ + "cffi>=v1.17.0rc1", # remove once v1.17.0 is out; add 3.13 classifier above (see #127) "click>=6", "gidgethub", "requests", From 3d4f082a9251509b5d04a93f0df9d827b8b5e984 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Sun, 30 Jun 2024 18:01:57 +0900 Subject: [PATCH 34/45] Remove `setuptools` installation for `safety` 3 (#128) --- .github/workflows/lint.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 83d6b76..80815f3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,8 +23,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip wheel - # TODO: remove setuptools installation when safety==2.4.0 is released - python -m pip install --upgrade safety setuptools + python -m pip install --upgrade safety python -m pip install --editable . # Ignore 62044 / CVE-2023-5752, we're not using that pip or feature # Ignore 70612 / CVE-2019-8341, Jinja2 is a safety dep, not ours From 788c96cd527d757dc4dc3991e4582b82c4816573 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Sun, 30 Jun 2024 18:08:34 +0900 Subject: [PATCH 35/45] Revert #102 after upstream fix (#126) --- .github/workflows/lint.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 80815f3..7af199e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,6 +25,5 @@ jobs: python -m pip install --upgrade pip wheel python -m pip install --upgrade safety python -m pip install --editable . - # Ignore 62044 / CVE-2023-5752, we're not using that pip or feature # Ignore 70612 / CVE-2019-8341, Jinja2 is a safety dep, not ours - - run: safety check --ignore 62044 --ignore 70612 + - run: safety check --ignore 70612 From 68153a8f93746fc7d8e5f4cb82707ea5550530e0 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Wed, 11 Sep 2024 19:47:55 +0200 Subject: [PATCH 36/45] Update actions/download-artifact to v4 in deploy.yml. (#131) --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0903628..afdf7d6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -64,7 +64,7 @@ jobs: steps: - name: Download packages built by build-and-inspect-python-package - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: Packages path: dist From bea8856ec2942012b17d8807a657f70eeb011b1e Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Tue, 17 Sep 2024 02:03:09 +0100 Subject: [PATCH 37/45] Handle whitespace when calculating usernames (#132) --- cherry_picker/cherry_picker.py | 2 +- cherry_picker/test_cherry_picker.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index f2046ee..423c76f 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -196,7 +196,7 @@ def sorted_branches(self): @property def username(self): cmd = ["git", "config", "--get", f"remote.{self.pr_remote}.url"] - result = self.run_cmd(cmd, required_real_result=True) + result = self.run_cmd(cmd, required_real_result=True).strip() # implicit ssh URIs use : to separate host from user, others just use / username = result.replace(":", "/").rstrip("/").split("/")[-2] return username diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index 5138c83..9ce5cce 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -351,6 +351,10 @@ def test_get_pr_url(config): b"https://github.com/mock_user/cpython.git", b"https://github.com/mock_user/cpython", b"https://github.com/mock_user/cpython/", + # test trailing whitespace + b"https://github.com/mock_user/cpython.git\n", + b"https://github.com/mock_user/cpython\n", + b"https://github.com/mock_user/cpython/\n", ], ) def test_username(url, config): From a7d8aee8ab9d22a09f8c3098a03109a41b0e7a40 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:58:35 -0700 Subject: [PATCH 38/45] Drop support for Python 3.8 (#133) --- .github/workflows/main.yml | 2 +- .pre-commit-config.yaml | 2 +- tox.ini | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cb8b350..60f56db 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] os: [windows-latest, macos-latest, ubuntu-latest] steps: - uses: actions/checkout@v4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c5fbb02..ed70683 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: v3.15.0 hooks: - id: pyupgrade - args: [--py38-plus] + args: [--py39-plus] - repo: https://github.com/psf/black-pre-commit-mirror rev: 23.12.1 diff --git a/tox.ini b/tox.ini index d41abed..f56c058 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{312, 311, 310, 39, 38} + py{313, 312, 311, 310, 39} isolated_build = true [testenv] @@ -9,4 +9,9 @@ passenv = extras = dev commands = - {envpython} -m pytest --cov cherry_picker --cov-report html --cov-report term --cov-report xml {posargs} + {envpython} -m pytest \ + --cov cherry_picker \ + --cov-report html \ + --cov-report term \ + --cov-report xml \ + {posargs} From 7543a088f458fca178594821177b39e6b1006512 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:53:42 -0700 Subject: [PATCH 39/45] Add Trove classifier for Python 3.13 (#134) Co-authored-by: Alex Waygood --- .pre-commit-config.yaml | 74 +++++++++++++++------------------- cherry_picker/cherry_picker.py | 2 +- pyproject.toml | 48 ++++++++++++++++------ tox.ini | 19 ++++----- 4 files changed, 80 insertions(+), 63 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ed70683..71227b0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,60 +1,42 @@ repos: - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.7 hooks: - - id: pyupgrade - args: [--py39-plus] + - id: ruff + args: [--exit-non-zero-on-fix] - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.12.1 + rev: 24.8.0 hooks: - id: black - - repo: https://github.com/PyCQA/isort - rev: 5.13.2 - hooks: - - id: isort - args: [--add-import=from __future__ import annotations] - - - repo: https://github.com/PyCQA/bandit - rev: 1.7.6 - hooks: - - id: bandit - args: ["--skip=B101,B404,B603"] - - - repo: https://github.com/PyCQA/flake8 - rev: 7.0.0 - hooks: - - id: flake8 - additional_dependencies: - [ - flake8-2020, - flake8-bugbear, - flake8-comprehensions, - flake8-implicit-str-concat, - flake8-logging, - ] - - - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.10.0 - hooks: - - id: python-check-blanket-noqa - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: + - id: check-added-large-files - id: check-case-conflict - id: check-executables-have-shebangs - id: check-merge-conflict - - id: check-json - id: check-toml - id: check-yaml - id: debug-statements - id: end-of-file-fixer + - id: forbid-submodules - id: trailing-whitespace + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.29.2 + hooks: + - id: check-dependabot + - id: check-github-workflows + + - repo: https://github.com/rhysd/actionlint + rev: v1.7.1 + hooks: + - id: actionlint + - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.8.0 + rev: v1.10.1 hooks: - id: mypy args: @@ -69,20 +51,30 @@ repos: pass_filenames: false - repo: https://github.com/tox-dev/pyproject-fmt - rev: 1.6.0 + rev: 2.2.4 hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.15 + rev: v0.19 hooks: - id: validate-pyproject + - repo: https://github.com/tox-dev/tox-ini-fmt + rev: 1.4.1 + hooks: + - id: tox-ini-fmt + - repo: https://github.com/codespell-project/codespell - rev: v2.2.6 + rev: v2.3.0 hooks: - id: codespell args: [--ignore-words-list=commitish] + - repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes + ci: autoupdate_schedule: quarterly diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 423c76f..89fc411 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -702,7 +702,7 @@ def is_mirror(self) -> bool: return out.startswith("true") -CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) +CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]} @click.command(context_settings=CONTEXT_SETTINGS) diff --git a/pyproject.toml b/pyproject.toml index 0813d12..121ff51 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,8 +8,8 @@ requires = [ [project] name = "cherry-picker" readme = "README.md" -maintainers = [{ name = "Python Core Developers", email = "core-workflow@python.org" }] -authors = [{ name = "Mariatta Wijaya", email = "mariatta@python.org" }] +maintainers = [ { name = "Python Core Developers", email = "core-workflow@python.org" } ] +authors = [ { name = "Mariatta Wijaya", email = "mariatta@python.org" } ] requires-python = ">=3.8" classifiers = [ "Intended Audience :: Developers", @@ -20,27 +20,24 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ] dynamic = [ "description", "version", ] dependencies = [ - "cffi>=v1.17.0rc1", # remove once v1.17.0 is out; add 3.13 classifier above (see #127) "click>=6", "gidgethub", "requests", - 'tomli>=1.1; python_version < "3.11"', + "tomli>=1.1; python_version<'3.11'", ] -[project.optional-dependencies] -dev = [ +optional-dependencies.dev = [ "pytest", "pytest-cov", ] -[project.urls] -"Homepage" = "https://github.com/python/cherry-picker" -[project.scripts] -cherry_picker = "cherry_picker.cherry_picker:cherry_pick_cli" +urls.Homepage = "https://github.com/python/cherry-picker" +scripts.cherry_picker = "cherry_picker.cherry_picker:cherry_pick_cli" [tool.hatch.version] source = "vcs" @@ -50,5 +47,32 @@ tag-pattern = '^cherry-picker-(?P[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)? [tool.hatch.version.raw-options] local_scheme = "no-local-version" -[tool.isort] -profile = "black" +[tool.ruff] +fix = true + +lint.select = [ + "C4", # flake8-comprehensions + "E", # pycodestyle errors + "F", # pyflakes errors + "I", # isort + "ICN", # flake8-import-conventions + "ISC", # flake8-implicit-str-concat + "LOG", # flake8-logging + "PGH", # pygrep-hooks + "PYI", # flake8-pyi + "RUF022", # unsorted-dunder-all + "RUF100", # unused noqa (yesqa) + "S", # flake8-bandit + "UP", # pyupgrade + "W", # pycodestyle warnings + "YTT", # flake8-2020 +] +lint.ignore = [ + "S101", # Use of assert detected + "S404", # subprocess module is possibly insecure + "S603", # subprocess call: check for execution of untrusted input +] +lint.isort.required-imports = [ "from __future__ import annotations" ] + +[tool.pyproject-fmt] +max_supported_python = "3.13" diff --git a/tox.ini b/tox.ini index f56c058..812ab48 100644 --- a/tox.ini +++ b/tox.ini @@ -1,17 +1,18 @@ [tox] -envlist = +requires = + tox>=4.2 +env_list = py{313, 312, 311, 310, 39} -isolated_build = true [testenv] -passenv = - FORCE_COLOR extras = dev +pass_env = + FORCE_COLOR commands = {envpython} -m pytest \ - --cov cherry_picker \ - --cov-report html \ - --cov-report term \ - --cov-report xml \ - {posargs} + --cov cherry_picker \ + --cov-report html \ + --cov-report term \ + --cov-report xml \ + {posargs} From e2540afb076226e667b832c7c4b5d4669e0fd1af Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 6 Oct 2024 14:20:26 +0300 Subject: [PATCH 40/45] Generate digital attestations for PyPI (PEP 740) (#135) --- .github/workflows/deploy.yml | 6 ++++++ .github/workflows/main.yml | 8 ++++++++ .pre-commit-config.yaml | 8 ++++---- cherry_picker/cherry_picker.py | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index afdf7d6..6dc1929 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -11,6 +11,9 @@ on: permissions: contents: read +env: + FORCE_COLOR: 1 + jobs: # Always build & lint package. build-package: @@ -47,6 +50,7 @@ jobs: - name: Publish to Test PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: + attestations: true repository-url: https://test.pypi.org/legacy/ # Publish to PyPI on GitHub Releases. @@ -71,3 +75,5 @@ jobs: - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + with: + attestations: true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 60f56db..a3fb835 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,6 +2,9 @@ name: tests on: [push, pull_request, workflow_dispatch] +permissions: + contents: read + env: FORCE_COLOR: 1 @@ -13,12 +16,14 @@ jobs: matrix: python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] os: [windows-latest, macos-latest, ubuntu-latest] + steps: - uses: actions/checkout@v4 with: # fetch all branches and tags # ref actions/checkout#448 fetch-depth: 0 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: @@ -26,11 +31,14 @@ jobs: allow-prereleases: true cache: pip cache-dependency-path: pyproject.toml + - name: Install tox run: | python -m pip install tox + - name: Run tests run: tox -e py + - name: Upload coverage uses: codecov/codecov-action@v4 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 71227b0..2a532db 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.7 + rev: v0.6.8 hooks: - id: ruff args: [--exit-non-zero-on-fix] @@ -31,12 +31,12 @@ repos: - id: check-github-workflows - repo: https://github.com/rhysd/actionlint - rev: v1.7.1 + rev: v1.7.2 hooks: - id: actionlint - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.10.1 + rev: v1.11.2 hooks: - id: mypy args: @@ -56,7 +56,7 @@ repos: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.19 + rev: v0.20.2 hooks: - id: validate-pyproject diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 89fc411..95229b1 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -36,7 +36,7 @@ WORKFLOW_STATES = enum.Enum( - "Workflow states", + "WORKFLOW_STATES", """ FETCHING_UPSTREAM FETCHED_UPSTREAM From 7fdaa0846ec6fca37f7778109778dbdb3b66d68c Mon Sep 17 00:00:00 2001 From: Olena <107187316+OlenaYefymenko@users.noreply.github.com> Date: Fri, 11 Oct 2024 23:18:41 +0300 Subject: [PATCH 41/45] Update minimum Python version to 3.9 in the configuration (#137) --- cherry_picker/test_cherry_picker.py | 133 ++++++++++++++++------------ pyproject.toml | 3 +- 2 files changed, 77 insertions(+), 59 deletions(-) diff --git a/cherry_picker/test_cherry_picker.py b/cherry_picker/test_cherry_picker.py index 9ce5cce..88c3cde 100644 --- a/cherry_picker/test_cherry_picker.py +++ b/cherry_picker/test_cherry_picker.py @@ -665,13 +665,15 @@ def test_get_updated_commit_message_with_trailers( with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True): cherry_picker = CherryPicker("origin", commit, []) - with mock.patch( - "cherry_picker.cherry_picker.validate_sha", return_value=True - ), mock.patch.object( - cherry_picker, "get_commit_message", return_value=commit_message - ), mock.patch( - "cherry_picker.cherry_picker.get_author_info_from_short_sha", - return_value="PR Author ", + with ( + mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True), + mock.patch.object( + cherry_picker, "get_commit_message", return_value=commit_message + ), + mock.patch( + "cherry_picker.cherry_picker.get_author_info_from_short_sha", + return_value="PR Author ", + ), ): updated_commit_message = cherry_picker.get_updated_commit_message( cherry_pick_branch @@ -914,9 +916,10 @@ class tested_state: r"stored in Git config using the following command: " r"`git config --local --remove-section cherry-picker`" ) - with mock.patch( - "cherry_picker.cherry_picker.validate_sha", return_value=True - ), pytest.raises(InvalidRepoException, match=expected_msg_regexp): + with ( + mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True), + pytest.raises(InvalidRepoException, match=expected_msg_regexp), + ): CherryPicker("origin", "xxx", []) @@ -932,9 +935,11 @@ def test_push_to_remote_interactive(tmp_git_repo_dir): with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True): cherry_picker = CherryPicker("origin", "xxx", []) - with mock.patch.object(cherry_picker, "run_cmd"), mock.patch.object( - cherry_picker, "open_pr" - ), mock.patch.object(cherry_picker, "get_pr_url", return_value="https://pr_url"): + with ( + mock.patch.object(cherry_picker, "run_cmd"), + mock.patch.object(cherry_picker, "open_pr"), + mock.patch.object(cherry_picker, "get_pr_url", return_value="https://pr_url"), + ): cherry_picker.push_to_remote("main", "backport-branch-test") assert get_state() == WORKFLOW_STATES.PR_OPENING @@ -944,8 +949,9 @@ def test_push_to_remote_botflow(tmp_git_repo_dir, monkeypatch): with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True): cherry_picker = CherryPicker("origin", "xxx", []) - with mock.patch.object(cherry_picker, "run_cmd"), mock.patch.object( - cherry_picker, "create_gh_pr" + with ( + mock.patch.object(cherry_picker, "run_cmd"), + mock.patch.object(cherry_picker, "create_gh_pr"), ): cherry_picker.push_to_remote("main", "backport-branch-test") assert get_state() == WORKFLOW_STATES.PR_CREATING @@ -956,8 +962,9 @@ def test_push_to_remote_no_auto_pr(tmp_git_repo_dir, monkeypatch): with mock.patch("cherry_picker.cherry_picker.validate_sha", return_value=True): cherry_picker = CherryPicker("origin", "xxx", [], auto_pr=False) - with mock.patch.object(cherry_picker, "run_cmd"), mock.patch.object( - cherry_picker, "create_gh_pr" + with ( + mock.patch.object(cherry_picker, "run_cmd"), + mock.patch.object(cherry_picker, "create_gh_pr"), ): cherry_picker.push_to_remote("main", "backport-branch-test") assert get_state() == WORKFLOW_STATES.PUSHED_TO_REMOTE @@ -995,10 +1002,13 @@ def test_backport_cherry_pick_fail( pr_remote, scm_revision, cherry_pick_target_branches ) - with pytest.raises(CherryPickException), mock.patch.object( - cherry_picker, "checkout_branch" - ), mock.patch.object(cherry_picker, "fetch_upstream"), mock.patch.object( - cherry_picker, "cherry_pick", side_effect=CherryPickException + with ( + pytest.raises(CherryPickException), + mock.patch.object(cherry_picker, "checkout_branch"), + mock.patch.object(cherry_picker, "fetch_upstream"), + mock.patch.object( + cherry_picker, "cherry_pick", side_effect=CherryPickException + ), ): cherry_picker.backport() @@ -1027,13 +1037,16 @@ def test_backport_cherry_pick_crash_ignored( pr_remote, scm_revision, cherry_pick_target_branches ) - with mock.patch.object(cherry_picker, "checkout_branch"), mock.patch.object( - cherry_picker, "fetch_upstream" - ), mock.patch.object(cherry_picker, "cherry_pick"), mock.patch.object( - cherry_picker, - "amend_commit_message", - side_effect=subprocess.CalledProcessError( - 1, ("git", "commit", "-am", "new commit message") + with ( + mock.patch.object(cherry_picker, "checkout_branch"), + mock.patch.object(cherry_picker, "fetch_upstream"), + mock.patch.object(cherry_picker, "cherry_pick"), + mock.patch.object( + cherry_picker, + "amend_commit_message", + side_effect=subprocess.CalledProcessError( + 1, ("git", "commit", "-am", "new commit message") + ), ), ): cherry_picker.backport() @@ -1067,9 +1080,10 @@ def test_backport_cherry_pick_branch_already_exists( ) git_branch(backport_branch_name) - with mock.patch.object(cherry_picker, "fetch_upstream"), pytest.raises( - BranchCheckoutException - ) as exc_info: + with ( + mock.patch.object(cherry_picker, "fetch_upstream"), + pytest.raises(BranchCheckoutException) as exc_info, + ): cherry_picker.backport() assert exc_info.value.branch_name == backport_branch_name @@ -1098,10 +1112,12 @@ def test_backport_success( pr_remote, scm_revision, cherry_pick_target_branches ) - with mock.patch.object(cherry_picker, "checkout_branch"), mock.patch.object( - cherry_picker, "fetch_upstream" - ), mock.patch.object( - cherry_picker, "amend_commit_message", return_value="commit message" + with ( + mock.patch.object(cherry_picker, "checkout_branch"), + mock.patch.object(cherry_picker, "fetch_upstream"), + mock.patch.object( + cherry_picker, "amend_commit_message", return_value="commit message" + ), ): cherry_picker.backport() @@ -1141,8 +1157,11 @@ def test_backport_pause_and_continue( pr_remote, scm_revision, cherry_pick_target_branches, push=False ) - with mock.patch.object(cherry_picker, "fetch_upstream"), mock.patch.object( - cherry_picker, "amend_commit_message", return_value="commit message" + with ( + mock.patch.object(cherry_picker, "fetch_upstream"), + mock.patch.object( + cherry_picker, "amend_commit_message", return_value="commit message" + ), ): cherry_picker.backport() @@ -1164,26 +1183,26 @@ def test_backport_pause_and_continue( Co-authored-by: Author Name """ - with mock.patch( - "cherry_picker.cherry_picker.wipe_cfg_vals_from_git_cfg" - ), mock.patch( - "cherry_picker.cherry_picker.get_full_sha_from_short", - return_value="xxxxxxyyyyyy", - ), mock.patch( - "cherry_picker.cherry_picker.get_base_branch", return_value="3.8" - ), mock.patch( - "cherry_picker.cherry_picker.get_current_branch", - return_value="backport-xxx-3.8", - ), mock.patch.object( - cherry_picker, "amend_commit_message", return_value=commit_message - ) as amend_commit_message, mock.patch.object( - cherry_picker, "get_updated_commit_message", return_value=commit_message - ) as get_updated_commit_message, mock.patch.object( - cherry_picker, "checkout_branch" - ), mock.patch.object( - cherry_picker, "fetch_upstream" - ), mock.patch.object( - cherry_picker, "cleanup_branch" + with ( + mock.patch("cherry_picker.cherry_picker.wipe_cfg_vals_from_git_cfg"), + mock.patch( + "cherry_picker.cherry_picker.get_full_sha_from_short", + return_value="xxxxxxyyyyyy", + ), + mock.patch("cherry_picker.cherry_picker.get_base_branch", return_value="3.8"), + mock.patch( + "cherry_picker.cherry_picker.get_current_branch", + return_value="backport-xxx-3.8", + ), + mock.patch.object( + cherry_picker, "amend_commit_message", return_value=commit_message + ) as amend_commit_message, + mock.patch.object( + cherry_picker, "get_updated_commit_message", return_value=commit_message + ) as get_updated_commit_message, + mock.patch.object(cherry_picker, "checkout_branch"), + mock.patch.object(cherry_picker, "fetch_upstream"), + mock.patch.object(cherry_picker, "cleanup_branch"), ): cherry_picker.continue_cherry_pick() diff --git a/pyproject.toml b/pyproject.toml index 121ff51..35a72fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,12 +10,11 @@ name = "cherry-picker" readme = "README.md" maintainers = [ { name = "Python Core Developers", email = "core-workflow@python.org" } ] authors = [ { name = "Mariatta Wijaya", email = "mariatta@python.org" } ] -requires-python = ">=3.8" +requires-python = ">=3.9" classifiers = [ "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", From 52565cb447f0416a0cc51522a5bea64ec396e323 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:08:48 +0300 Subject: [PATCH 42/45] Update changelog for 2.3.0 (#138) Co-authored-by: Ezio Melotti --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09fe12a..e9ed5b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +## 2.3.0 + +- Add support for Python 3.13 + ([PR 127](https://github.com/python/cherry-picker/pull/127), + [PR 134](https://github.com/python/cherry-picker/pull/134)) +- Drop support for EOL Python 3.8 + ([PR 133](https://github.com/python/cherry-picker/pull/133), + [PR 137](https://github.com/python/cherry-picker/pull/137)) +- Resolve usernames when the remote ends with a trailing slash ([PR 110](https://github.com/python/cherry-picker/pull/110)) +- Optimize `validate_sha()` with `--max-count=1` ([PR 111](https://github.com/python/cherry-picker/pull/111)) +- Make # replacing more strict ([PR 115](https://github.com/python/cherry-picker/pull/115)) +- Remove multiple commit prefixes ([PR 118](https://github.com/python/cherry-picker/pull/118)) +- Handle whitespace when calculating usernames ([PR 132](https://github.com/python/cherry-picker/pull/132)) +- Publish to PyPI using Trusted Publishers ([PR 94](https://github.com/python/cherry-picker/pull/94)) +- Generate digital attestations for PyPI ([PEP 740](https://peps.python.org/pep-0740/)) + ([PR 135](https://github.com/python/cherry-picker/pull/135)) + ## 2.2.0 - Add log messages From 71490d0ded27a1dabfacc11ad763fa636e470819 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 12 Oct 2024 17:46:50 +0300 Subject: [PATCH 43/45] Exclude bots from generated release notes (#139) --- .github/release.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .github/release.yml diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..9d1e098 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,5 @@ +changelog: + exclude: + authors: + - dependabot + - pre-commit-ci From a7d1d0de9d5bcf1461aaae45c28ea8ffa6dfc949 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:06:48 +0300 Subject: [PATCH 44/45] Generate `__version__` at build to avoid slow `importlib.metadata` import (#141) --- .gitignore | 3 +++ cherry_picker/__init__.py | 4 ++-- pyproject.toml | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8b6ca4e..18a1ce6 100644 --- a/.gitignore +++ b/.gitignore @@ -399,3 +399,6 @@ $RECYCLE.BIN/ *.lnk # End of https://www.gitignore.io/api/git,linux,pydev,python,windows,pycharm+all,jupyternotebook,vim,webstorm,emacs + +# hatch-vcs +cherry_picker/_version.py diff --git a/cherry_picker/__init__.py b/cherry_picker/__init__.py index 843751f..5a6ec37 100644 --- a/cherry_picker/__init__.py +++ b/cherry_picker/__init__.py @@ -2,6 +2,6 @@ from __future__ import annotations -import importlib.metadata +from ._version import __version__ -__version__ = importlib.metadata.version(__name__) +__all__ = ["__version__"] diff --git a/pyproject.toml b/pyproject.toml index 35a72fc..a0021ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,9 @@ source = "vcs" # Change regex to match tags like "cherry-picker-v2.2.0". tag-pattern = '^cherry-picker-(?P[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$' +[tool.hatch.build.hooks.vcs] +version-file = "cherry_picker/_version.py" + [tool.hatch.version.raw-options] local_scheme = "no-local-version" From 7721133ef148db8a5d6787fd1920a80587d2607b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:07:26 +0300 Subject: [PATCH 45/45] PyPI metatada: re-add description (#140) --- pyproject.toml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a0021ea..6c3d7c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ requires = [ [project] name = "cherry-picker" +description = "Backport CPython changes from main to maintenance branches" readme = "README.md" maintainers = [ { name = "Python Core Developers", email = "core-workflow@python.org" } ] authors = [ { name = "Mariatta Wijaya", email = "mariatta@python.org" } ] @@ -21,10 +22,7 @@ classifiers = [ "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", ] -dynamic = [ - "description", - "version", -] +dynamic = [ "version" ] dependencies = [ "click>=6", "gidgethub", @@ -51,7 +49,6 @@ local_scheme = "no-local-version" [tool.ruff] fix = true - lint.select = [ "C4", # flake8-comprehensions "E", # pycodestyle errors