google-cloud-bigtable 2.30.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. google/cloud/bigtable/__init__.py +25 -0
  2. google/cloud/bigtable/app_profile.py +377 -0
  3. google/cloud/bigtable/backup.py +490 -0
  4. google/cloud/bigtable/batcher.py +414 -0
  5. google/cloud/bigtable/client.py +475 -0
  6. google/cloud/bigtable/cluster.py +541 -0
  7. google/cloud/bigtable/column_family.py +362 -0
  8. google/cloud/bigtable/data/__init__.py +103 -0
  9. google/cloud/bigtable/data/_async/__init__.py +25 -0
  10. google/cloud/bigtable/data/_async/_mutate_rows.py +226 -0
  11. google/cloud/bigtable/data/_async/_read_rows.py +363 -0
  12. google/cloud/bigtable/data/_async/client.py +1522 -0
  13. google/cloud/bigtable/data/_async/mutations_batcher.py +534 -0
  14. google/cloud/bigtable/data/_cross_sync/__init__.py +20 -0
  15. google/cloud/bigtable/data/_cross_sync/_decorators.py +441 -0
  16. google/cloud/bigtable/data/_cross_sync/_mapping_meta.py +64 -0
  17. google/cloud/bigtable/data/_cross_sync/cross_sync.py +334 -0
  18. google/cloud/bigtable/data/_helpers.py +249 -0
  19. google/cloud/bigtable/data/_sync_autogen/_mutate_rows.py +182 -0
  20. google/cloud/bigtable/data/_sync_autogen/_read_rows.py +304 -0
  21. google/cloud/bigtable/data/_sync_autogen/client.py +1293 -0
  22. google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py +449 -0
  23. google/cloud/bigtable/data/exceptions.py +340 -0
  24. google/cloud/bigtable/data/execute_query/__init__.py +43 -0
  25. google/cloud/bigtable/data/execute_query/_async/__init__.py +13 -0
  26. google/cloud/bigtable/data/execute_query/_async/execute_query_iterator.py +291 -0
  27. google/cloud/bigtable/data/execute_query/_byte_cursor.py +123 -0
  28. google/cloud/bigtable/data/execute_query/_checksum.py +43 -0
  29. google/cloud/bigtable/data/execute_query/_parameters_formatting.py +155 -0
  30. google/cloud/bigtable/data/execute_query/_query_result_parsing_utils.py +134 -0
  31. google/cloud/bigtable/data/execute_query/_reader.py +122 -0
  32. google/cloud/bigtable/data/execute_query/_sync_autogen/execute_query_iterator.py +239 -0
  33. google/cloud/bigtable/data/execute_query/metadata.py +399 -0
  34. google/cloud/bigtable/data/execute_query/values.py +123 -0
  35. google/cloud/bigtable/data/mutations.py +380 -0
  36. google/cloud/bigtable/data/read_modify_write_rules.py +112 -0
  37. google/cloud/bigtable/data/read_rows_query.py +536 -0
  38. google/cloud/bigtable/data/row.py +535 -0
  39. google/cloud/bigtable/data/row_filters.py +968 -0
  40. google/cloud/bigtable/encryption_info.py +64 -0
  41. google/cloud/bigtable/enums.py +223 -0
  42. google/cloud/bigtable/error.py +64 -0
  43. google/cloud/bigtable/gapic_version.py +16 -0
  44. google/cloud/bigtable/helpers.py +31 -0
  45. google/cloud/bigtable/instance.py +789 -0
  46. google/cloud/bigtable/policy.py +255 -0
  47. google/cloud/bigtable/row.py +1267 -0
  48. google/cloud/bigtable/row_data.py +380 -0
  49. google/cloud/bigtable/row_filters.py +838 -0
  50. google/cloud/bigtable/row_merger.py +250 -0
  51. google/cloud/bigtable/row_set.py +213 -0
  52. google/cloud/bigtable/table.py +1409 -0
  53. google/cloud/bigtable_admin/__init__.py +410 -0
  54. google/cloud/bigtable_admin/gapic_version.py +16 -0
  55. google/cloud/bigtable_admin/py.typed +2 -0
  56. google/cloud/bigtable_admin_v2/__init__.py +250 -0
  57. google/cloud/bigtable_admin_v2/gapic_metadata.json +962 -0
  58. google/cloud/bigtable_admin_v2/gapic_version.py +16 -0
  59. google/cloud/bigtable_admin_v2/py.typed +2 -0
  60. google/cloud/bigtable_admin_v2/services/__init__.py +15 -0
  61. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/__init__.py +22 -0
  62. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/async_client.py +3465 -0
  63. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py +3944 -0
  64. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/pagers.py +681 -0
  65. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/__init__.py +40 -0
  66. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/base.py +751 -0
  67. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc.py +1249 -0
  68. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc_asyncio.py +1579 -0
  69. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest.py +6820 -0
  70. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest_base.py +1746 -0
  71. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/__init__.py +22 -0
  72. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/async_client.py +3472 -0
  73. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/client.py +3949 -0
  74. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/pagers.py +669 -0
  75. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/__init__.py +40 -0
  76. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/base.py +708 -0
  77. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc.py +1257 -0
  78. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc_asyncio.py +1549 -0
  79. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest.py +6609 -0
  80. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest_base.py +1714 -0
  81. google/cloud/bigtable_admin_v2/types/__init__.py +248 -0
  82. google/cloud/bigtable_admin_v2/types/bigtable_instance_admin.py +1364 -0
  83. google/cloud/bigtable_admin_v2/types/bigtable_table_admin.py +1715 -0
  84. google/cloud/bigtable_admin_v2/types/common.py +81 -0
  85. google/cloud/bigtable_admin_v2/types/instance.py +819 -0
  86. google/cloud/bigtable_admin_v2/types/table.py +1028 -0
  87. google/cloud/bigtable_admin_v2/types/types.py +776 -0
  88. google/cloud/bigtable_v2/__init__.py +136 -0
  89. google/cloud/bigtable_v2/gapic_metadata.json +193 -0
  90. google/cloud/bigtable_v2/gapic_version.py +16 -0
  91. google/cloud/bigtable_v2/py.typed +2 -0
  92. google/cloud/bigtable_v2/services/__init__.py +15 -0
  93. google/cloud/bigtable_v2/services/bigtable/__init__.py +22 -0
  94. google/cloud/bigtable_v2/services/bigtable/async_client.py +1741 -0
  95. google/cloud/bigtable_v2/services/bigtable/client.py +2194 -0
  96. google/cloud/bigtable_v2/services/bigtable/transports/__init__.py +38 -0
  97. google/cloud/bigtable_v2/services/bigtable/transports/base.py +343 -0
  98. google/cloud/bigtable_v2/services/bigtable/transports/grpc.py +660 -0
  99. google/cloud/bigtable_v2/services/bigtable/transports/grpc_asyncio.py +762 -0
  100. google/cloud/bigtable_v2/services/bigtable/transports/rest.py +2489 -0
  101. google/cloud/bigtable_v2/services/bigtable/transports/rest_base.py +711 -0
  102. google/cloud/bigtable_v2/types/__init__.py +138 -0
  103. google/cloud/bigtable_v2/types/bigtable.py +1531 -0
  104. google/cloud/bigtable_v2/types/data.py +1612 -0
  105. google/cloud/bigtable_v2/types/feature_flags.py +119 -0
  106. google/cloud/bigtable_v2/types/request_stats.py +171 -0
  107. google/cloud/bigtable_v2/types/response_params.py +64 -0
  108. google/cloud/bigtable_v2/types/types.py +579 -0
  109. google_cloud_bigtable-2.30.0.data/scripts/fixup_bigtable_admin_v2_keywords.py +233 -0
  110. google_cloud_bigtable-2.30.0.data/scripts/fixup_bigtable_v2_keywords.py +186 -0
  111. google_cloud_bigtable-2.30.0.dist-info/LICENSE +202 -0
  112. google_cloud_bigtable-2.30.0.dist-info/METADATA +154 -0
  113. google_cloud_bigtable-2.30.0.dist-info/RECORD +115 -0
  114. google_cloud_bigtable-2.30.0.dist-info/WHEEL +5 -0
  115. google_cloud_bigtable-2.30.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,233 @@
1
+ #!python
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright 2024 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ import argparse
18
+ import os
19
+ import libcst as cst
20
+ import pathlib
21
+ import sys
22
+ from typing import (Any, Callable, Dict, List, Sequence, Tuple)
23
+
24
+
25
+ def partition(
26
+ predicate: Callable[[Any], bool],
27
+ iterator: Sequence[Any]
28
+ ) -> Tuple[List[Any], List[Any]]:
29
+ """A stable, out-of-place partition."""
30
+ results = ([], [])
31
+
32
+ for i in iterator:
33
+ results[int(predicate(i))].append(i)
34
+
35
+ # Returns trueList, falseList
36
+ return results[1], results[0]
37
+
38
+
39
+ class bigtable_adminCallTransformer(cst.CSTTransformer):
40
+ CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata')
41
+ METHOD_TO_PARAMS: Dict[str, Tuple[str]] = {
42
+ 'check_consistency': ('name', 'consistency_token', 'standard_read_remote_writes', 'data_boost_read_local_writes', ),
43
+ 'copy_backup': ('parent', 'backup_id', 'source_backup', 'expire_time', ),
44
+ 'create_app_profile': ('parent', 'app_profile_id', 'app_profile', 'ignore_warnings', ),
45
+ 'create_authorized_view': ('parent', 'authorized_view_id', 'authorized_view', ),
46
+ 'create_backup': ('parent', 'backup_id', 'backup', ),
47
+ 'create_cluster': ('parent', 'cluster_id', 'cluster', ),
48
+ 'create_instance': ('parent', 'instance_id', 'instance', 'clusters', ),
49
+ 'create_logical_view': ('parent', 'logical_view_id', 'logical_view', ),
50
+ 'create_materialized_view': ('parent', 'materialized_view_id', 'materialized_view', ),
51
+ 'create_table': ('parent', 'table_id', 'table', 'initial_splits', ),
52
+ 'create_table_from_snapshot': ('parent', 'table_id', 'source_snapshot', ),
53
+ 'delete_app_profile': ('name', 'ignore_warnings', ),
54
+ 'delete_authorized_view': ('name', 'etag', ),
55
+ 'delete_backup': ('name', ),
56
+ 'delete_cluster': ('name', ),
57
+ 'delete_instance': ('name', ),
58
+ 'delete_logical_view': ('name', 'etag', ),
59
+ 'delete_materialized_view': ('name', 'etag', ),
60
+ 'delete_snapshot': ('name', ),
61
+ 'delete_table': ('name', ),
62
+ 'drop_row_range': ('name', 'row_key_prefix', 'delete_all_data_from_table', ),
63
+ 'generate_consistency_token': ('name', ),
64
+ 'get_app_profile': ('name', ),
65
+ 'get_authorized_view': ('name', 'view', ),
66
+ 'get_backup': ('name', ),
67
+ 'get_cluster': ('name', ),
68
+ 'get_iam_policy': ('resource', 'options', ),
69
+ 'get_instance': ('name', ),
70
+ 'get_logical_view': ('name', ),
71
+ 'get_materialized_view': ('name', ),
72
+ 'get_snapshot': ('name', ),
73
+ 'get_table': ('name', 'view', ),
74
+ 'list_app_profiles': ('parent', 'page_size', 'page_token', ),
75
+ 'list_authorized_views': ('parent', 'page_size', 'page_token', 'view', ),
76
+ 'list_backups': ('parent', 'filter', 'order_by', 'page_size', 'page_token', ),
77
+ 'list_clusters': ('parent', 'page_token', ),
78
+ 'list_hot_tablets': ('parent', 'start_time', 'end_time', 'page_size', 'page_token', ),
79
+ 'list_instances': ('parent', 'page_token', ),
80
+ 'list_logical_views': ('parent', 'page_size', 'page_token', ),
81
+ 'list_materialized_views': ('parent', 'page_size', 'page_token', ),
82
+ 'list_snapshots': ('parent', 'page_size', 'page_token', ),
83
+ 'list_tables': ('parent', 'view', 'page_size', 'page_token', ),
84
+ 'modify_column_families': ('name', 'modifications', 'ignore_warnings', ),
85
+ 'partial_update_cluster': ('cluster', 'update_mask', ),
86
+ 'partial_update_instance': ('instance', 'update_mask', ),
87
+ 'restore_table': ('parent', 'table_id', 'backup', ),
88
+ 'set_iam_policy': ('resource', 'policy', 'update_mask', ),
89
+ 'snapshot_table': ('name', 'cluster', 'snapshot_id', 'ttl', 'description', ),
90
+ 'test_iam_permissions': ('resource', 'permissions', ),
91
+ 'undelete_table': ('name', ),
92
+ 'update_app_profile': ('app_profile', 'update_mask', 'ignore_warnings', ),
93
+ 'update_authorized_view': ('authorized_view', 'update_mask', 'ignore_warnings', ),
94
+ 'update_backup': ('backup', 'update_mask', ),
95
+ 'update_cluster': ('name', 'location', 'state', 'serve_nodes', 'node_scaling_factor', 'cluster_config', 'default_storage_type', 'encryption_config', ),
96
+ 'update_instance': ('display_name', 'name', 'state', 'type_', 'labels', 'create_time', 'satisfies_pzs', 'satisfies_pzi', ),
97
+ 'update_logical_view': ('logical_view', 'update_mask', ),
98
+ 'update_materialized_view': ('materialized_view', 'update_mask', ),
99
+ 'update_table': ('table', 'update_mask', 'ignore_warnings', ),
100
+ }
101
+
102
+ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode:
103
+ try:
104
+ key = original.func.attr.value
105
+ kword_params = self.METHOD_TO_PARAMS[key]
106
+ except (AttributeError, KeyError):
107
+ # Either not a method from the API or too convoluted to be sure.
108
+ return updated
109
+
110
+ # If the existing code is valid, keyword args come after positional args.
111
+ # Therefore, all positional args must map to the first parameters.
112
+ args, kwargs = partition(lambda a: not bool(a.keyword), updated.args)
113
+ if any(k.keyword.value == "request" for k in kwargs):
114
+ # We've already fixed this file, don't fix it again.
115
+ return updated
116
+
117
+ kwargs, ctrl_kwargs = partition(
118
+ lambda a: a.keyword.value not in self.CTRL_PARAMS,
119
+ kwargs
120
+ )
121
+
122
+ args, ctrl_args = args[:len(kword_params)], args[len(kword_params):]
123
+ ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl))
124
+ for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS))
125
+
126
+ request_arg = cst.Arg(
127
+ value=cst.Dict([
128
+ cst.DictElement(
129
+ cst.SimpleString("'{}'".format(name)),
130
+ cst.Element(value=arg.value)
131
+ )
132
+ # Note: the args + kwargs looks silly, but keep in mind that
133
+ # the control parameters had to be stripped out, and that
134
+ # those could have been passed positionally or by keyword.
135
+ for name, arg in zip(kword_params, args + kwargs)]),
136
+ keyword=cst.Name("request")
137
+ )
138
+
139
+ return updated.with_changes(
140
+ args=[request_arg] + ctrl_kwargs
141
+ )
142
+
143
+
144
+ def fix_files(
145
+ in_dir: pathlib.Path,
146
+ out_dir: pathlib.Path,
147
+ *,
148
+ transformer=bigtable_adminCallTransformer(),
149
+ ):
150
+ """Duplicate the input dir to the output dir, fixing file method calls.
151
+
152
+ Preconditions:
153
+ * in_dir is a real directory
154
+ * out_dir is a real, empty directory
155
+ """
156
+ pyfile_gen = (
157
+ pathlib.Path(os.path.join(root, f))
158
+ for root, _, files in os.walk(in_dir)
159
+ for f in files if os.path.splitext(f)[1] == ".py"
160
+ )
161
+
162
+ for fpath in pyfile_gen:
163
+ with open(fpath, 'r') as f:
164
+ src = f.read()
165
+
166
+ # Parse the code and insert method call fixes.
167
+ tree = cst.parse_module(src)
168
+ updated = tree.visit(transformer)
169
+
170
+ # Create the path and directory structure for the new file.
171
+ updated_path = out_dir.joinpath(fpath.relative_to(in_dir))
172
+ updated_path.parent.mkdir(parents=True, exist_ok=True)
173
+
174
+ # Generate the updated source file at the corresponding path.
175
+ with open(updated_path, 'w') as f:
176
+ f.write(updated.code)
177
+
178
+
179
+ if __name__ == '__main__':
180
+ parser = argparse.ArgumentParser(
181
+ description="""Fix up source that uses the bigtable_admin client library.
182
+
183
+ The existing sources are NOT overwritten but are copied to output_dir with changes made.
184
+
185
+ Note: This tool operates at a best-effort level at converting positional
186
+ parameters in client method calls to keyword based parameters.
187
+ Cases where it WILL FAIL include
188
+ A) * or ** expansion in a method call.
189
+ B) Calls via function or method alias (includes free function calls)
190
+ C) Indirect or dispatched calls (e.g. the method is looked up dynamically)
191
+
192
+ These all constitute false negatives. The tool will also detect false
193
+ positives when an API method shares a name with another method.
194
+ """)
195
+ parser.add_argument(
196
+ '-d',
197
+ '--input-directory',
198
+ required=True,
199
+ dest='input_dir',
200
+ help='the input directory to walk for python files to fix up',
201
+ )
202
+ parser.add_argument(
203
+ '-o',
204
+ '--output-directory',
205
+ required=True,
206
+ dest='output_dir',
207
+ help='the directory to output files fixed via un-flattening',
208
+ )
209
+ args = parser.parse_args()
210
+ input_dir = pathlib.Path(args.input_dir)
211
+ output_dir = pathlib.Path(args.output_dir)
212
+ if not input_dir.is_dir():
213
+ print(
214
+ f"input directory '{input_dir}' does not exist or is not a directory",
215
+ file=sys.stderr,
216
+ )
217
+ sys.exit(-1)
218
+
219
+ if not output_dir.is_dir():
220
+ print(
221
+ f"output directory '{output_dir}' does not exist or is not a directory",
222
+ file=sys.stderr,
223
+ )
224
+ sys.exit(-1)
225
+
226
+ if os.listdir(output_dir):
227
+ print(
228
+ f"output directory '{output_dir}' is not empty",
229
+ file=sys.stderr,
230
+ )
231
+ sys.exit(-1)
232
+
233
+ fix_files(input_dir, output_dir)
@@ -0,0 +1,186 @@
1
+ #!python
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright 2024 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ import argparse
18
+ import os
19
+ import libcst as cst
20
+ import pathlib
21
+ import sys
22
+ from typing import (Any, Callable, Dict, List, Sequence, Tuple)
23
+
24
+
25
+ def partition(
26
+ predicate: Callable[[Any], bool],
27
+ iterator: Sequence[Any]
28
+ ) -> Tuple[List[Any], List[Any]]:
29
+ """A stable, out-of-place partition."""
30
+ results = ([], [])
31
+
32
+ for i in iterator:
33
+ results[int(predicate(i))].append(i)
34
+
35
+ # Returns trueList, falseList
36
+ return results[1], results[0]
37
+
38
+
39
+ class bigtableCallTransformer(cst.CSTTransformer):
40
+ CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata')
41
+ METHOD_TO_PARAMS: Dict[str, Tuple[str]] = {
42
+ 'check_and_mutate_row': ('row_key', 'table_name', 'authorized_view_name', 'app_profile_id', 'predicate_filter', 'true_mutations', 'false_mutations', ),
43
+ 'execute_query': ('instance_name', 'query', 'params', 'app_profile_id', 'prepared_query', 'proto_format', 'resume_token', ),
44
+ 'generate_initial_change_stream_partitions': ('table_name', 'app_profile_id', ),
45
+ 'mutate_row': ('row_key', 'mutations', 'table_name', 'authorized_view_name', 'app_profile_id', ),
46
+ 'mutate_rows': ('entries', 'table_name', 'authorized_view_name', 'app_profile_id', ),
47
+ 'ping_and_warm': ('name', 'app_profile_id', ),
48
+ 'prepare_query': ('instance_name', 'query', 'param_types', 'app_profile_id', 'proto_format', ),
49
+ 'read_change_stream': ('table_name', 'app_profile_id', 'partition', 'start_time', 'continuation_tokens', 'end_time', 'heartbeat_duration', ),
50
+ 'read_modify_write_row': ('row_key', 'rules', 'table_name', 'authorized_view_name', 'app_profile_id', ),
51
+ 'read_rows': ('table_name', 'authorized_view_name', 'materialized_view_name', 'app_profile_id', 'rows', 'filter', 'rows_limit', 'request_stats_view', 'reversed', ),
52
+ 'sample_row_keys': ('table_name', 'authorized_view_name', 'materialized_view_name', 'app_profile_id', ),
53
+ }
54
+
55
+ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode:
56
+ try:
57
+ key = original.func.attr.value
58
+ kword_params = self.METHOD_TO_PARAMS[key]
59
+ except (AttributeError, KeyError):
60
+ # Either not a method from the API or too convoluted to be sure.
61
+ return updated
62
+
63
+ # If the existing code is valid, keyword args come after positional args.
64
+ # Therefore, all positional args must map to the first parameters.
65
+ args, kwargs = partition(lambda a: not bool(a.keyword), updated.args)
66
+ if any(k.keyword.value == "request" for k in kwargs):
67
+ # We've already fixed this file, don't fix it again.
68
+ return updated
69
+
70
+ kwargs, ctrl_kwargs = partition(
71
+ lambda a: a.keyword.value not in self.CTRL_PARAMS,
72
+ kwargs
73
+ )
74
+
75
+ args, ctrl_args = args[:len(kword_params)], args[len(kword_params):]
76
+ ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl))
77
+ for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS))
78
+
79
+ request_arg = cst.Arg(
80
+ value=cst.Dict([
81
+ cst.DictElement(
82
+ cst.SimpleString("'{}'".format(name)),
83
+ cst.Element(value=arg.value)
84
+ )
85
+ # Note: the args + kwargs looks silly, but keep in mind that
86
+ # the control parameters had to be stripped out, and that
87
+ # those could have been passed positionally or by keyword.
88
+ for name, arg in zip(kword_params, args + kwargs)]),
89
+ keyword=cst.Name("request")
90
+ )
91
+
92
+ return updated.with_changes(
93
+ args=[request_arg] + ctrl_kwargs
94
+ )
95
+
96
+
97
+ def fix_files(
98
+ in_dir: pathlib.Path,
99
+ out_dir: pathlib.Path,
100
+ *,
101
+ transformer=bigtableCallTransformer(),
102
+ ):
103
+ """Duplicate the input dir to the output dir, fixing file method calls.
104
+
105
+ Preconditions:
106
+ * in_dir is a real directory
107
+ * out_dir is a real, empty directory
108
+ """
109
+ pyfile_gen = (
110
+ pathlib.Path(os.path.join(root, f))
111
+ for root, _, files in os.walk(in_dir)
112
+ for f in files if os.path.splitext(f)[1] == ".py"
113
+ )
114
+
115
+ for fpath in pyfile_gen:
116
+ with open(fpath, 'r') as f:
117
+ src = f.read()
118
+
119
+ # Parse the code and insert method call fixes.
120
+ tree = cst.parse_module(src)
121
+ updated = tree.visit(transformer)
122
+
123
+ # Create the path and directory structure for the new file.
124
+ updated_path = out_dir.joinpath(fpath.relative_to(in_dir))
125
+ updated_path.parent.mkdir(parents=True, exist_ok=True)
126
+
127
+ # Generate the updated source file at the corresponding path.
128
+ with open(updated_path, 'w') as f:
129
+ f.write(updated.code)
130
+
131
+
132
+ if __name__ == '__main__':
133
+ parser = argparse.ArgumentParser(
134
+ description="""Fix up source that uses the bigtable client library.
135
+
136
+ The existing sources are NOT overwritten but are copied to output_dir with changes made.
137
+
138
+ Note: This tool operates at a best-effort level at converting positional
139
+ parameters in client method calls to keyword based parameters.
140
+ Cases where it WILL FAIL include
141
+ A) * or ** expansion in a method call.
142
+ B) Calls via function or method alias (includes free function calls)
143
+ C) Indirect or dispatched calls (e.g. the method is looked up dynamically)
144
+
145
+ These all constitute false negatives. The tool will also detect false
146
+ positives when an API method shares a name with another method.
147
+ """)
148
+ parser.add_argument(
149
+ '-d',
150
+ '--input-directory',
151
+ required=True,
152
+ dest='input_dir',
153
+ help='the input directory to walk for python files to fix up',
154
+ )
155
+ parser.add_argument(
156
+ '-o',
157
+ '--output-directory',
158
+ required=True,
159
+ dest='output_dir',
160
+ help='the directory to output files fixed via un-flattening',
161
+ )
162
+ args = parser.parse_args()
163
+ input_dir = pathlib.Path(args.input_dir)
164
+ output_dir = pathlib.Path(args.output_dir)
165
+ if not input_dir.is_dir():
166
+ print(
167
+ f"input directory '{input_dir}' does not exist or is not a directory",
168
+ file=sys.stderr,
169
+ )
170
+ sys.exit(-1)
171
+
172
+ if not output_dir.is_dir():
173
+ print(
174
+ f"output directory '{output_dir}' does not exist or is not a directory",
175
+ file=sys.stderr,
176
+ )
177
+ sys.exit(-1)
178
+
179
+ if os.listdir(output_dir):
180
+ print(
181
+ f"output directory '{output_dir}' is not empty",
182
+ file=sys.stderr,
183
+ )
184
+ sys.exit(-1)
185
+
186
+ fix_files(input_dir, output_dir)
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.