Skip to content

Commit 79ef976

Browse files
committed
feat(mypy): centralize mypy.ini and update templates
> [!note] > This is step one of a multi-step process. The work done here is outlined below. Additional steps (to be completed in other PRs) include: > * generate the **generated packages** > * generate and/or post process **hybrid packages** This work: * Adds a centralized `mypy.ini` file at the root of the repository. * Updates GAPIC generator templates to omit local `mypy.ini` and dynamically resolve the root config via a `MYPY_CONFIG_FILE` constant. > [!note] > Work on strictly handwritten libraries is outside the scope of this PR and can be found here: #17409
1 parent a0da993 commit 79ef976

22 files changed

Lines changed: 134 additions & 139 deletions

File tree

mypy.ini

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
[mypy]
2+
namespace_packages = True
3+
ignore_missing_imports = False
4+
5+
# Helps mypy navigate the "google" namespace more reliably in 3.10+
6+
explicit_package_bases = True
7+
8+
# Performance: reuse results from previous runs to speed up "nox"
9+
incremental = True
10+
11+
exclude = (?x)(
12+
(^|/)third_party/
13+
| (^|/)tests/unit/resources/
14+
| (^|/)tests/unit/gapic/
15+
)
16+
17+
18+
# ==============================================================================
19+
# GLOBAL THIRD-PARTY & SHARED LIBRARY IGNORES
20+
# ==============================================================================
21+
22+
[mypy-anywidget]
23+
ignore_missing_imports = True
24+
25+
[mypy-cloudpickle.*]
26+
ignore_missing_imports = True
27+
28+
[mypy-flask]
29+
ignore_missing_imports = True
30+
31+
[mypy-google.auth.*]
32+
ignore_missing_imports = True
33+
34+
[mypy-google.cloud.bigtable]
35+
ignore_missing_imports = True
36+
37+
[mypy-google.cloud.pubsub]
38+
ignore_missing_imports = True
39+
40+
[mypy-google.colab]
41+
ignore_missing_imports = True
42+
43+
[mypy-google.iam.*]
44+
ignore_missing_imports = True
45+
46+
[mypy-google.longrunning.*]
47+
ignore_missing_imports = True
48+
49+
[mypy-google.oauth2.*]
50+
ignore_missing_imports = True
51+
52+
[mypy-google.protobuf.*]
53+
ignore_missing_imports = True
54+
55+
[mypy-google.rpc.*]
56+
ignore_missing_imports = True
57+
58+
[mypy-google.type.*]
59+
ignore_missing_imports = True
60+
61+
[mypy-grpc.*]
62+
ignore_missing_imports = True
63+
64+
[mypy-ibis.*]
65+
ignore_missing_imports = True
66+
67+
[mypy-ipywidgets]
68+
ignore_missing_imports = True
69+
70+
[mypy-proto.*]
71+
ignore_missing_imports = True
72+
73+
[mypy-pyarrow.*]
74+
ignore_missing_imports = True
75+
76+
[mypy-pydata_google_auth]
77+
ignore_missing_imports = True
78+
79+
[mypy-pytest]
80+
ignore_missing_imports = True
81+
82+
[mypy-pytz]
83+
ignore_missing_imports = True
84+
85+
86+
# ==============================================================================
87+
# PACKAGE-SPECIFIC OVERRIDES & EXCEPTIONS
88+
# ==============================================================================
89+
90+
# --- google-cloud-bigtable ---
91+
[mypy-google.cloud.bigtable.*]
92+
ignore_errors = True
93+
94+
[mypy-google.cloud.bigtable.data.*]
95+
check_untyped_defs = True
96+
warn_unreachable = True
97+
disallow_any_generics = True
98+
ignore_errors = False
99+
100+

packages/gapic-generator/gapic/ads-templates/mypy.ini.j2

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/gapic-generator/gapic/ads-templates/noxfile.py.j2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
{% block content %}
44

55
import os
6+
import pathlib
67

78
import nox # type: ignore
89

10+
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
11+
MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini")
12+
913

1014
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2450):
1115
# Add tests for Python 3.15 alpha1
@@ -44,6 +48,7 @@ def mypy(session):
4448
session.install('.')
4549
session.run(
4650
'mypy',
51+
f"--config-file={MYPY_CONFIG_FILE}",
4752
{% if api.naming.module_namespace %}
4853
'{{ api.naming.module_namespace[0] }}',
4954
{% else %}

packages/gapic-generator/gapic/templates/mypy.ini.j2

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/gapic-generator/gapic/templates/noxfile.py.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ DEFAULT_PYTHON_VERSION = "3.14"
4040
PREVIEW_PYTHON_VERSION = "3.14"
4141

4242
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
43+
# Path to the centralized mypy configuration file at the repository root.
44+
MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini")
4345

4446
LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
4547
PACKAGE_NAME = "{{ api.naming.warehouse_package_name }}"
@@ -96,6 +98,7 @@ def mypy(session):
9698
session.install(".")
9799
session.run(
98100
"mypy",
101+
f"--config-file={MYPY_CONFIG_FILE}",
99102
"-p",
100103
{% if api.naming.module_namespace %}
101104
"{{ api.naming.module_namespace[0] }}",

packages/gapic-generator/rules_python_gapic/test/integration_test.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ def _overwrite_golden_impl(ctx):
114114
golden_update_script_content = """
115115
cd ${{BUILD_WORKSPACE_DIRECTORY}}
116116
# Filename pattern-based removal is needed to preserve the BUILD.bazel file.
117-
find tests/integration/goldens/{api_name}/ -name \\*.py-type f -delete
117+
find tests/integration/goldens/{api_name}/ -name \\*.py -type f -delete
118118
find tests/integration/goldens/{api_name}/ -name \\*.json -type f -delete
119+
find tests/integration/goldens/{api_name}/ -name \\*.ini -type f -delete
119120
unzip -ao {goldens_output_zip} -d tests/integration/goldens/{api_name}
120121
""".format(
121122
goldens_output_zip = goldens_output_zip.path,

packages/gapic-generator/tests/integration/goldens/asset/mypy.ini

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/gapic-generator/tests/integration/goldens/asset/noxfile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
PREVIEW_PYTHON_VERSION = "3.14"
4848

4949
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
50+
# Path to the centralized mypy configuration file at the repository root.
51+
MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini")
5052

5153
LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
5254
PACKAGE_NAME = "google-cloud-asset"
@@ -103,6 +105,7 @@ def mypy(session):
103105
session.install(".")
104106
session.run(
105107
"mypy",
108+
f"--config-file={MYPY_CONFIG_FILE}",
106109
"-p",
107110
"google",
108111
"--check-untyped-defs",

packages/gapic-generator/tests/integration/goldens/credentials/mypy.ini

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
PREVIEW_PYTHON_VERSION = "3.14"
4848

4949
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
50+
# Path to the centralized mypy configuration file at the repository root.
51+
MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini")
5052

5153
LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
5254
PACKAGE_NAME = "google-iam-credentials"
@@ -103,6 +105,7 @@ def mypy(session):
103105
session.install(".")
104106
session.run(
105107
"mypy",
108+
f"--config-file={MYPY_CONFIG_FILE}",
106109
"-p",
107110
"google",
108111
"--check-untyped-defs",

0 commit comments

Comments
 (0)