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

Commit fbb1c1c

Browse files
committed
simplified __init__.py files
1 parent dc61aa9 commit fbb1c1c

2 files changed

Lines changed: 22 additions & 46 deletions

File tree

google/cloud/bigtable/__init__.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
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+
115
import importlib
216
import sys
3-
import warnings
4-
517

6-
_LEGACY_MODULE_NAMES = {
18+
_CLASSIC_CLIENT_MODULE_NAMES = {
719
"app_profile",
820
"backup",
921
"batcher",
@@ -24,34 +36,16 @@
2436
"table",
2537
}
2638

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:
3241
old_path = f"google.cloud.bigtable.{module_name}"
3342
new_path = f".classic.{module_name}"
3443

35-
# Import the module from its new location
3644
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.
4045
sys.modules[old_path] = module
41-
4246
# Attach the module as an attribute to the current package
4347
setattr(sys.modules[__name__], module_name, module)
4448

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-
5549
# previously exported classes
5650
from google.cloud.bigtable.classic.client import Client
5751
from . import gapic_version
Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Copyright 2025 Google LLC
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,39 +15,22 @@
1615
import sys
1716
import importlib
1817
import pkgutil
19-
import warnings
2018

2119
_new_path = "google.cloud.bigtable.admin"
22-
_old_path = __name__ # This will be 'google.cloud.bigtable_admin_v2'
2320

24-
# Issue a warning to users that the old path is deprecated.
25-
warnings.warn(
26-
f"The '{_old_path}' package is deprecated and will be removed in a future "
27-
f"version. Please use '{_new_path}' instead.",
28-
DeprecationWarning,
29-
stacklevel=2,
30-
)
31-
32-
# 1. Import the real top-level package from its new location.
21+
# update sys.modules to add an alias from this path to new
3322
_real_package = importlib.import_module(_new_path)
23+
sys.modules[__name__] = _real_package
3424

35-
# 2. Immediately replace this alias package in the module cache with the real one.
36-
sys.modules[_old_path] = _real_package
37-
38-
# 3. Eagerly walk and import all submodules of the real package.
39-
# This populates sys.modules with all the canonical submodule paths
40-
# (e.g., 'google.cloud.bigtable.admin.types', etc.).
25+
# iterate and import all submodules to populate sys.modules
4126
for _, name, _ in pkgutil.walk_packages(
4227
path=_real_package.__path__,
4328
prefix=_real_package.__name__ + ".",
4429
):
4530
importlib.import_module(name)
4631

47-
# 4. Now that they're all loaded, create an alias for each submodule.
48-
# We iterate over a copy of the keys, as the dictionary size will change.
32+
# create an alias for each submodule
4933
for name in list(sys.modules.keys()):
50-
# Check if a loaded module is a submodule of our new package...
5134
if name.startswith(_new_path + "."):
52-
# ...and create a corresponding alias using the old path prefix.
53-
old_submodule_path = name.replace(_new_path, _old_path, 1)
35+
old_submodule_path = name.replace(_new_path, __name__, 1)
5436
sys.modules[old_submodule_path] = sys.modules[name]

0 commit comments

Comments
 (0)