Skip to content

Commit 8bdb709

Browse files
authored
fix: don't enable snippetgen by default (googleapis#1078)
* Revert "test: add tests for autogen-snippets option (googleapis#1055)" This reverts commit 185ecc7. * Revert "feat: generate code snippets by default (googleapis#1044)" This reverts commit e46f443.
1 parent 89bc432 commit 8bdb709

3 files changed

Lines changed: 9 additions & 45 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

tests/unit/generator/test_options.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ def test_options_service_config(fs):
141141

142142

143143
def test_options_bool_flags():
144-
# Most options are default False.
144+
# All these options are default False.
145+
# If new options violate this assumption,
146+
# this test may need to be tweaked.
145147
# New options should follow the dash-case/snake_case convention.
146148
opt_str_to_attr_name = {
147149
name: re.sub(r"-", "_", name)
@@ -159,22 +161,3 @@ def test_options_bool_flags():
159161

160162
options = Options.build(opt)
161163
assert getattr(options, attr)
162-
163-
# Check autogen-snippets separately, as it is default True
164-
options = Options.build("")
165-
assert options.autogen_snippets
166-
167-
options = Options.build("autogen-snippets=False")
168-
assert not options.autogen_snippets
169-
170-
171-
def test_options_autogen_snippets_false_for_old_naming():
172-
# NOTE: Snippets are not currently correct for the alternative (Ads) templates
173-
# so always disable snippetgen in that case
174-
# https://github.com/googleapis/gapic-generator-python/issues/1052
175-
options = Options.build("old-naming")
176-
assert not options.autogen_snippets
177-
178-
# Even if autogen-snippets is set to True, do not enable snippetgen
179-
options = Options.build("old-naming,autogen-snippets=True")
180-
assert not options.autogen_snippets

0 commit comments

Comments
 (0)