Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
[mypy]
namespace_packages = True
ignore_missing_imports = False

# Helps mypy navigate the "google" namespace more reliably in 3.10+
explicit_package_bases = True

# Performance: reuse results from previous runs to speed up "nox"
incremental = True

exclude = (?x)(
(^|/)third_party/
| (^|/)tests/unit/resources/
| (^|/)tests/unit/gapic/
)


# ==============================================================================
# GLOBAL THIRD-PARTY & SHARED LIBRARY IGNORES
# ==============================================================================

[mypy-anywidget]
ignore_missing_imports = True

[mypy-cloudpickle.*]
ignore_missing_imports = True

[mypy-flask]
ignore_missing_imports = True

[mypy-google.auth.*]
ignore_missing_imports = True

[mypy-google.cloud.bigtable]
ignore_missing_imports = True

[mypy-google.cloud.pubsub]
ignore_missing_imports = True

[mypy-google.colab]
ignore_missing_imports = True

[mypy-google.iam.*]
ignore_missing_imports = True

[mypy-google.longrunning.*]
ignore_missing_imports = True

[mypy-google.oauth2.*]
ignore_missing_imports = True

[mypy-google.protobuf.*]
ignore_missing_imports = True

[mypy-google.rpc.*]
ignore_missing_imports = True

[mypy-google.type.*]
ignore_missing_imports = True

[mypy-grpc.*]
ignore_missing_imports = True

[mypy-ibis.*]
ignore_missing_imports = True

[mypy-ipywidgets]
ignore_missing_imports = True

[mypy-proto.*]
ignore_missing_imports = True

[mypy-pyarrow.*]
ignore_missing_imports = True

[mypy-pydata_google_auth]
ignore_missing_imports = True

[mypy-pytest]
ignore_missing_imports = True

[mypy-pytz]
ignore_missing_imports = True


# ==============================================================================
# PACKAGE-SPECIFIC OVERRIDES & EXCEPTIONS
# ==============================================================================

# --- google-cloud-bigtable ---
[mypy-google.cloud.bigtable.*]
ignore_errors = True

[mypy-google.cloud.bigtable.data.*]
check_untyped_defs = True
warn_unreachable = True
disallow_any_generics = True
ignore_errors = False


3 changes: 0 additions & 3 deletions packages/gapic-generator/gapic/ads-templates/mypy.ini.j2

This file was deleted.

5 changes: 5 additions & 0 deletions packages/gapic-generator/gapic/ads-templates/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
{% block content %}

import os
import pathlib

import nox # type: ignore

CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
MYPY_CONFIG_FILE = str(CURRENT_DIRECTORY.parent.parent / "mypy.ini")
Comment on lines +10 to +11

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The hardcoded relative path CURRENT_DIRECTORY.parent.parent / 'mypy.ini' assumes that the generated package is always located exactly two levels down from the repository root. While this is true for standard packages in the monorepo, it is not true for integration test goldens (which are located five levels down at packages/gapic-generator/tests/integration/goldens/<package>). As a result, running nox -s mypy inside the golden directories will fail to find the centralized mypy.ini file.

To make this robust across all directory structures (including local development and integration tests), search upwards through parent directories to dynamically locate the mypy.ini file, falling back to the default relative path if not found.

CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
# Search upwards to support running nox from both monorepo packages and integration test goldens.
MYPY_CONFIG_FILE = next(
    (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()),
    str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"),
)
References
  1. Do not suggest manual code modifications, optimizations, or style fixes for generated files, as any changes should be implemented in the generator or templates to prevent them from being overwritten.



# TODO(https://github.com/googleapis/gapic-generator-python/issues/2450):
# Add tests for Python 3.15 alpha1
Expand Down Expand Up @@ -44,6 +48,7 @@ def mypy(session):
session.install('.')
session.run(
'mypy',
f"--config-file={MYPY_CONFIG_FILE}",
{% if api.naming.module_namespace %}
'{{ api.naming.module_namespace[0] }}',
{% else %}
Expand Down
15 changes: 0 additions & 15 deletions packages/gapic-generator/gapic/templates/mypy.ini.j2

This file was deleted.

3 changes: 3 additions & 0 deletions packages/gapic-generator/gapic/templates/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ DEFAULT_PYTHON_VERSION = "3.14"
PREVIEW_PYTHON_VERSION = "3.14"

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The hardcoded relative path CURRENT_DIRECTORY.parent.parent / 'mypy.ini' assumes that the generated package is always located exactly two levels down from the repository root. While this is true for standard packages in the monorepo, it is not true for integration test goldens (which are located five levels down at packages/gapic-generator/tests/integration/goldens/<package>). As a result, running nox -s mypy inside the golden directories will fail to find the centralized mypy.ini file.

To make this robust across all directory structures (including local development and integration tests), search upwards through parent directories to dynamically locate the mypy.ini file, falling back to the default relative path if not found.

# Path to the centralized mypy configuration file at the repository root.
# Search upwards to support running nox from both monorepo packages and integration test goldens.
MYPY_CONFIG_FILE = next(
    (str(p / "mypy.ini") for p in CURRENT_DIRECTORY.parents if (p / "mypy.ini").exists()),
    str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"),
)
References
  1. Do not suggest manual code modifications, optimizations, or style fixes for generated files, as any changes should be implemented in the generator or templates to prevent them from being overwritten.


LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
PACKAGE_NAME = "{{ api.naming.warehouse_package_name }}"
Expand Down Expand Up @@ -96,6 +98,7 @@ def mypy(session):
session.install(".")
session.run(
"mypy",
f"--config-file={MYPY_CONFIG_FILE}",
"-p",
{% if api.naming.module_namespace %}
"{{ api.naming.module_namespace[0] }}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ def _overwrite_golden_impl(ctx):
golden_update_script_content = """
cd ${{BUILD_WORKSPACE_DIRECTORY}}
# Filename pattern-based removal is needed to preserve the BUILD.bazel file.
find tests/integration/goldens/{api_name}/ -name \\*.py-type f -delete
find tests/integration/goldens/{api_name}/ -name \\*.py -type f -delete
find tests/integration/goldens/{api_name}/ -name \\*.json -type f -delete
find tests/integration/goldens/{api_name}/ -name \\*.ini -type f -delete
unzip -ao {goldens_output_zip} -d tests/integration/goldens/{api_name}
""".format(
goldens_output_zip = goldens_output_zip.path,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
PREVIEW_PYTHON_VERSION = "3.14"

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

LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
PACKAGE_NAME = "google-cloud-asset"
Expand Down Expand Up @@ -103,6 +105,7 @@ def mypy(session):
session.install(".")
session.run(
"mypy",
f"--config-file={MYPY_CONFIG_FILE}",
"-p",
"google",
"--check-untyped-defs",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
PREVIEW_PYTHON_VERSION = "3.14"

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

LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
PACKAGE_NAME = "google-iam-credentials"
Expand Down Expand Up @@ -103,6 +105,7 @@ def mypy(session):
session.install(".")
session.run(
"mypy",
f"--config-file={MYPY_CONFIG_FILE}",
"-p",
"google",
"--check-untyped-defs",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
PREVIEW_PYTHON_VERSION = "3.14"

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

LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
PACKAGE_NAME = "google-cloud-eventarc"
Expand Down Expand Up @@ -103,6 +105,7 @@ def mypy(session):
session.install(".")
session.run(
"mypy",
f"--config-file={MYPY_CONFIG_FILE}",
"-p",
"google",
"--check-untyped-defs",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
PREVIEW_PYTHON_VERSION = "3.14"

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

LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
PACKAGE_NAME = "google-cloud-logging"
Expand Down Expand Up @@ -103,6 +105,7 @@ def mypy(session):
session.install(".")
session.run(
"mypy",
f"--config-file={MYPY_CONFIG_FILE}",
"-p",
"google",
"--check-untyped-defs",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
PREVIEW_PYTHON_VERSION = "3.14"

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

LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
PACKAGE_NAME = "google-cloud-logging"
Expand Down Expand Up @@ -103,6 +105,7 @@ def mypy(session):
session.install(".")
session.run(
"mypy",
f"--config-file={MYPY_CONFIG_FILE}",
"-p",
"google",
"--check-untyped-defs",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
PREVIEW_PYTHON_VERSION = "3.14"

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

LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
PACKAGE_NAME = "google-cloud-redis"
Expand Down Expand Up @@ -103,6 +105,7 @@ def mypy(session):
session.install(".")
session.run(
"mypy",
f"--config-file={MYPY_CONFIG_FILE}",
"-p",
"google",
"--check-untyped-defs",
Expand Down

This file was deleted.

Loading
Loading