Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc26cf1

Browse files
author
hauntsaninja
committed
add the ability to easily run on a local project
This makes bisection easier as well
1 parent 134ea50 commit fc26cf1

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ mypy_primer, it'll check out projects as they were today and things should work!
2727
λ mypy_primer --help
2828
usage: mypy_primer [-h] [--new NEW] [--old OLD] [--repo REPO]
2929
[--custom-typeshed-repo CUSTOM_TYPESHED_REPO] [--new-typeshed NEW_TYPESHED]
30-
[--old-typeshed OLD_TYPESHED] [-k PROJECT_SELECTOR] [--expected-success]
31-
[--project-date PROJECT_DATE] [-o {full,diff,concise}] [--old-success]
32-
[--coverage] [--bisect] [--bisect-error BISECT_ERROR] [-j CONCURRENCY]
33-
[--debug] [--base-dir BASE_DIR] [--clear]
30+
[--old-typeshed OLD_TYPESHED] [-k PROJECT_SELECTOR] [-p LOCAL_PROJECT]
31+
[--expected-success] [--project-date PROJECT_DATE] [-o {full,diff,concise}]
32+
[--old-success] [--coverage] [--bisect] [--bisect-error BISECT_ERROR]
33+
[-j CONCURRENCY] [--debug] [--base-dir BASE_DIR] [--clear]
3434
3535
optional arguments:
3636
-h, --help show this help message and exit
@@ -54,6 +54,9 @@ mypy:
5454
project selection:
5555
-k PROJECT_SELECTOR, --project-selector PROJECT_SELECTOR
5656
regex to filter projects (matches against location)
57+
-p LOCAL_PROJECT, --local-project LOCAL_PROJECT
58+
run only on the given file or directory. if a single file, supports a '#
59+
flags: ...' comment, like mypy unit tests
5760
--expected-success filter to hardcoded subset of projects where some recent mypy version
5861
succeeded aka are committed to the mypy way of life. also look at: --old-
5962
success
@@ -112,6 +115,11 @@ Figure out what commit is causing a specific error in the project you care about
112115
mypy_primer -k pandas --bisect-error 'Incompatible types in assignment'
113116
```
114117

118+
Or on a local file / directory:
119+
```
120+
mypy_primer -p test.py --bisect --old v0.770
121+
```
122+
115123
Find out what the hell mypy_primer is doing:
116124
```
117125
mypy_primer --debug

mypy_primer.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,19 @@ async def source_paths(self, mypy_python: str) -> List[Path]:
371371
)
372372
return [ARGS.projects_dir / self.name / p for p in proc.stdout.splitlines()]
373373

374+
@classmethod
375+
def from_location(cls, location: str) -> Project:
376+
additional_flags = ""
377+
if Path(location).is_file():
378+
with open(location) as f:
379+
header = f.readline().strip()
380+
if header.startswith("# flags:"):
381+
additional_flags = header[len("# flags:") :]
382+
return Project(
383+
location=location,
384+
mypy_cmd=f"{{mypy}} {location} {additional_flags}",
385+
)
386+
374387

375388
@dataclass(frozen=True)
376389
class MypyResult:
@@ -474,6 +487,8 @@ def format_full(self) -> str:
474487

475488

476489
def select_projects() -> Iterator[Project]:
490+
if ARGS.local_project:
491+
return iter([Project.from_location(ARGS.local_project)])
477492
project_iter = (p for p in PROJECTS)
478493
if ARGS.project_selector:
479494
project_iter = (
@@ -648,6 +663,14 @@ def parse_options(argv: List[str]) -> argparse.Namespace:
648663
proj_group.add_argument(
649664
"-k", "--project-selector", help="regex to filter projects (matches against location)"
650665
)
666+
proj_group.add_argument(
667+
"-p",
668+
"--local-project",
669+
help=(
670+
"run only on the given file or directory. if a single file, supports a "
671+
"'# flags: ...' comment, like mypy unit tests"
672+
),
673+
)
651674
proj_group.add_argument(
652675
"--expected-success",
653676
action="store_true",

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ set -ex
22

33
isort --diff --check --quiet .
44
black --diff --check --quiet .
5-
flake8 --max-line-length 100
5+
flake8 --max-line-length 100 --ignore E203,W503
66
mypy -m mypy_primer --strict
77
python -c 'import mypy_primer'

0 commit comments

Comments
 (0)