Skip to content

Commit 3488a75

Browse files
committed
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 9cb3093 commit 3488a75

30 files changed

Lines changed: 112 additions & 253 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: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,77 +9,94 @@ explicit_package_bases = True
99
incremental = True
1010

1111
exclude = (?x)(
12-
^third_party/
13-
| tests/unit/resources/
14-
| tests/unit/gapic/
12+
(^|/)third_party/
13+
| (^|/)tests/unit/resources/
14+
| (^|/)tests/unit/gapic/
1515
)
1616

17-
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2563):
18-
# Dependencies that historically lacks py.typed markers
19-
[mypy-google.iam.*]
20-
ignore_missing_imports = True
21-
22-
[mypy-google.type.*]
23-
ignore_missing_imports = True
24-
2517

2618
# ==============================================================================
27-
# PACKAGE-SPECIFIC OVERRIDES
19+
# GLOBAL THIRD-PARTY & SHARED LIBRARY IGNORES
2820
# ==============================================================================
2921

30-
# --- google-cloud-core ---
31-
[mypy-google.protobuf.*]
22+
[mypy-anywidget]
3223
ignore_missing_imports = True
3324

34-
# --- bigframes ---
3525
[mypy-cloudpickle.*]
3626
ignore_missing_imports = True
27+
3728
[mypy-flask]
3829
ignore_missing_imports = True
39-
[mypy-pydata_google_auth]
40-
ignore_missing_imports = True
41-
[mypy-google.colab]
30+
31+
[mypy-google.auth.*]
4232
ignore_missing_imports = True
43-
[mypy-pytz]
33+
34+
[mypy-google.cloud.bigtable]
4435
ignore_missing_imports = True
45-
[mypy-pyarrow.*]
36+
37+
[mypy-google.cloud.pubsub]
4638
ignore_missing_imports = True
47-
[mypy-ibis.*]
39+
40+
[mypy-google.colab]
4841
ignore_missing_imports = True
49-
[mypy-ipywidgets]
42+
43+
[mypy-google.iam.*]
5044
ignore_missing_imports = True
51-
[mypy-google.cloud.pubsub]
45+
46+
[mypy-google.longrunning.*]
5247
ignore_missing_imports = True
53-
[mypy-google.cloud.bigtable]
48+
49+
[mypy-google.oauth2.*]
5450
ignore_missing_imports = True
55-
[mypy-anywidget]
51+
52+
[mypy-google.protobuf.*]
5653
ignore_missing_imports = True
5754

58-
# --- google-cloud-bigtable ---
59-
[mypy-google.cloud.bigtable.*]
60-
check_untyped_defs = True
61-
warn_unreachable = True
62-
disallow_any_generics = True
63-
ignore_errors = True
55+
[mypy-google.rpc.*]
56+
ignore_missing_imports = True
6457

65-
[mypy-google.cloud.bigtable.data.*]
66-
ignore_errors = False
58+
[mypy-google.type.*]
59+
ignore_missing_imports = True
6760

6861
[mypy-grpc.*]
6962
ignore_missing_imports = True
70-
[mypy-google.auth.*]
63+
64+
[mypy-ibis.*]
7165
ignore_missing_imports = True
72-
[mypy-google.longrunning.*]
66+
67+
[mypy-ipywidgets]
7368
ignore_missing_imports = True
74-
[mypy-google.oauth2.*]
69+
70+
[mypy-proto.*]
7571
ignore_missing_imports = True
76-
[mypy-google.rpc.*]
72+
73+
[mypy-pyarrow.*]
7774
ignore_missing_imports = True
78-
[mypy-proto.*]
75+
76+
[mypy-pydata_google_auth]
7977
ignore_missing_imports = True
78+
8079
[mypy-pytest]
8180
ignore_missing_imports = True
8281

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+
83100
# --- google-cloud-datastore ---
84101
[mypy-google.cloud.datastore._app_engine_key_pb2]
85102
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)