Skip to content

Commit 8ea802d

Browse files
authored
chore(generator): centralize mypy configuration and regenerate google-cloud-datastore POC (#17408)
> [!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 remaining **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. * Removes `mypy.ini` replacements from `datastore-integration.yaml` post-processing. * Regenerates `google-cloud-datastore` using the updated generator configurations to serve as a proof of concept. > [!note] > Work on strictly handwritten libraries is outside the scope of this PR and can be found here: #17409
1 parent d3dd066 commit 8ea802d

30 files changed

Lines changed: 167 additions & 215 deletions

File tree

.librarian/generator-input/client-post-processing/datastore-integration.yaml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,42 +39,6 @@ replacements:
3939
"google-cloud-core >= 2.0.0, <3.0.0",
4040
"grpcio >= 1.59.0, < 2.0.0",
4141
count: 1
42-
- paths: [
43-
"packages/google-cloud-datastore/mypy.ini",
44-
]
45-
before: |-
46-
# Performance: reuse results from previous runs to speed up 'nox'
47-
incremental = True
48-
after: |-
49-
# Performance: reuse results from previous runs to speed up "nox"
50-
incremental = True
51-
52-
[mypy-google.cloud.datastore._app_engine_key_pb2]
53-
ignore_errors = True
54-
55-
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2410):
56-
# Remove once this generator bug is fixed
57-
[mypy-google.cloud.datastore_v1.services.datastore.async_client]
58-
ignore_errors = True
59-
60-
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2410):
61-
# Remove once this generator bug is fixed
62-
[mypy-google.cloud.datastore_v1.services.datastore.client]
63-
ignore_errors = True
64-
count: 1
65-
- paths: [
66-
"packages/google-cloud-datastore/mypy.ini",
67-
]
68-
before: |
69-
ignore_missing_imports = False
70-
71-
# TODO\(https://github.com/googleapis/gapic-generator-python/issues/2563\):
72-
# Dependencies that historically lacks py.typed markers
73-
\[mypy-google\.iam\.\*\]
74-
ignore_missing_imports = True
75-
after: |
76-
ignore_missing_imports = True
77-
count: 1
7842
- paths: [
7943
"packages/google-cloud-datastore/docs/index.rst",
8044
]

mypy.ini

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
# --- google-cloud-datastore ---
101+
[mypy-google.cloud.datastore._app_engine_key_pb2]
102+
ignore_errors = True
103+
104+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2410):
105+
# Remove once this generator bug is fixed
106+
[mypy-google.cloud.datastore_v1.services.datastore.async_client]
107+
ignore_errors = True
108+
109+
[mypy-google.cloud.datastore_v1.services.datastore.client]
110+
ignore_errors = True

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
{% block content %}
44

55
import os
6+
import pathlib
67

78
import nox # type: ignore
89

910

11+
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
12+
# Path to the centralized mypy configuration file at the repository root.
13+
MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini")
14+
15+
1016
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2450):
1117
# Add tests for Python 3.15 alpha1
1218
# https://peps.python.org/pep-0790/
@@ -44,6 +50,7 @@ def mypy(session):
4450
session.install('.')
4551
session.run(
4652
'mypy',
53+
f"--config-file={MYPY_CONFIG_FILE}",
4754
{% if api.naming.module_namespace %}
4855
'{{ api.naming.module_namespace[0] }}',
4956
{% 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
if (CURRENT_DIRECTORY / "testing").exists():
4547
LOWER_BOUND_CONSTRAINTS_FILE = (
@@ -101,6 +103,7 @@ def mypy(session):
101103
session.install(".")
102104
session.run(
103105
"mypy",
106+
f"--config-file={MYPY_CONFIG_FILE}",
104107
"-p",
105108
{% if api.naming.module_namespace %}
106109
"{{ api.naming.module_namespace[0] }}",

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
if (CURRENT_DIRECTORY / "testing").exists():
5254
LOWER_BOUND_CONSTRAINTS_FILE = (
@@ -108,6 +110,7 @@ def mypy(session):
108110
session.install(".")
109111
session.run(
110112
"mypy",
113+
f"--config-file={MYPY_CONFIG_FILE}",
111114
"-p",
112115
"google",
113116
"--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
if (CURRENT_DIRECTORY / "testing").exists():
5254
LOWER_BOUND_CONSTRAINTS_FILE = (
@@ -108,6 +110,7 @@ def mypy(session):
108110
session.install(".")
109111
session.run(
110112
"mypy",
113+
f"--config-file={MYPY_CONFIG_FILE}",
111114
"-p",
112115
"google",
113116
"--check-untyped-defs",

0 commit comments

Comments
 (0)