MCPcopy Index your code
hub / github.com/python/mypy / main

Function main

misc/sync-typeshed.py:129–224  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127
128
129def main() -> None:
130 parser = argparse.ArgumentParser()
131 parser.add_argument(
132 "--commit",
133 default=None,
134 help="Typeshed commit (default to latest main if using a repository clone)",
135 )
136 parser.add_argument(
137 "--typeshed-dir",
138 default=None,
139 help="Location of typeshed (default to a temporary repository clone)",
140 )
141 parser.add_argument(
142 "--make-pr",
143 action="store_true",
144 help="Whether to make a PR with the changes (default to no)",
145 )
146 parser.add_argument("--no-branch", action="store_true", help="Skip creating a new branch")
147 args = parser.parse_args()
148
149 check_state()
150
151 if args.make_pr:
152 if os.environ.get("GITHUB_TOKEN") is None:
153 raise ValueError("GITHUB_TOKEN environment variable must be set")
154
155 with tempfile.TemporaryDirectory() as tmpdir:
156 # Stash patches before checking out a new branch
157 typeshed_patches = os.path.join("misc", "typeshed_patches")
158 tmp_patches = os.path.join(tmpdir, "typeshed_patches")
159 shutil.copytree(typeshed_patches, tmp_patches)
160
161 branch_name = "mypybot/sync-typeshed"
162 if not args.no_branch:
163 subprocess.run(["git", "checkout", "-B", branch_name, "origin/master"], check=True)
164
165 # Copy the stashed patches back
166 shutil.rmtree(typeshed_patches, ignore_errors=True)
167 shutil.copytree(tmp_patches, typeshed_patches)
168 if subprocess.run(["git", "diff", "--quiet", "--exit-code"], check=False).returncode != 0:
169 subprocess.run(["git", "commit", "-am", "Update typeshed patches"], check=True)
170
171 if not args.typeshed_dir:
172 tmp_typeshed = os.path.join(tmpdir, "typeshed")
173 os.makedirs(tmp_typeshed)
174 # Clone typeshed repo if no directory given.
175 print(f"Cloning typeshed in {tmp_typeshed}...")
176 subprocess.run(
177 ["git", "clone", "https://github.com/python/typeshed.git"],
178 check=True,
179 cwd=tmp_typeshed,
180 )
181 repo = os.path.join(tmp_typeshed, "typeshed")
182 commit = update_typeshed(repo, args.commit)
183 else:
184 commit = update_typeshed(args.typeshed_dir, args.commit)
185
186 assert commit

Callers 1

sync-typeshed.pyFile · 0.70

Calls 12

check_stateFunction · 0.85
ValueErrorClass · 0.85
printFunction · 0.85
update_typeshedFunction · 0.85
sortedFunction · 0.85
RuntimeErrorClass · 0.85
add_argumentMethod · 0.80
getMethod · 0.45
joinMethod · 0.45
runMethod · 0.45
dedentMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…