Skip to content

Commit d80d607

Browse files
Merge pull request #85058 from charles-zablit/charles-zablit/update-checkout/type-arguments
[NFC][update-checkout] add type hints
2 parents 7f6a4da + 9377c4b commit d80d607

File tree

3 files changed

+198
-160
lines changed

3 files changed

+198
-160
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import argparse
2+
from typing import List, Optional
3+
4+
from build_swift.build_swift.constants import SWIFT_SOURCE_ROOT
5+
6+
7+
class CliArguments(argparse.Namespace):
8+
clone: bool
9+
clone_with_ssh: bool
10+
skip_history: bool
11+
skip_tags: bool
12+
skip_repository_list: List[str]
13+
all_repositories: bool
14+
scheme: Optional[str]
15+
reset_to_remote: bool
16+
clean: bool
17+
stash: bool
18+
configs: List[str]
19+
github_comment: Optional[str]
20+
dump_hashes: bool
21+
dump_hashes_config: Optional[str]
22+
tag: Optional[str]
23+
match_timestamp: bool
24+
n_processes: int
25+
source_root: str
26+
use_submodules: bool
27+
verbose: bool
28+
29+
@staticmethod
30+
def parse_args() -> "CliArguments":
31+
parser = argparse.ArgumentParser(
32+
formatter_class=argparse.RawDescriptionHelpFormatter,
33+
description="""
34+
By default, updates your checkouts of Swift, SourceKit, LLDB, and SwiftPM
35+
repositories.
36+
""",
37+
)
38+
parser.add_argument(
39+
"--clone",
40+
help="obtain sources for Swift and related projects",
41+
action="store_true",
42+
)
43+
parser.add_argument(
44+
"--clone-with-ssh",
45+
help="Obtain sources for Swift and related projects via SSH",
46+
action="store_true",
47+
)
48+
parser.add_argument(
49+
"--skip-history",
50+
help="Skip histories when obtaining sources",
51+
action="store_true",
52+
)
53+
parser.add_argument(
54+
"--skip-tags", help="Skip tags when obtaining sources", action="store_true"
55+
)
56+
parser.add_argument(
57+
"--skip-repository",
58+
metavar="DIRECTORY",
59+
default=[],
60+
help="Skip the specified repository",
61+
dest="skip_repository_list",
62+
action="append",
63+
)
64+
parser.add_argument(
65+
"--all-repositories",
66+
help="""Includes repositories not required for current platform.
67+
This will not override '--skip-repositories'""",
68+
action="store_true",
69+
)
70+
parser.add_argument(
71+
"--scheme",
72+
help='Use branches from the specified branch-scheme. A "branch-scheme"'
73+
" is a list of (repo, branch) pairs.",
74+
metavar="BRANCH-SCHEME",
75+
)
76+
parser.add_argument(
77+
"--reset-to-remote",
78+
help="Reset each branch to the remote state.",
79+
action="store_true",
80+
)
81+
parser.add_argument(
82+
"--clean",
83+
help="""Delete tracked and untracked changes, ignored files, and abort
84+
an ongoing rebase, if any, before updating a repository.""",
85+
action="store_true",
86+
)
87+
parser.add_argument(
88+
"--stash",
89+
help="""Stash tracked and untracked changes, delete ignored files, and
90+
abort an ongoing rebase, if any, before updating a repository.""",
91+
action="store_true",
92+
)
93+
parser.add_argument(
94+
"--config",
95+
help="""The configuration file to use. Can be specified multiple times,
96+
each config will be merged together with a 'last-wins' strategy.
97+
Overwriting branch-schemes is not allowed.""",
98+
action="append",
99+
default=[],
100+
dest="configs",
101+
)
102+
parser.add_argument(
103+
"--github-comment",
104+
help="""Check out related pull requests referenced in the given
105+
free-form GitHub-style comment.""",
106+
metavar="GITHUB-COMMENT",
107+
)
108+
parser.add_argument(
109+
"--dump-hashes",
110+
action="store_true",
111+
help="Dump the git hashes of all repositories being tracked",
112+
)
113+
parser.add_argument(
114+
"--dump-hashes-config",
115+
help="Dump the git hashes of all repositories packaged into "
116+
"update-checkout-config.json",
117+
metavar="BRANCH-SCHEME-NAME",
118+
)
119+
parser.add_argument(
120+
"--tag",
121+
help="""Check out each repository to the specified tag.""",
122+
metavar="TAG-NAME",
123+
)
124+
parser.add_argument(
125+
"--match-timestamp",
126+
help="Check out adjacent repositories to match timestamp of "
127+
" current swift checkout.",
128+
action="store_true",
129+
)
130+
parser.add_argument(
131+
"-j",
132+
"--jobs",
133+
type=int,
134+
help="Number of threads to run at once",
135+
default=0,
136+
dest="n_processes",
137+
)
138+
parser.add_argument(
139+
"--source-root",
140+
help="The root directory to checkout repositories",
141+
default=SWIFT_SOURCE_ROOT,
142+
)
143+
parser.add_argument(
144+
"--use-submodules",
145+
help="Checkout repositories as git submodules.",
146+
action="store_true",
147+
)
148+
parser.add_argument(
149+
"-v",
150+
"--verbose",
151+
help="Increases the script's verbosity.",
152+
action="store_true",
153+
)
154+
return parser.parse_args()

utils/update_checkout/update_checkout/runner_arguments.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from dataclasses import dataclass
2-
from typing import Any, Dict
2+
from typing import Any, Dict, List
3+
4+
from .cli_arguments import CliArguments
35

46
@dataclass
57
class RunnerArguments:
@@ -22,13 +24,8 @@ class UpdateArguments(RunnerArguments):
2224

2325
@dataclass
2426
class AdditionalSwiftSourcesArguments(RunnerArguments):
25-
args: Any
26-
"Arguments passed during CLI invocation." # TODO: Properly type this.
27+
args: CliArguments
2728
repo_info: str
2829
repo_branch: str
2930
remote: str
30-
with_ssh: bool
31-
skip_history: bool
32-
skip_tags: bool
33-
skip_repository_list: bool
34-
use_submodules: bool
31+
skip_repository_list: List[str]

0 commit comments

Comments
 (0)