Skip to content
Closed
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
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
# Replace |version| in the docs with the actual version string.
rst_epilog = """
.. |version| replace:: {version}
""".format(
version=version
)
""".format(version=version)

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion gapic/cli/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"--output",
type=click.File("wb"),
default=sys.stdout.buffer,
help="Where to output the `CodeGeneratorResponse`. " "Defaults to stdout.",
help="Where to output the `CodeGeneratorResponse`. Defaults to stdout.",
)
def generate(request: typing.BinaryIO, output: typing.BinaryIO) -> None:
"""Generate a full API client description."""
Expand Down
4 changes: 1 addition & 3 deletions gapic/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ def get_response(self, api_schema: api.API, opts: Options) -> CodeGeneratorRespo
)

# Return the CodeGeneratorResponse output.
res = CodeGeneratorResponse(
file=[i for i in output_files.values()]
) # type: ignore
res = CodeGeneratorResponse(file=[i for i in output_files.values()]) # type: ignore
res.supported_features |= CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL # type: ignore
return res

Expand Down
4 changes: 3 additions & 1 deletion gapic/samplegen_utils/snippet_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def __init__(self, api_schema: api.API):
self.metadata_index.client_library.name = (
api_schema.naming.warehouse_package_name
)
self.metadata_index.client_library.language = snippet_metadata_pb2.Language.PYTHON # type: ignore
self.metadata_index.client_library.language = (
snippet_metadata_pb2.Language.PYTHON
) # type: ignore

self.metadata_index.client_library.version = api_schema.gapic_version

Expand Down
4 changes: 3 additions & 1 deletion gapic/samplegen_utils/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def get(self, key, default=None):
return next(
iter(
[
e.val for e in self.elements if e.key == key # type: ignore
e.val
for e in self.elements
if e.key == key # type: ignore
] # type: ignore
),
default,
Expand Down
9 changes: 2 additions & 7 deletions gapic/schema/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,11 +941,7 @@ def enforce_valid_library_settings(
selective_gapic_errors = {}
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2446):
# Workaround issue in Python 3.14 related to code coverage by adding `# pragma: no branch`
for (
method_name
) in (
library_settings.python_settings.common.selective_gapic_generation.methods
): # pragma: no branch
for method_name in library_settings.python_settings.common.selective_gapic_generation.methods: # pragma: no branch
if method_name not in self.all_methods:
selective_gapic_errors[method_name] = "Method does not exist."
elif not method_name.startswith(library_settings.version):
Expand Down Expand Up @@ -1180,8 +1176,7 @@ def __init__(
object.__setattr__(field, "enum", maybe_enum_type)
else:
raise TypeError(
f"Unknown type referenced in "
f"{self.file_descriptor.name}: '{key}'"
f"Unknown type referenced in {self.file_descriptor.name}: '{key}'"
)

# Only generate the service if this is a target file to be generated.
Expand Down
2 changes: 1 addition & 1 deletion gapic/schema/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def resolve(self, selector: str) -> str:
str: An absolute selector.
"""
if "." not in selector:
return f'{".".join(self.package)}.{selector}'
return f"{'.'.join(self.package)}.{selector}"
return selector

def with_context(self, *, collisions: Set[str]) -> "Address":
Expand Down
2 changes: 1 addition & 1 deletion gapic/schema/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def build(
"The protos provided do not share a common root package. "
"Ensure that all explicitly-specified protos are for a "
"single API. "
f'The packages we got are: {", ".join(proto_packages)}'
f"The packages we got are: {', '.join(proto_packages)}"
)

# Define the valid regex to split the package.
Expand Down
2 changes: 1 addition & 1 deletion gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ def get_field(
# Quick check: If this cursor has no message, there is a problem.
if not cursor.message:
raise KeyError(
f'Field {".".join(field_path)} could not be resolved from '
f"Field {'.'.join(field_path)} could not be resolved from "
f"{cursor.name}.",
)

Expand Down
49 changes: 27 additions & 22 deletions gapic/templates/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import warnings

import nox

BLACK_VERSION = "black[jupyter]==23.7.0"
ISORT_VERSION = "isort==5.11.0"
RUFF_VERSION = "ruff==0.14.14"

{% if api.naming.module_namespace %}
LINT_PATHS = ["docs", "{{ api.naming.module_namespace[0] }}", "tests", "noxfile.py", "setup.py"]
Expand Down Expand Up @@ -147,12 +146,11 @@ def lint(session):
Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install("flake8", BLACK_VERSION)
session.run(
"black",
"--check",
*LINT_PATHS,
)
session.install("flake8", RUFF_VERSION)

# 2. Check formatting
session.run("ruff", "format", "--check", "--line-length=88", *LINT_PATHS)


{% if api.naming.module_namespace %}
session.run("flake8", "{{ api.naming.module_namespace[0] }}", "tests")
Expand All @@ -163,30 +161,37 @@ def lint(session):

@nox.session(python=DEFAULT_PYTHON_VERSION)
def blacken(session):
"""Run black. Format code to uniform standard."""
session.install(BLACK_VERSION)
session.run(
"black",
*LINT_PATHS,
)
"""(Deprecated) Legacy session. Please use 'nox -s format'."""
session.log("WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future.")

# Just run the ruff formatter (keeping legacy behavior of only formatting, not sorting imports)
session.install(RUFF_VERSION)
session.run("ruff", "format", "--line-length=88", *LINT_PATHS)


@nox.session(python=DEFAULT_PYTHON_VERSION)
def format(session):
"""
Run isort to sort imports. Then run black
to format code to uniform standard.
Run ruff to sort imports and format code.
"""
session.install(BLACK_VERSION, ISORT_VERSION)
# Use the --fss option to sort imports using strict alphabetical order.
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections
# 1. Install ruff (skipped automatically if you run with --no-venv)
session.install(RUFF_VERSION)

# 2. Run Ruff to fix imports
# check --select I: Enables strict import sorting
# --fix: Applies the changes automatically
session.run(
"isort",
"--fss",
"ruff", "check",
"--select", "I",
"--fix",
"--line-length=88", # Standard Black line length
*LINT_PATHS,
)

# 3. Run Ruff to format code
session.run(
"black",
"ruff", "format",
"--line-length=88", # Standard Black line length
*LINT_PATHS,
)

Expand Down
83 changes: 67 additions & 16 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@

showcase_version = os.environ.get("SHOWCASE_VERSION", "0.35.0")
ADS_TEMPLATES = path.join(path.dirname(__file__), "gapic", "ads-templates")
BLACK_VERSION = "black==25.1.0"
BLACK_PATHS = ["docs", "gapic", "tests", "test_utils", "noxfile.py", "setup.py"]
# exclude golden files and generated protobuf code
BLACK_EXCLUDES = "|".join([".*golden.*", ".*pb2.py"])
RUFF_VERSION = "ruff==0.14.14"
LINT_PATHS = ["docs", "gapic", "tests", "test_utils", "noxfile.py", "setup.py"]
# Ruff uses globs for excludes (different from Black's regex)
# .*golden.* -> *golden*
# .*pb2.py -> *pb2.py
RUFF_EXCLUDES = "*golden*,*pb2.py,*pb2.pyi"

ALL_PYTHON = (
"3.7",
Expand Down Expand Up @@ -80,6 +82,7 @@ def unit(session):
path.join("tests", "unit"),
]
),
external=True,
)


Expand Down Expand Up @@ -294,7 +297,7 @@ def showcase_library(
}
]
update_service_yaml = _add_python_settings(tmp_dir, python_settings)
session.run("python", "-c" f"{update_service_yaml}")
session.run("python", f"-c{update_service_yaml}")
# END TODO section to remove.
if retry_config:
session.run(
Expand Down Expand Up @@ -755,14 +758,19 @@ def lint(session):
Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install("flake8", BLACK_VERSION)
session.install("flake8", RUFF_VERSION)

# 2. Check formatting
session.run(
"black",
"ruff",
"format",
"--check",
*BLACK_PATHS,
"--extend-exclude",
BLACK_EXCLUDES,
*LINT_PATHS,
"--exclude",
RUFF_EXCLUDES,
)

# 3. Run Flake8
session.run(
"flake8",
"gapic",
Expand All @@ -772,11 +780,54 @@ def lint(session):

@nox.session(python="3.10")
def blacken(session):
"""Run black. Format code to uniform standard."""
session.install(BLACK_VERSION)
"""Run ruff format.

DEPRECATED: This session now uses Ruff instead of Black.
It formats code style only (indentation, quotes, etc).
"""
session.log(
"WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future."
)

session.install(RUFF_VERSION)

# 1. Format Code (Replaces black)
# We do NOT run 'ruff check --select I' here, preserving strict parity.
session.run(
"ruff",
"format",
"--line-length=88", # Standard Black line length
*LINT_PATHS,
"--exclude",
RUFF_EXCLUDES,
)


@nox.session(python=NEWEST_PYTHON)
def format(session):
"""
Run ruff to sort imports and format code.
"""
# 1. Install ruff (skipped automatically if you run with --no-venv)
session.install(RUFF_VERSION)

# 2. Run Ruff to fix imports
# check --select I: Enables strict import sorting
# --fix: Applies the changes automatically
session.run(
"ruff",
"check",
"--select",
"I",
"--fix",
"--line-length=88", # Standard Black line length
*LINT_PATHS,
)

# 3. Run Ruff to format code
session.run(
"black",
*BLACK_PATHS,
"--extend-exclude",
BLACK_EXCLUDES,
"ruff",
"format",
"--line-length=88", # Standard Black line length
*LINT_PATHS,
)
10 changes: 5 additions & 5 deletions tests/integration/goldens/asset/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import shlex
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -81,9 +81,9 @@
root_doc = "index"

# General information about the project.
project = u"google-cloud-asset"
copyright = u"2025, Google, LLC"
author = u"Google APIs"
project = "google-cloud-asset"
copyright = "2025, Google, LLC"
author = "Google APIs"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -283,7 +283,7 @@
(
root_doc,
"google-cloud-asset.tex",
u"google-cloud-asset Documentation",
"google-cloud-asset Documentation",
author,
"manual",
)
Expand Down
Loading
Loading