-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle dynamic imports with deprecation warning
- Loading branch information
1 parent
063e889
commit e62767b
Showing
2 changed files
with
58 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,45 @@ | ||
from . import _version | ||
import warnings | ||
|
||
from .core import PrefectDbtSettings, PrefectDbtRunner | ||
from .cloud import DbtCloudCredentials, DbtCloudJob # noqa | ||
from .cli import ( # noqa | ||
DbtCliProfile, | ||
GlobalConfigs, | ||
MissingExtrasRequireError, | ||
TargetConfigs, | ||
DbtCoreOperation, | ||
) | ||
|
||
try: | ||
from .cli.configs.snowflake import SnowflakeTargetConfigs # noqa | ||
except MissingExtrasRequireError: | ||
pass | ||
|
||
try: | ||
from .cli.configs.bigquery import BigQueryTargetConfigs # noqa | ||
except MissingExtrasRequireError: | ||
pass | ||
|
||
try: | ||
from .cli.configs.postgres import PostgresTargetConfigs # noqa | ||
except MissingExtrasRequireError: | ||
pass | ||
from .cloud import DbtCloudCredentials, DbtCloudJob | ||
|
||
# Define the mapping of CLI-related attributes to their import locations | ||
_public_api: dict[str, tuple[str, str]] = { | ||
"DbtCliProfile": ("prefect_dbt", "cli"), | ||
"GlobalConfigs": ("prefect_dbt", "cli"), | ||
"MissingExtrasRequireError": ("prefect_dbt", "cli"), | ||
"TargetConfigs": ("prefect_dbt", "cli"), | ||
"DbtCoreOperation": ("prefect_dbt", "cli"), | ||
"SnowflakeTargetConfigs": ("prefect_dbt", "cli.configs.snowflake"), | ||
"BigQueryTargetConfigs": ("prefect_dbt", "cli.configs.bigquery"), | ||
"PostgresTargetConfigs": ("prefect_dbt", "cli.configs.postgres"), | ||
} | ||
|
||
# Declare API for type-checkers | ||
__all__ = [ | ||
"__version__", | ||
"PrefectDbtSettings", | ||
"PrefectDbtRunner", | ||
"DbtCloudCredentials", | ||
"DbtCloudJob", | ||
] | ||
|
||
|
||
def __getattr__(attr_name: str): | ||
if attr_name in _public_api: | ||
package, module = _public_api[attr_name] | ||
try: | ||
import importlib | ||
|
||
mod = importlib.import_module(f".{module}", package=package) | ||
result = getattr(mod, attr_name) | ||
return result | ||
except ImportError: | ||
if "configs" in module: # For the database-specific configs | ||
return None | ||
raise | ||
raise AttributeError(f"module '{__name__}' has no attribute '{attr_name}'") | ||
|
||
|
||
__version__ = _version.__version__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters