ghstack 0.11.0__tar.gz → 0.13.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. ghstack-0.13.0/LICENSE +19 -0
  2. {ghstack-0.11.0 → ghstack-0.13.0}/PKG-INFO +6 -5
  3. {ghstack-0.11.0 → ghstack-0.13.0}/README.md +1 -1
  4. {ghstack-0.11.0 → ghstack-0.13.0}/pyproject.toml +6 -3
  5. ghstack-0.13.0/src/ghstack/cherry_pick.py +65 -0
  6. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/cli.py +30 -0
  7. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/github_real.py +4 -0
  8. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/github_utils.py +36 -13
  9. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/submit.py +1 -3
  10. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/test_prelude.py +14 -0
  11. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/__init__.py +0 -0
  12. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/__main__.py +0 -0
  13. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/action.py +0 -0
  14. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/cache.py +0 -0
  15. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/checkout.py +0 -0
  16. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/circleci.py +0 -0
  17. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/circleci_real.py +0 -0
  18. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/config.py +0 -0
  19. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/diff.py +0 -0
  20. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/forensics.py +0 -0
  21. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/git.py +0 -0
  22. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/github.py +0 -0
  23. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/github_fake.py +0 -0
  24. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/github_schema.graphql +0 -0
  25. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/gpg_sign.py +0 -0
  26. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/land.py +0 -0
  27. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/logs.py +0 -0
  28. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/py.typed +0 -0
  29. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/rage.py +0 -0
  30. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/shell.py +0 -0
  31. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/status.py +0 -0
  32. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/trailers.py +0 -0
  33. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/types.py +0 -0
  34. {ghstack-0.11.0 → ghstack-0.13.0}/src/ghstack/unlink.py +0 -0
ghstack-0.13.0/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) Edward Z. Yang <ezyang@mit.edu>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -1,10 +1,11 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: ghstack
3
- Version: 0.11.0
3
+ Version: 0.13.0
4
4
  Summary: Stack diff support for GitHub
5
5
  Author: Edward Z. Yang
6
6
  Author-email: Edward Z. Yang <ezyang@mit.edu>
7
- License: MIT
7
+ License-Expression: MIT
8
+ License-File: LICENSE
8
9
  Classifier: Programming Language :: Python :: 3
9
10
  Classifier: License :: OSI Approved :: MIT License
10
11
  Classifier: Operating System :: OS Independent
@@ -14,7 +15,7 @@ Requires-Dist: requests>=2,<3
14
15
  Requires-Dist: typing-extensions>=3
15
16
  Requires-Dist: click>=8,<9
16
17
  Requires-Dist: flake8>=7.0.0,<8.0.0
17
- Requires-Python: >=3.8.1, <4.0.0
18
+ Requires-Python: >=3.9.1, <4.0.0
18
19
  Project-URL: repository, https://github.com/ezyang/ghstack
19
20
  Description-Content-Type: text/markdown
20
21
 
@@ -28,7 +29,7 @@ uv tool install ghstack
28
29
 
29
30
  ghstack is tested with
30
31
  [several different Python versions](https://github.com/ezyang/ghstack/blob/master/.github/workflows/test.yml#L13).
31
- It requires at least Python 3.8.1.
32
+ It requires at least Python 3.9.1.
32
33
 
33
34
  ## How to setup
34
35
 
@@ -8,7 +8,7 @@ uv tool install ghstack
8
8
 
9
9
  ghstack is tested with
10
10
  [several different Python versions](https://github.com/ezyang/ghstack/blob/master/.github/workflows/test.yml#L13).
11
- It requires at least Python 3.8.1.
11
+ It requires at least Python 3.9.1.
12
12
 
13
13
  ## How to setup
14
14
 
@@ -2,8 +2,11 @@
2
2
  authors = [
3
3
  {name = "Edward Z. Yang", email = "ezyang@mit.edu"},
4
4
  ]
5
- license = {text = "MIT"}
6
- requires-python = "<4.0.0,>=3.8.1"
5
+ license = "MIT"
6
+ license-files = [
7
+ "LICENSE",
8
+ ]
9
+ requires-python = "<4.0.0,>=3.9.1"
7
10
  dependencies = [
8
11
  "aiohttp<4,>=3",
9
12
  "importlib-metadata>=1.4; python_version < \"3.8\"",
@@ -13,7 +16,7 @@ dependencies = [
13
16
  "flake8<8.0.0,>=7.0.0",
14
17
  ]
15
18
  name = "ghstack"
16
- version = "0.11.0"
19
+ version = "0.13.0"
17
20
  description = "Stack diff support for GitHub"
18
21
  readme = "README.md"
19
22
  classifiers = [
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import logging
4
+ import re
5
+
6
+ import ghstack.github
7
+ import ghstack.github_utils
8
+ import ghstack.shell
9
+
10
+
11
+ def main(
12
+ pull_request: str,
13
+ github: ghstack.github.GitHubEndpoint,
14
+ sh: ghstack.shell.Shell,
15
+ remote_name: str,
16
+ stack: bool = False,
17
+ ) -> None:
18
+
19
+ params = ghstack.github_utils.parse_pull_request(
20
+ pull_request, sh=sh, remote_name=remote_name
21
+ )
22
+ head_ref = github.get_head_ref(**params)
23
+ orig_ref = re.sub(r"/head$", "/orig", head_ref)
24
+ if orig_ref == head_ref:
25
+ logging.warning(
26
+ "The ref {} doesn't look like a ghstack reference".format(head_ref)
27
+ )
28
+
29
+ sh.git("fetch", "--prune", remote_name)
30
+
31
+ if stack:
32
+ # Cherry-pick the entire stack from merge-base to the commit
33
+ remote_orig_ref = remote_name + "/" + orig_ref
34
+
35
+ # Find the merge-base with the main branch
36
+ repo_info = ghstack.github_utils.get_github_repo_info(
37
+ github=github,
38
+ sh=sh,
39
+ github_url=params["github_url"],
40
+ remote_name=remote_name,
41
+ )
42
+ main_branch = f"{remote_name}/{repo_info['default_branch']}"
43
+
44
+ # Get merge-base between the commit and main branch
45
+ merge_base = sh.git("merge-base", main_branch, remote_orig_ref).strip()
46
+
47
+ # Get all commits from merge-base to the target commit
48
+ commit_list = (
49
+ sh.git("rev-list", "--reverse", f"{merge_base}..{remote_orig_ref}")
50
+ .strip()
51
+ .split("\n")
52
+ )
53
+
54
+ if not commit_list or commit_list == [""]:
55
+ raise RuntimeError("No commits found to cherry-pick in the specified range")
56
+
57
+ logging.info(f"Cherry-picking {len(commit_list)} commits from stack")
58
+ for commit in commit_list:
59
+ sh.git("cherry-pick", commit)
60
+ logging.info(f"Cherry-picked {commit}")
61
+ else:
62
+ # Cherry-pick just the single commit
63
+ remote_orig_ref = remote_name + "/" + orig_ref
64
+ sh.git("cherry-pick", remote_orig_ref)
65
+ logging.info(f"Cherry-picked {orig_ref}")
@@ -1,5 +1,6 @@
1
1
  import asyncio
2
2
  import contextlib
3
+ import sys
3
4
  from typing import Generator, List, Optional, Tuple
4
5
 
5
6
  import click
@@ -7,6 +8,7 @@ import click
7
8
  import ghstack
8
9
  import ghstack.action
9
10
  import ghstack.checkout
11
+ import ghstack.cherry_pick
10
12
  import ghstack.circleci_real
11
13
  import ghstack.config
12
14
  import ghstack.github_real
@@ -78,6 +80,12 @@ def main(
78
80
  """
79
81
  Submit stacks of diffs to Github
80
82
  """
83
+ if sys.version_info >= (3, 14):
84
+ # Create new event loop as asyncio.get_event_loop() throws runtime error in 3.14
85
+ import asyncio as _asyncio
86
+
87
+ _asyncio.set_event_loop(_asyncio.new_event_loop())
88
+
81
89
  EXIT_STACK.enter_context(ghstack.logs.manager(debug=debug))
82
90
 
83
91
  if not ctx.invoked_subcommand:
@@ -126,6 +134,28 @@ def checkout(pull_request: str) -> None:
126
134
  )
127
135
 
128
136
 
137
+ @main.command("cherry-pick")
138
+ @click.option(
139
+ "--stack",
140
+ "-s",
141
+ is_flag=True,
142
+ help="Cherry-pick all commits from the commit to the merge-base with main branch",
143
+ )
144
+ @click.argument("pull_request", metavar="PR")
145
+ def cherry_pick(stack: bool, pull_request: str) -> None:
146
+ """
147
+ Cherry-pick a PR
148
+ """
149
+ with cli_context(request_github_token=False) as (shell, config, github):
150
+ ghstack.cherry_pick.main(
151
+ pull_request=pull_request,
152
+ github=github,
153
+ sh=shell,
154
+ remote_name=config.remote_name,
155
+ stack=stack,
156
+ )
157
+
158
+
129
159
  @main.command("land")
130
160
  @click.option("--force", is_flag=True, help="force land even if the PR is closed")
131
161
  @click.argument("pull_request", metavar="PR")
@@ -224,6 +224,10 @@ permissions. Please create a new OAuth token at
224
224
  https://{github_url}/settings/tokens and DOUBLE CHECK that you checked
225
225
  "public_repo" for permissions, and update ~/.ghstackrc with your new
226
226
  value.
227
+
228
+ Another possible reason for this error is if the repository has moved
229
+ to a new location or been renamed. Check that the repository URL is
230
+ still correct.
227
231
  """.format(
228
232
  url=url, github_url=self.github_url
229
233
  )
@@ -77,20 +77,43 @@ def get_github_repo_info(
77
77
  name_with_owner = {"owner": repo_owner, "name": repo_name}
78
78
 
79
79
  # TODO: Cache this guy
80
- repo = github.graphql(
81
- """
82
- query ($owner: String!, $name: String!) {
83
- repository(name: $name, owner: $owner) {
84
- id
85
- isFork
86
- defaultBranchRef {
87
- name
80
+ try:
81
+ repo = github.graphql(
82
+ """
83
+ query ($owner: String!, $name: String!) {
84
+ repository(name: $name, owner: $owner) {
85
+ id
86
+ isFork
87
+ defaultBranchRef {
88
+ name
89
+ }
88
90
  }
89
- }
90
- }""",
91
- owner=name_with_owner["owner"],
92
- name=name_with_owner["name"],
93
- )["data"]["repository"]
91
+ }""",
92
+ owner=name_with_owner["owner"],
93
+ name=name_with_owner["name"],
94
+ )["data"]["repository"]
95
+ except RuntimeError as e:
96
+ # Check if this is a repository access error (NOT_FOUND)
97
+ error_msg = str(e)
98
+ if (
99
+ "Could not resolve to a Repository" in error_msg
100
+ and "NOT_FOUND" in error_msg
101
+ ):
102
+ raise RuntimeError(
103
+ f"Original error: {error_msg}\n\n"
104
+ f"Could not access repository '{name_with_owner['owner']}/{name_with_owner['name']}'. "
105
+ f"This usually means:\n"
106
+ f"1. The repository is private and your OAuth token doesn't have access\n"
107
+ f"2. The repository is in a different organization that hasn't granted access\n"
108
+ f"3. The repository doesn't exist or has been moved\n\n"
109
+ f"If this is a private repository or in a separate organization, you can grant access by:\n"
110
+ f"1. Delete the 'github_oauth' entry from your .ghstackrc file\n"
111
+ f"2. Run ghstack again to redo the OAuth flow\n"
112
+ f"3. Make sure to grant access to the appropriate organizations when prompted"
113
+ )
114
+ else:
115
+ # Re-raise the original error if it's not the repository access issue
116
+ raise
94
117
 
95
118
  return {
96
119
  "name_with_owner": name_with_owner,
@@ -167,9 +167,7 @@ def strip_mentions(body: str) -> str:
167
167
  return RE_MENTION.sub(r"\1", body)
168
168
 
169
169
 
170
- STACK_HEADER = (
171
- "Stack from [ghstack](https://github.com/ezyang/ghstack) (oldest at bottom)"
172
- )
170
+ STACK_HEADER = f"Stack from [ghstack](https://github.com/ezyang/ghstack/tree/{ghstack.__version__}) (oldest at bottom)"
173
171
 
174
172
 
175
173
  def starts_with_bullet(body: str) -> bool:
@@ -12,6 +12,8 @@ from typing import Any, Callable, Iterator, List, Optional, Sequence, Tuple, Uni
12
12
 
13
13
  from expecttest import assert_expected_inline
14
14
 
15
+ import ghstack.cherry_pick
16
+
15
17
  import ghstack.github
16
18
  import ghstack.github_fake
17
19
  import ghstack.github_utils
@@ -29,6 +31,7 @@ __all__ = [
29
31
  "gh_submit",
30
32
  "gh_land",
31
33
  "gh_unlink",
34
+ "gh_cherry_pick",
32
35
  "GitCommitHash",
33
36
  "checkout",
34
37
  "amend",
@@ -237,6 +240,17 @@ def gh_unlink() -> None:
237
240
  )
238
241
 
239
242
 
243
+ def gh_cherry_pick(pull_request: str, stack: bool = False) -> None:
244
+ self = CTX
245
+ return ghstack.cherry_pick.main(
246
+ pull_request=pull_request,
247
+ github=self.github,
248
+ sh=self.sh,
249
+ remote_name="origin",
250
+ stack=stack,
251
+ )
252
+
253
+
240
254
  def write_file_and_add(filename: str, contents: str) -> None:
241
255
  self = CTX
242
256
  with self.sh.open(filename, "w") as f:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes