| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,13 +27,11 @@ def highlight(text: str, color: str) -> str: | |||
| 27 | 27 | return f"{color}{text}{Colors.RESET}" | |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | - def is_valid(one: str, total: Union[str, dict[str, str]]): | ||
| 30 | + def check_valid(one: str, total: Union[list[str], dict[str, list[str]]]) -> None: | ||
| 31 | 31 | if isinstance(total, dict): | |
| 32 | - total = total.keys() | ||
| 32 | + total = list(total.keys()) | ||
| 33 | 33 | if one not in total: | |
| 34 | - valid = ", ".join( | ||
| 35 | - [highlight(key, Colors.ORANGE) for key in total] | ||
| 36 | - ) | ||
| 34 | + valid = ", ".join([highlight(key, Colors.ORANGE) for key in total]) | ||
| 37 | 35 | raise typer.BadParameter( | |
| 38 | 36 | f"Invalid {highlight('REPO_OR_REPO_SPLIT', Colors.RED)}. Must be one of: {valid}", | |
| 39 | 37 | param_hint="REPO or REPO_SPLIT", | |
@@ -53,7 +51,7 @@ def setup( | |||
| 53 | 51 | base_dir: str = typer.Option("repos/", help="Base directory to clone repos to"), | |
| 54 | 52 | ) -> None: | |
| 55 | 53 | """Commit0 clone a repo split.""" | |
| 56 | - is_valid(repo_split, SPLIT) | ||
| 54 | + check_valid(repo_split, SPLIT) | ||
| 57 | 55 | ||
| 58 | 56 | typer.echo(f"Cloning repository for split: {repo_split}") | |
| 59 | 57 | typer.echo(f"Dataset name: {dataset_name}") | |
@@ -81,7 +79,7 @@ def build( | |||
| 81 | 79 | num_workers: int = typer.Option(8, help="Number of workers"), | |
| 82 | 80 | ) -> None: | |
| 83 | 81 | """Commit0 build a repository.""" | |
| 84 | - is_valid(repo_split, SPLIT) | ||
| 82 | + check_valid(repo_split, SPLIT) | ||
| 85 | 83 | ||
| 86 | 84 | typer.echo(f"Building repository for split: {repo_split}") | |
| 87 | 85 | typer.echo(f"Dataset name: {dataset_name}") | |
@@ -104,7 +102,7 @@ def get_tests( | |||
| 104 | 102 | ), | |
| 105 | 103 | ) -> None: | |
| 106 | 104 | """Get tests for a Commit0 repository.""" | |
| 107 | - is_valid(repo_name, SPLIT_ALL) | ||
| 105 | + check_valid(repo_name, SPLIT_ALL) | ||
| 108 | 106 | ||
| 109 | 107 | typer.echo(f"Getting tests for repository: {repo_name}") | |
| 110 | 108 | ||
@@ -116,8 +114,13 @@ def test( | |||
| 116 | 114 | repo_or_repo_path: str = typer.Argument( | |
| 117 | 115 | ..., help="Directory of the repository to test" | |
| 118 | 116 | ), | |
| 119 | - test_ids: str = typer.Argument(..., help="All ways pytest supports to run and select tests. Please provide a single string. Example: \"test_mod.py\", \"testing/\", \"test_mod.py::test_func\", \"-k 'MyClass and not method'\""), | ||
| 120 | - branch: Union[str, None] = typer.Option(None, help="Branch to test (branch MUST be provided or use --reference)"), | ||
| 117 | + test_ids: str = typer.Argument( | ||
| 118 | + ..., | ||
| 119 | + help='All ways pytest supports to run and select tests. Please provide a single string. Example: "test_mod.py", "testing/", "test_mod.py::test_func", "-k \'MyClass and not method\'"', | ||
| 120 | + ), | ||
| 121 | + branch: Union[str, None] = typer.Option( | ||
| 122 | + None, help="Branch to test (branch MUST be provided or use --reference)" | ||
| 123 | + ), | ||
| 121 | 124 | dataset_name: str = typer.Option( | |
| 122 | 125 | "wentingzhao/commit0_docstring", help="Name of the Huggingface dataset" | |
| 123 | 126 | ), | |
@@ -126,24 +129,26 @@ def test( | |||
| 126 | 129 | backend: str = typer.Option("local", help="Backend to use for testing"), | |
| 127 | 130 | timeout: int = typer.Option(1800, help="Timeout for tests in seconds"), | |
| 128 | 131 | num_cpus: int = typer.Option(1, help="Number of CPUs to use"), | |
| 129 | - reference: Annotated[bool, typer.Option("--reference", help="Test the reference commit.")] = False | ||
| 132 | + reference: Annotated[ | ||
| 133 | + bool, typer.Option("--reference", help="Test the reference commit.") | ||
| 134 | + ] = False, | ||
| 130 | 135 | ) -> None: | |
| 131 | 136 | """Run tests on a Commit0 repository.""" | |
| 132 | - typer.echo(f"Running tests for repository: {repo_or_repo_path}") | ||
| 133 | - typer.echo(f"Branch: {branch}") | ||
| 134 | - typer.echo(f"Test IDs: {test_ids}") | ||
| 135 | - | ||
| 136 | - if repo_or_repo_path.endswith('/'): | ||
| 137 | + if repo_or_repo_path.endswith("/"): | ||
| 137 | 138 | repo_or_repo_path = repo_or_repo_path[:-1] | |
| 138 | - is_valid(repo_or_repo_path.split('/')[-1], SPLIT_ALL) | ||
| 139 | + check_valid(repo_or_repo_path.split("/")[-1], SPLIT_ALL) | ||
| 140 | + if not branch and not reference: | ||
| 141 | + raise typer.BadParameter( | ||
| 142 | + f"Invalid {highlight('BRANCH', Colors.RED)}. Either --reference or provide a branch name.", | ||
| 143 | + param_hint="BRANCH", | ||
| 144 | + ) | ||
| 139 | 145 | if reference: | |
| 140 | 146 | branch = "reference" | |
| 147 | + assert branch is not None, "branch is not specified" | ||
| 141 | 148 | ||
| 142 | - if not branch and not reference: | ||
| 143 | - raise typer.BadParameter( | ||
| 144 | - f"Invalid {highlight('BRANCH', Colors.RED)}. Either --reference or provide a branch name.", | ||
| 145 | - param_hint="BRANCH", | ||
| 146 | - ) | ||
| 149 | + typer.echo(f"Running tests for repository: {repo_or_repo_path}") | ||
| 150 | + typer.echo(f"Branch: {branch}") | ||
| 151 | + typer.echo(f"Test IDs: {test_ids}") | ||
| 147 | 152 | ||
| 148 | 153 | commit0.harness.run_pytest_ids.main( | |
| 149 | 154 | dataset_name, | |
@@ -164,7 +169,9 @@ def evaluate( | |||
| 164 | 169 | repo_split: str = typer.Argument( | |
| 165 | 170 | ..., help=f"Split of repositories, one of {SPLIT.keys()}" | |
| 166 | 171 | ), | |
| 167 | - branch: Union[str, None] = typer.Option(None, help="Branch to evaluate (branch MUST be provided or use --reference)"), | ||
| 172 | + branch: Union[str, None] = typer.Option( | ||
| 173 | + None, help="Branch to evaluate (branch MUST be provided or use --reference)" | ||
| 174 | + ), | ||
| 168 | 175 | dataset_name: str = typer.Option( | |
| 169 | 176 | "wentingzhao/commit0_docstring", help="Name of the Huggingface dataset" | |
| 170 | 177 | ), | |
@@ -174,19 +181,21 @@ def evaluate( | |||
| 174 | 181 | timeout: int = typer.Option(1800, help="Timeout for evaluation in seconds"), | |
| 175 | 182 | num_cpus: int = typer.Option(1, help="Number of CPUs to use"), | |
| 176 | 183 | num_workers: int = typer.Option(8, help="Number of workers to use"), | |
| 177 | - reference: Annotated[bool, typer.Option("--reference", help="Evaluate the reference commit.")] = False | ||
| 184 | + reference: Annotated[ | ||
| 185 | + bool, typer.Option("--reference", help="Evaluate the reference commit.") | ||
| 186 | + ] = False, | ||
| 178 | 187 | ) -> None: | |
| 179 | 188 | """Evaluate a Commit0 repository.""" | |
| 180 | - is_valid(repo_split, SPLIT) | ||
| 181 | - | ||
| 189 | + if not branch and not reference: | ||
| 190 | + raise typer.BadParameter( | ||
| 191 | + f"Invalid {highlight('BRANCH', Colors.RED)}. Either --reference or provide a branch name", | ||
| 192 | + param_hint="BRANCH", | ||
| 193 | + ) | ||
| 182 | 194 | if reference: | |
| 183 | 195 | branch = "reference" | |
| 196 | + assert branch is not None, "branch is not specified" | ||
| 184 | 197 | ||
| 185 | - if not branch and not reference: | ||
| 186 | - raise typer.BadParameter( | ||
| 187 | - f"Invalid {highlight('BRANCH', Colors.RED)}. Either --reference or provide a branch name", | ||
| 188 | - param_hint="BRANCH", | ||
| 189 | - ) | ||
| 198 | + check_valid(repo_split, SPLIT) | ||
| 190 | 199 | ||
| 191 | 200 | typer.echo(f"Evaluating repository split: {repo_split}") | |
| 192 | 201 | typer.echo(f"Branch: {branch}") | |
@@ -214,9 +223,9 @@ def lint( | |||
| 214 | 223 | assert len(files) > 0, "No files to lint." | |
| 215 | 224 | for path in files: | |
| 216 | 225 | if not path.is_file(): | |
| 217 | - raise FileNotFoundError(f"File not found: {path}") | ||
| 226 | + raise FileNotFoundError(f"File not found: {str(path)}") | ||
| 218 | 227 | typer.echo( | |
| 219 | - f"Linting specific files: {', '.join(highlight(file, Colors.ORANGE) for file in files)}" | ||
| 228 | + f"Linting specific files: {', '.join(highlight(str(file), Colors.ORANGE) for file in files)}" | ||
| 220 | 229 | ) | |
| 221 | 230 | commit0.harness.lint.main(files) | |
| 222 | 231 | ||
@@ -236,7 +245,7 @@ def save( | |||
| 236 | 245 | github_token: str = typer.Option(None, help="GitHub token for authentication"), | |
| 237 | 246 | ) -> None: | |
| 238 | 247 | """Save a Commit0 repository to GitHub.""" | |
| 239 | - is_valid(repo_split, SPLIT) | ||
| 248 | + check_valid(repo_split, SPLIT) | ||
| 240 | 249 | ||
| 241 | 250 | typer.echo(f"Saving repository split: {repo_split}") | |
| 242 | 251 | typer.echo(f"Owner: {owner}") | |
@@ -251,3 +260,6 @@ def save( | |||
| 251 | 260 | branch, | |
| 252 | 261 | github_token, | |
| 253 | 262 | ) | |
| 263 | + | ||
| 264 | + | ||
| 265 | + __all__ = [] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | import subprocess | |
| 2 | 2 | import sys | |
| 3 | 3 | from pathlib import Path | |
| 4 | + from typing import List | ||
| 4 | 5 | ||
| 5 | 6 | ||
| 6 | 7 | config = """repos: | |
@@ -27,7 +28,7 @@ | |||
| 27 | 28 | - id: pyright""" | |
| 28 | 29 | ||
| 29 | 30 | ||
| 30 | - def main(files: list[str]) -> None: | ||
| 31 | + def main(files: List[Path]) -> None: | ||
| 31 | 32 | config_file = Path(".commit0.pre-commit-config.yaml") | |
| 32 | 33 | if not config_file.is_file(): | |
| 33 | 34 | config_file.write_text(config) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments