|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License |
| 14 | + |
1 | 15 | import importlib |
2 | 16 | import sys |
3 | | -import warnings |
4 | | - |
5 | 17 |
|
6 | | -_LEGACY_MODULE_NAMES = { |
| 18 | +_CLASSIC_CLIENT_MODULE_NAMES = { |
7 | 19 | "app_profile", |
8 | 20 | "backup", |
9 | 21 | "batcher", |
|
24 | 36 | "table", |
25 | 37 | } |
26 | 38 |
|
27 | | -# Eagerly create aliases in sys.modules for full backward compatibility. |
28 | | -# This is more robust than the lazy __getattr__ approach because it handles |
29 | | -# direct submodule imports (e.g., `import google.cloud.bigtable.row_data`). |
30 | | -for module_name in _LEGACY_MODULE_NAMES: |
31 | | - # Define the old and new module paths |
| 39 | +# update sys.modules to add an alias from old path to new |
| 40 | +for module_name in _CLASSIC_CLIENT_MODULE_NAMES: |
32 | 41 | old_path = f"google.cloud.bigtable.{module_name}" |
33 | 42 | new_path = f".classic.{module_name}" |
34 | 43 |
|
35 | | - # Import the module from its new location |
36 | 44 | module = importlib.import_module(new_path, __name__) |
37 | | - |
38 | | - # Inject the loaded module into sys.modules under its old path. |
39 | | - # This makes Python's import machinery find it automatically. |
40 | 45 | sys.modules[old_path] = module |
41 | | - |
42 | 46 | # Attach the module as an attribute to the current package |
43 | 47 | setattr(sys.modules[__name__], module_name, module) |
44 | 48 |
|
45 | | -# You can also issue a single, general warning that some modules were moved. |
46 | | -warnings.warn( |
47 | | - ( |
48 | | - "Several modules have been moved to the `google.cloud.bigtable.classic` " |
49 | | - "subpackage. The top-level aliases will be removed in a future version." |
50 | | - ), |
51 | | - DeprecationWarning, |
52 | | - stacklevel=2, |
53 | | -) |
54 | | - |
55 | 49 | # previously exported classes |
56 | 50 | from google.cloud.bigtable.classic.client import Client |
57 | 51 | from . import gapic_version |
|
0 commit comments