2626
2727common = gcp .CommonTemplates ()
2828
29- # This library ships clients for two different APIs,
30- # BigTable and BigTable Admin
31- bigtable_default_version = "v2"
32- bigtable_admin_default_version = "v2"
33-
3429# These flags are needed because certain post-processing operations
3530# append things after a certain line of text, and can infinitely loop
3631# in a Github PR. We use these flags to only do those operations
4035is_fresh_admin_v2_copy = False
4136is_fresh_admin_docs_copy = False
4237
43- for library in s .get_staging_dirs (bigtable_default_version ):
44- # ----------------------------------------------------------------------------
45- # Always supply app_profile_id in routing headers: https://github.com/googleapis/python-bigtable/pull/1109
46- # TODO: remove after backend no longer requires empty strings
47- # ----------------------------------------------------------------------------
48- for file in ["async_client.py" , "client.py" ]:
49- s .replace (
50- library / f"google/cloud/bigtable_v2/services/bigtable/{ file } " ,
51- "if request.app_profile_id:" ,
52- "if True: # always attach app_profile_id, even if empty string"
53- )
54- # fix tests
55- s .replace (
56- library / "tests/unit/gapic/bigtable_v2/test_bigtable.py" ,
57- 'assert \(\n \s*gapic_v1\.routing_header\.to_grpc_metadata\(expected_headers\) in kw\["metadata"\]\n .*' ,
58- """
59- # assert the expected headers are present, in any order
60- routing_string = next(iter([m[1] for m in kw["metadata"] if m[0] == 'x-goog-request-params']))
61- assert all([f"{k}={v}" in routing_string for k,v in expected_headers.items()])
62- """
63- )
64- s .replace (
65- library / "tests/unit/gapic/bigtable_v2/test_bigtable.py" ,
66- 'expected_headers = {"name": "projects/sample1/instances/sample2"}' ,
67- 'expected_headers = {"name": "projects/sample1/instances/sample2", "app_profile_id": ""}'
68- )
69- s .replace (
70- library / "tests/unit/gapic/bigtable_v2/test_bigtable.py" ,
71- """expected_headers = \{
72- "table_name": "projects/sample1/instances/sample2/tables/sample3"
73- \}""" ,
74- """expected_headers = {
75- "table_name": "projects/sample1/instances/sample2/tables/sample3",
76- "app_profile_id": ""
77- }"""
78- )
79-
38+ for library in s .get_staging_dirs ("v2" ):
8039 s .move (library / "google/cloud/bigtable_v2" )
81- s .move (library / "tests" )
82- s .move (library / "scripts" )
83-
84- for library in s .get_staging_dirs (bigtable_admin_default_version ):
8540 is_fresh_admin_copy = \
8641 s .move (library / "google/cloud/bigtable_admin" )
8742 is_fresh_admin_v2_copy = \
11267
11368s .move (templated_files , excludes = [".coveragerc" , "README.rst" , ".github/**" , ".kokoro/**" , "noxfile.py" , "renovate.json" ])
11469
70+
71+ s .shell .run (["nox" , "-s" , "blacken" ], hide_output = False )
72+
73+ # ----------------------------------------------------------------------------
74+ # Always supply app_profile_id in routing headers: https://github.com/googleapis/python-bigtable/pull/1109
75+ # TODO: remove after backend no longer requires empty strings
76+ # ----------------------------------------------------------------------------
77+ for file in ["async_client.py" , "client.py" ]:
78+ s .replace (
79+ f"google/cloud/bigtable_v2/services/bigtable/{ file } " ,
80+ "if request.app_profile_id:" ,
81+ "if True: # always attach app_profile_id, even if empty string"
82+ )
83+ # fix tests
84+ s .replace (
85+ "tests/unit/gapic/bigtable_v2/test_bigtable.py" ,
86+ 'assert \(\n \s*gapic_v1\.routing_header\.to_grpc_metadata\(expected_headers\) in kw\["metadata"\]\n .*' ,
87+ """# assert the expected headers are present, in any order
88+ routing_string = next(
89+ iter([m[1] for m in kw["metadata"] if m[0] == "x-goog-request-params"])
90+ )
91+ assert all([f"{k}={v}" in routing_string for k, v in expected_headers.items()])"""
92+ )
93+ s .replace (
94+ "tests/unit/gapic/bigtable_v2/test_bigtable.py" ,
95+ 'expected_headers = {"name": "projects/sample1/instances/sample2"}' ,
96+ """expected_headers = {
97+ "name": "projects/sample1/instances/sample2",
98+ "app_profile_id": "",
99+ }"""
100+ )
101+ s .replace (
102+ "tests/unit/gapic/bigtable_v2/test_bigtable.py" ,
103+ """
104+ expected_headers = {
105+ "table_name": "projects/sample1/instances/sample2/tables/sample3"
106+ }
107+ """ ,
108+ """
109+ expected_headers = {
110+ "table_name": "projects/sample1/instances/sample2/tables/sample3",
111+ "app_profile_id": "",
112+ }
113+ """
114+ )
115+
115116# ----------------------------------------------------------------------------
116117# Samples templates
117118# ----------------------------------------------------------------------------
118119
119120python .py_samples (skip_readmes = True )
120121
121- s .replace (
122- "samples/beam/noxfile.py" ,
123- """INSTALL_LIBRARY_FROM_SOURCE \= os.environ.get\("INSTALL_LIBRARY_FROM_SOURCE", False\) in \(
124- "True",
125- "true",
126- \)""" ,
127- """# todo(kolea2): temporary workaround to install pinned dep version
128- INSTALL_LIBRARY_FROM_SOURCE = False""" )
129-
130122# --------------------------------------------------------------------------
131123# Admin Overlay work
132124# --------------------------------------------------------------------------
@@ -144,9 +136,8 @@ def add_overlay_to_init_py(init_py_location, import_statements, should_add):
144136
145137add_overlay_to_init_py (
146138 "google/cloud/bigtable_admin_v2/__init__.py" ,
147- """from .overlay import * # noqa: F403
148- __all__ += overlay.__all__ # noqa: F405
149- """ ,
139+ """from .overlay import * # noqa: F403\n
140+ __all__ += overlay.__all__ # noqa: F405""" ,
150141 is_fresh_admin_v2_copy ,
151142)
152143
@@ -155,8 +146,7 @@ def add_overlay_to_init_py(init_py_location, import_statements, should_add):
155146 """import google.cloud.bigtable_admin_v2.overlay # noqa: F401
156147from google.cloud.bigtable_admin_v2.overlay import * # noqa: F401, F403
157148
158- __all__ += google.cloud.bigtable_admin_v2.overlay.__all__
159- """ ,
149+ __all__ += google.cloud.bigtable_admin_v2.overlay.__all__""" ,
160150 is_fresh_admin_copy ,
161151)
162152
@@ -274,5 +264,3 @@ def add_overlay_to_init_py(init_py_location, import_statements, should_add):
274264 r"class GcRule\(proto\.Message\)\:" ,
275265 "class GcRule(oneof_message.OneofMessage):" ,
276266 )
277-
278- s .shell .run (["nox" , "-s" , "blacken" ], hide_output = False )
0 commit comments