()
| 127 | |
| 128 | |
| 129 | def 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 |
no test coverage detected
searching dependent graphs…