From f43724a5f6abeb1d183ec8dfec3cad8bf0f0b40b Mon Sep 17 00:00:00 2001 From: A5rocks Date: Mon, 27 Nov 2023 07:19:44 +0900 Subject: [PATCH 1/3] Make `mypy_primer --coverage` not error on my machine --- mypy_primer/main.py | 8 ++++++-- mypy_primer/model.py | 6 +++++- mypy_primer/projects.py | 7 +++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/mypy_primer/main.py b/mypy_primer/main.py index c45335f..7f4b446 100644 --- a/mypy_primer/main.py +++ b/mypy_primer/main.py @@ -128,7 +128,7 @@ def select_projects() -> list[Project]: if ARGS.project_date: project_iter = (replace(p, revision=ARGS.project_date) for p in project_iter) - projects = list(project_iter) + projects = [p for p in project_iter if p.only_platform is None or p.only_platform == sys.platform] if projects == []: raise ValueError("No projects selected!") @@ -302,7 +302,11 @@ async def coverage() -> None: ) projects = select_projects() - mypy_python = mypy_exe.parent / "python" + if sys.platform == "win32": + mypy_python = mypy_exe.parent / "python.exe" + else: + mypy_python = mypy_exe.parent / "python" + assert mypy_python.exists() all_paths = await asyncio.gather( diff --git a/mypy_primer/model.py b/mypy_primer/model.py index dd42864..42fcca0 100644 --- a/mypy_primer/model.py +++ b/mypy_primer/model.py @@ -39,6 +39,8 @@ class Project: name_override: str | None = None + only_platform: str | None = None + # custom __repr__ that omits defaults. def __repr__(self) -> str: result = f"Project(location={self.location!r}, mypy_cmd={self.mypy_cmd!r}" @@ -58,6 +60,8 @@ def __repr__(self) -> str: result += f", min_python_version={self.min_python_version!r}" if self.name_override: result += f", name_override={self.name_override!r}" + if self.only_platform: + result += f", only_platform={self.only_platform!r}" result += ")" return result @@ -265,7 +269,7 @@ async def mypy_source_paths(self, mypy_python: str) -> list[Path]: """ # the extra shell stuff here makes sure we expand globs in mypy_cmd proc, _ = await run( - f"{mypy_python} -c {shlex.quote(program)} {mypy_cmd}", + f"{mypy_python} -c {quote_path(program)} {mypy_cmd}", output=True, cwd=ctx.get().projects_dir / self.name, shell=True, diff --git a/mypy_primer/projects.py b/mypy_primer/projects.py index cc00323..225b261 100644 --- a/mypy_primer/projects.py +++ b/mypy_primer/projects.py @@ -112,6 +112,7 @@ def get_projects() -> list[Project]: mypy_cmd="{mypy} aiohttp", pip_cmd="AIOHTTP_NO_EXTENSIONS=1 {pip} install -e . pytest", expected_mypy_success=True, + only_platform="linux", ), Project( location="https://github.com/python-attrs/attrs", @@ -144,6 +145,7 @@ def get_projects() -> list[Project]: mypy_cmd="{mypy} boostedblob", pip_cmd="{pip} install aiohttp uvloop pycryptodome", expected_mypy_success=True, + only_platform="linux", ), Project( location="https://github.com/quora/asynq", @@ -227,6 +229,7 @@ def get_projects() -> list[Project]: " types-pytz types-PyYAML types-requests" ), expected_mypy_success=True, + only_platform="linux", ), Project( location="https://github.com/PrefectHQ/prefect", @@ -338,6 +341,7 @@ def get_projects() -> list[Project]: mypy_cmd="{mypy} src/schemathesis", pip_cmd="{pip} install attrs types-requests types-PyYAML", expected_mypy_success=True, + only_platform="linux", ), Project( location="https://github.com/graphql-python/graphql-core", @@ -588,6 +592,7 @@ def get_projects() -> list[Project]: mypy_cmd="{mypy} .", pip_cmd="{pip} install types-Pillow types-cachetools types-requests attrs", expected_mypy_success=True, + only_platform="linux", ), Project( location="https://github.com/sco1/pylox", @@ -890,4 +895,6 @@ def get_projects() -> list[Project]: ), ] assert len(projects) == len({p.name for p in projects}) + for p in projects: + assert p.only_platform is None or p.only_platform == "linux" return projects From cb6509d301c42305c7d3639594bac253f794dc63 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Mon, 27 Nov 2023 07:21:21 +0900 Subject: [PATCH 2/3] Run black --- mypy_primer/main.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mypy_primer/main.py b/mypy_primer/main.py index 7f4b446..6f0d5ed 100644 --- a/mypy_primer/main.py +++ b/mypy_primer/main.py @@ -128,7 +128,9 @@ def select_projects() -> list[Project]: if ARGS.project_date: project_iter = (replace(p, revision=ARGS.project_date) for p in project_iter) - projects = [p for p in project_iter if p.only_platform is None or p.only_platform == sys.platform] + projects = [ + p for p in project_iter if p.only_platform is None or p.only_platform == sys.platform + ] if projects == []: raise ValueError("No projects selected!") @@ -157,17 +159,15 @@ async def validate_expected_success() -> None: assert ARGS.type_checker == "mypy" - recent_mypy_exes = await asyncio.gather( - *[ - setup_mypy( - ARGS.base_dir / ("mypy_" + recent_mypy), - recent_mypy, - repo=ARGS.repo, - mypyc_compile_level=ARGS.mypyc_compile_level, - ) - for recent_mypy in RECENT_MYPYS - ] - ) + recent_mypy_exes = await asyncio.gather(*[ + setup_mypy( + ARGS.base_dir / ("mypy_" + recent_mypy), + recent_mypy, + repo=ARGS.repo, + mypyc_compile_level=ARGS.mypyc_compile_level, + ) + for recent_mypy in RECENT_MYPYS + ]) async def inner(project: Project) -> str | None: await project.setup() @@ -309,9 +309,9 @@ async def coverage() -> None: assert mypy_python.exists() - all_paths = await asyncio.gather( - *[project.mypy_source_paths(str(mypy_python)) for project in projects] - ) + all_paths = await asyncio.gather(*[ + project.mypy_source_paths(str(mypy_python)) for project in projects + ]) project_to_paths: dict[str, int] = {} project_to_lines: dict[str, int] = {} From 84af1c9eb1d5c6c1164a43f4b569f4d56c1dc59e Mon Sep 17 00:00:00 2001 From: Shantanu Jain Date: Sun, 26 Nov 2023 17:17:44 -0800 Subject: [PATCH 3/3] changes --- mypy_primer/main.py | 4 +++- mypy_primer/model.py | 6 +++--- mypy_primer/projects.py | 14 ++++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/mypy_primer/main.py b/mypy_primer/main.py index 6f0d5ed..5820fb3 100644 --- a/mypy_primer/main.py +++ b/mypy_primer/main.py @@ -129,7 +129,9 @@ def select_projects() -> list[Project]: project_iter = (replace(p, revision=ARGS.project_date) for p in project_iter) projects = [ - p for p in project_iter if p.only_platform is None or p.only_platform == sys.platform + p + for p in project_iter + if p.supported_platforms is None or sys.platform in p.supported_platforms ] if projects == []: raise ValueError("No projects selected!") diff --git a/mypy_primer/model.py b/mypy_primer/model.py index 42fcca0..f03700d 100644 --- a/mypy_primer/model.py +++ b/mypy_primer/model.py @@ -39,7 +39,7 @@ class Project: name_override: str | None = None - only_platform: str | None = None + supported_platforms: list[str] | None = None # custom __repr__ that omits defaults. def __repr__(self) -> str: @@ -60,8 +60,8 @@ def __repr__(self) -> str: result += f", min_python_version={self.min_python_version!r}" if self.name_override: result += f", name_override={self.name_override!r}" - if self.only_platform: - result += f", only_platform={self.only_platform!r}" + if self.supported_platforms: + result += f", supported_platforms={self.supported_platforms!r}" result += ")" return result diff --git a/mypy_primer/projects.py b/mypy_primer/projects.py index 225b261..c036620 100644 --- a/mypy_primer/projects.py +++ b/mypy_primer/projects.py @@ -112,7 +112,7 @@ def get_projects() -> list[Project]: mypy_cmd="{mypy} aiohttp", pip_cmd="AIOHTTP_NO_EXTENSIONS=1 {pip} install -e . pytest", expected_mypy_success=True, - only_platform="linux", + supported_platforms=["linux", "darwin"], ), Project( location="https://github.com/python-attrs/attrs", @@ -145,7 +145,7 @@ def get_projects() -> list[Project]: mypy_cmd="{mypy} boostedblob", pip_cmd="{pip} install aiohttp uvloop pycryptodome", expected_mypy_success=True, - only_platform="linux", + supported_platforms=["linux", "darwin"], ), Project( location="https://github.com/quora/asynq", @@ -229,7 +229,7 @@ def get_projects() -> list[Project]: " types-pytz types-PyYAML types-requests" ), expected_mypy_success=True, - only_platform="linux", + supported_platforms=["linux", "darwin"], ), Project( location="https://github.com/PrefectHQ/prefect", @@ -341,7 +341,7 @@ def get_projects() -> list[Project]: mypy_cmd="{mypy} src/schemathesis", pip_cmd="{pip} install attrs types-requests types-PyYAML", expected_mypy_success=True, - only_platform="linux", + supported_platforms=["linux", "darwin"], ), Project( location="https://github.com/graphql-python/graphql-core", @@ -592,7 +592,7 @@ def get_projects() -> list[Project]: mypy_cmd="{mypy} .", pip_cmd="{pip} install types-Pillow types-cachetools types-requests attrs", expected_mypy_success=True, - only_platform="linux", + supported_platforms=["linux", "darwin"], ), Project( location="https://github.com/sco1/pylox", @@ -896,5 +896,7 @@ def get_projects() -> list[Project]: ] assert len(projects) == len({p.name for p in projects}) for p in projects: - assert p.only_platform is None or p.only_platform == "linux" + assert p.supported_platforms is None or all( + p in ("linux", "darwin") for p in p.supported_platforms + ) return projects