Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust package top level imports #2269

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ cython_debug/
*.parquet
*.csv

# html files opt-in only
*.html

.DS_Store

# vscode local settings
Expand Down
13 changes: 3 additions & 10 deletions splink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
from splink.internals.linker import Linker
from splink.internals.settings_creator import SettingsCreator

# The following is a workaround for the fact that dependencies of postgres, spark
# and duckdb may not be installed, but we don't want this to prevent import
# The following is a workaround for the fact that dependencies of particular backends
# may not be installed, but we don't want this to prevent import
# of the other backends.

# This enables auto-complete to be used to import the various DBAPIs
# and ensures that typing information is retained so e.g. the arguments autocomplete
# without importing them at runtime
if TYPE_CHECKING:
from splink.internals.duckdb.database_api import DuckDBAPI
from splink.internals.postgres.database_api import PostgresAPI
from splink.internals.spark.database_api import SparkAPI


Expand All @@ -30,12 +29,8 @@ def __getattr__(name):
from splink.internals.duckdb.database_api import DuckDBAPI

return DuckDBAPI
elif name == "PostgresAPI":
from splink.internals.postgres.database_api import PostgresAPI

return PostgresAPI
except ImportError as err:
if name in ["SparkAPI", "DuckDBAPI", "PostgresAPI"]:
if name in ["SparkAPI", "DuckDBAPI"]:
raise ImportError(
f"{name} cannot be imported because its dependencies are not "
"installed. Please `pip install` the required package(s) as "
Expand All @@ -52,9 +47,7 @@ def __getattr__(name):
"ColumnExpression",
"DuckDBAPI",
"Linker",
"PostgresAPI",
"SettingsCreator",
"SparkAPI",
"splink_datasets",
"SQLiteAPI",
]
3 changes: 3 additions & 0 deletions splink/backends/duckdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from splink.internals.duckdb.database_api import DuckDBAPI

__all__ = ["DuckDBAPI"]
3 changes: 3 additions & 0 deletions splink/backends/postgres.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from splink.internals.postgres.database_api import PostgresAPI

__all__ = ["PostgresAPI"]
3 changes: 2 additions & 1 deletion splink/backends/spark.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from splink.internals.spark.database_api import SparkAPI
from splink.internals.spark.jar_location import similarity_jar_location

__all__ = ["similarity_jar_location"]
__all__ = ["similarity_jar_location", "SparkAPI"]
Loading