From 74466fb69d1f397c9c8f4f8f501f81132158a662 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Sat, 12 Jun 2021 11:14:39 -0400 Subject: [PATCH 1/5] style: use bin extra --- noxfile.py | 4 ++-- setup.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/noxfile.py b/noxfile.py index 4d8493bb..d10c7212 100644 --- a/noxfile.py +++ b/noxfile.py @@ -48,7 +48,7 @@ def update_pins(session): """ Update the python and docker pins version inplace. """ - session.install("-e", ".[dev]") + session.install("-e", ".[bin]") session.run("python", "bin/update_pythons.py", "--force") session.run("python", "bin/update_docker.py") @@ -58,7 +58,7 @@ def update_proj(session): """ Update the README inplace. """ - session.install("-e", ".[dev]") + session.install("-e", ".[bin]") session.run("./bin/projects.py", "docs/data/projects.yml", "--readme=README.md") diff --git a/setup.py b/setup.py index 87168e76..690b54eb 100644 --- a/setup.py +++ b/setup.py @@ -11,21 +11,24 @@ extras = { "pytest>=4", "pytest-timeout", ], - "dev": [ + "bin": [ "click", "ghapi", - "mypy>=0.800", - "packaging>=20.8", "pip-tools", "pygithub", "pyyaml", "requests", "rich>=9.6", - "typing-extensions", + "packaging>=20.8", ], } +extras["dev"] = [ + "mypy>=0.800", + *extras["test"], + *extras["bin"], +] + extras["all"] = sum(extras.values(), []) -extras["dev"] += extras["test"] setup(extras_require=extras) From 506f2dcb9c205115b19e59c4e1a548f4da9044c7 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Sat, 12 Jun 2021 11:45:06 -0400 Subject: [PATCH 2/5] tests: simpler install --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 013e3879..cd50c3ec 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,7 +37,7 @@ jobs: - name: Install dependencies run: | - python -m pip install -e ".[dev]" + python -m pip install ".[test]" - name: Sample build if: "contains(github.event.pull_request.labels.*.name, 'CI: Sample build')" @@ -70,7 +70,7 @@ jobs: - uses: actions/setup-python@v2 - name: Install dependencies run: | - python -m pip install -r requirements-dev.txt + python -m pip install ".[test]" - name: Set up QEMU id: qemu From 3311a36e65a2aaa8590905a048b6445921cfbe9f Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Sat, 12 Jun 2021 11:40:33 -0400 Subject: [PATCH 3/5] chore: bump style, more in pyproject.toml --- .pre-commit-config.yaml | 25 ++++++++++++----- pyproject.toml | 60 +++++++++++++++++++++++++++++++++++++++++ setup.cfg | 54 ------------------------------------- setup.py | 4 +-- 4 files changed, 80 insertions(+), 63 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e45ef7d..2320cfd0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/asottile/pyupgrade - rev: v2.19.1 + rev: v2.19.4 hooks: - id: pyupgrade name: PyUpgrade 3.6+ @@ -31,7 +31,7 @@ repos: - id: isort - repo: https://github.com/psf/black - rev: 21.5b2 + rev: 21.6b0 hooks: - id: black @@ -42,17 +42,28 @@ repos: stages: [manual] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.812 + rev: v0.902 hooks: - id: mypy exclude: ^(bin/|cibuildwheel/resources/).*py$ - additional_dependencies: [packaging] - args: ["--python-version=3.6", "--ignore-missing-imports", "--scripts-are-modules"] + args: ["--python-version=3.6", "--scripts-are-modules"] + additional_dependencies: + - packaging + - types-jinja2 + - types-certifi + - types-toml - id: mypy name: mypy 3.7+ on bin/ files: ^bin/.*py$ - additional_dependencies: [packaging] - args: ["--python-version=3.7", "--ignore-missing-imports", "--scripts-are-modules"] + args: ["--python-version=3.7", "--scripts-are-modules"] + additional_dependencies: + - packaging + - rich + - types-jinja2 + - types-pyyaml + - types-click + - types-requests + - types-toml - repo: https://github.com/PyCQA/flake8 rev: 3.9.2 diff --git a/pyproject.toml b/pyproject.toml index 386fb3e1..f51ad0ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,66 @@ requires = [ build-backend = "setuptools.build_meta" + [tool.black] line-length = 100 target-version = ['py36', 'py37', 'py38', 'py39'] + + +[tool.isort] +profile = "black" +multi_line_output = 3 + + +[tool.pytest.ini_options] +junit_family = "xunit2" +testpaths = [ + "test", + "unit_test", +] + + +[tool.mypy] +minversion = 6.0 +python_version = 3.7 +files = [ + "cibuildwheel/*.py", + "test/**/*.py", + "unit_test/**/*.py", + "bin/*.py" +] +warn_unused_configs = true +warn_redundant_casts = true + +# Don't require typed functions for tests +[[tool.mypy.overrides]] +module = ["test", "unit_test"] +check_untyped_defs = true + +[[tool.mypy.overrides]] +module = "cibuildwheel" +disallow_any_generics = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_defs = true +disallow_incomplete_defs = true +check_untyped_defs = true +disallow_untyped_decorators = true +no_implicit_optional = true +warn_unused_ignores = true +warn_return_any = true +no_implicit_reexport = true +strict_equality = true + +[[tool.mypy.overrides]] +module = [ + "setuptools", + "pytest", # ignored in pre-commit to speed up check + "bashlex", + "toml.encoder", # missing from stub package + "bracex", + "importlib_resources", + "nox", + "github", +] +ignore_missing_imports = true diff --git a/setup.cfg b/setup.cfg index 4c6cecf8..9e3fc215 100644 --- a/setup.cfg +++ b/setup.cfg @@ -65,57 +65,3 @@ exclude = env??/, .venv/, site/ - -[tool:pytest] -junit_family = xunit2 -testpaths = - test - unit_test - -[mypy] -python_version = 3.7 -files = cibuildwheel/*.py,test/**/*.py,unit_test/**/*.py,bin/*.py -warn_unused_configs = True -warn_redundant_casts = True - -[mypy-test.*,mypy-unit_test.*] -check_untyped_defs = True - -[mypy-cibuildwheel.*] -disallow_any_generics = True -disallow_subclassing_any = True -disallow_untyped_calls = True -disallow_untyped_defs = True -disallow_incomplete_defs = True -check_untyped_defs = True -disallow_untyped_decorators = True -no_implicit_optional = True -warn_unused_ignores = True -warn_return_any = True -no_implicit_reexport = True -strict_equality = True - -[mypy-setuptools.*] -ignore_missing_imports = True - -# Ignored for pre-commit to speed up check -# Not ignored if manually running and pytest installed -[mypy-pytest.*] -ignore_missing_imports = True - -[mypy-bashlex.*] -ignore_missing_imports = True - -# Has type stubs, but no pyproject.toml or .pyi files in the wheel. -[mypy-toml.*] -ignore_missing_imports = True - -[mypy-bracex.*] -ignore_missing_imports = True - -[mypy-importlib_resources.*] -ignore_missing_imports = True - -[tool:isort] -profile = black -multi_line_output = 3 diff --git a/setup.py b/setup.py index 690b54eb..4ed6ac54 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ extras = { ], "test": [ "jinja2", - "pytest>=4", + "pytest>=6", "pytest-timeout", ], "bin": [ @@ -24,7 +24,7 @@ extras = { } extras["dev"] = [ - "mypy>=0.800", + "mypy>=0.901", *extras["test"], *extras["bin"], ] From 0aac8c2221db66ab320af2da9bb1639425912dce Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Sat, 12 Jun 2021 14:02:06 -0400 Subject: [PATCH 4/5] chore: stricter mypy checking --- bin/projects.py | 2 +- bin/update_pythons.py | 6 ++--- pyproject.toml | 36 +++++++++++++----------------- test/test_projects/__init__.py | 6 +++-- unit_test/build_ids_test.py | 4 ++-- unit_test/docker_container_test.py | 1 + 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/bin/projects.py b/bin/projects.py index 21461e8d..ad7f27a5 100755 --- a/bin/projects.py +++ b/bin/projects.py @@ -62,7 +62,7 @@ class Project: print(f"Broken: {self.stars_repo}") raise - self.num_stars = repo.stargazers_count + self.num_stars: int = repo.stargazers_count self.pushed_at = repo.pushed_at if not self.notes: notes = repo.description diff --git a/bin/update_pythons.py b/bin/update_pythons.py index c21b0823..4eacb195 100755 --- a/bin/update_pythons.py +++ b/bin/update_pythons.py @@ -122,7 +122,7 @@ class PyPyVersions: self.arch = arch_str def get_arch_file(self, release: dict[str, Any]) -> str: - urls = [ + urls: list[str] = [ rf["download_url"] for rf in release["files"] if "" in rf["platform"] == f"win{self.arch}" @@ -131,7 +131,7 @@ class PyPyVersions: def update_version_windows(self, spec: Specifier) -> ConfigWinCP: releases = [r for r in self.releases if spec.contains(r["python_version"])] - releases = sorted(releases, key=lambda r: r["pypy_version"]) + releases = sorted(releases, key=lambda r: r["pypy_version"]) # type: ignore releases = [r for r in releases if self.get_arch_file(r)] if not releases: @@ -156,7 +156,7 @@ class PyPyVersions: raise RuntimeError("Other archs not supported yet on macOS") releases = [r for r in self.releases if spec.contains(r["python_version"])] - releases = sorted(releases, key=lambda r: r["pypy_version"]) + releases = sorted(releases, key=lambda r: r["pypy_version"]) # type: ignore if not releases: raise RuntimeError(f"PyPy macOS {self.arch} not found for {spec}!") diff --git a/pyproject.toml b/pyproject.toml index f51ad0ee..91d17547 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ multi_line_output = 3 [tool.pytest.ini_options] +minversion = 6.0 junit_family = "xunit2" testpaths = [ "test", @@ -26,7 +27,6 @@ testpaths = [ [tool.mypy] -minversion = 6.0 python_version = 3.7 files = [ "cibuildwheel/*.py", @@ -36,33 +36,29 @@ files = [ ] warn_unused_configs = true warn_redundant_casts = true - -# Don't require typed functions for tests -[[tool.mypy.overrides]] -module = ["test", "unit_test"] -check_untyped_defs = true - -[[tool.mypy.overrides]] -module = "cibuildwheel" -disallow_any_generics = true -disallow_subclassing_any = true -disallow_untyped_calls = true -disallow_untyped_defs = true -disallow_incomplete_defs = true -check_untyped_defs = true -disallow_untyped_decorators = true -no_implicit_optional = true -warn_unused_ignores = true -warn_return_any = true no_implicit_reexport = true strict_equality = true +warn_unused_ignores = true +check_untyped_defs = true + +disallow_subclassing_any = true +disallow_any_generics = true +warn_return_any = true +no_implicit_optional = true + +[[tool.mypy.overrides]] +module = "cibuildwheel.*" +disallow_untyped_defs = true +disallow_untyped_calls = true +disallow_incomplete_defs = true +disallow_untyped_decorators = true [[tool.mypy.overrides]] module = [ "setuptools", "pytest", # ignored in pre-commit to speed up check "bashlex", - "toml.encoder", # missing from stub package + "toml.encoder", # encoder missing from stub package "bracex", "importlib_resources", "nox", diff --git a/test/test_projects/__init__.py b/test/test_projects/__init__.py index 48d7dbec..d6bed818 100644 --- a/test/test_projects/__init__.py +++ b/test/test_projects/__init__.py @@ -1,2 +1,4 @@ -from .base import TestProject # noqa -from .c import new_c_project # noqa +from .base import TestProject +from .c import new_c_project + +__all__ = ("TestProject", "new_c_project") diff --git a/unit_test/build_ids_test.py b/unit_test/build_ids_test.py index b0d4188a..6aa100e3 100644 --- a/unit_test/build_ids_test.py +++ b/unit_test/build_ids_test.py @@ -11,7 +11,7 @@ def test_compare_configs(): dict_txt = toml.loads(txt) - new_txt = toml.dumps(dict_txt, encoder=InlineArrayDictEncoder()) + new_txt = toml.dumps(dict_txt, encoder=InlineArrayDictEncoder()) # type: ignore print(new_txt) assert new_txt == txt @@ -35,6 +35,6 @@ python_configurations = [ ] """ - output = toml.dumps(example, encoder=InlineArrayDictEncoder()) + output = toml.dumps(example, encoder=InlineArrayDictEncoder()) # type: ignore print(output) assert output == result diff --git a/unit_test/docker_container_test.py b/unit_test/docker_container_test.py index 79046e72..2b49eda0 100644 --- a/unit_test/docker_container_test.py +++ b/unit_test/docker_container_test.py @@ -63,6 +63,7 @@ def test_container_removed(): stdout=subprocess.PIPE, universal_newlines=True, ).stdout + assert container.name is not None assert container.name in docker_containers_listing old_container_name = container.name From 07fd2fc7b1f8aab05b929b3937d33c8e5fd260e4 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 17 Jun 2021 17:18:57 -0400 Subject: [PATCH 5/5] chore: mypy extra and mypy types --- setup.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4ed6ac54..3074dc9c 100644 --- a/setup.py +++ b/setup.py @@ -21,10 +21,21 @@ extras = { "rich>=9.6", "packaging>=20.8", ], + "mypy": [ + "mypy>=0.901", + "types-jinja2", + "types-certifi", + "types-toml", + "types-jinja2", + "types-pyyaml", + "types-click", + "types-requests", + "types-toml", + ], } extras["dev"] = [ - "mypy>=0.901", + *extras["mypy"], *extras["test"], *extras["bin"], ]