Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit eccee7f

Browse files
committed
Revert "feat: generate code snippets by default (#1044)"
This reverts commit e46f443.
1 parent 269350c commit eccee7f

2 files changed

Lines changed: 6 additions & 25 deletions

File tree

gapic/utils/options.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Options:
3737
warehouse_package_name: str = ''
3838
retry: Optional[Dict[str, Any]] = None
3939
sample_configs: Tuple[str, ...] = dataclasses.field(default=())
40-
autogen_snippets: bool = True
40+
autogen_snippets: bool = False
4141
templates: Tuple[str, ...] = dataclasses.field(default=('DEFAULT',))
4242
lazy_import: bool = False
4343
old_naming: bool = False
@@ -132,17 +132,6 @@ def tweak_path(p):
132132
# Build the options instance.
133133
sample_paths = opts.pop('samples', [])
134134

135-
# autogen-snippets is True by default, so make sure users can disable
136-
# by passing `autogen-snippets=false`
137-
autogen_snippets = opts.pop(
138-
"autogen-snippets", ["True"])[0] in ("True", "true", "T", "t", "TRUE")
139-
140-
# NOTE: Snippets are not currently correct for the alternative (Ads) templates
141-
# so always disable snippetgen in that case
142-
# https://github.com/googleapis/gapic-generator-python/issues/1052
143-
if opts.get("old-naming"):
144-
autogen_snippets = False
145-
146135
answer = Options(
147136
name=opts.pop('name', ['']).pop(),
148137
namespace=tuple(opts.pop('namespace', [])),
@@ -154,7 +143,7 @@ def tweak_path(p):
154143
for s in sample_paths
155144
for cfg_path in samplegen_utils.generate_all_sample_fpaths(s)
156145
),
157-
autogen_snippets=autogen_snippets,
146+
autogen_snippets=bool(opts.pop("autogen-snippets", False)),
158147
templates=tuple(path.expanduser(i) for i in templates),
159148
lazy_import=bool(opts.pop('lazy-import', False)),
160149
old_naming=bool(opts.pop('old-naming', False)),

tests/unit/generator/test_generator.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,7 @@ def test_get_response_enumerates_proto():
242242

243243

244244
def test_get_response_divides_subpackages():
245-
# NOTE: autogen-snippets is intentionally disabled for this test
246-
# The API schema below is incomplete and will result in errors when the
247-
# snippetgen logic tries to parse it.
248-
g = make_generator("autogen-snippets=false")
245+
g = make_generator()
249246
api_schema = api.API.build(
250247
[
251248
descriptor_pb2.FileDescriptorProto(
@@ -280,7 +277,7 @@ def test_get_response_divides_subpackages():
280277
""".strip()
281278
)
282279
cgr = g.get_response(api_schema=api_schema,
283-
opts=Options.build("autogen-snippets=false"))
280+
opts=Options.build(""))
284281
assert len(cgr.file) == 6
285282
assert {i.name for i in cgr.file} == {
286283
"foo/types/top.py",
@@ -686,12 +683,7 @@ def test_dont_generate_in_code_samples(mock_gmtime, mock_generate_sample, fs):
686683
),
687684
)
688685

689-
# NOTE: autogen-snippets is intentionally disabled for this test
690-
# The API schema below is incomplete and will result in errors when the
691-
# snippetgen logic attempts to parse it.
692-
generator = make_generator(
693-
f"samples={config_fpath},autogen-snippets=False")
694-
print(generator)
686+
generator = make_generator(f"samples={config_fpath}")
695687
generator._env.loader = jinja2.DictLoader({"sample.py.j2": ""})
696688
api_schema = make_api(
697689
make_proto(
@@ -751,7 +743,7 @@ def test_dont_generate_in_code_samples(mock_gmtime, mock_generate_sample, fs):
751743
expected.supported_features |= CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL
752744

753745
actual = generator.get_response(
754-
api_schema=api_schema, opts=Options.build("autogen-snippets=False")
746+
api_schema=api_schema, opts=Options.build("")
755747
)
756748
assert actual == expected
757749

0 commit comments

Comments
 (0)