Skip to content

Commit

Permalink
Merge pull request #2269 from moj-analytical-services/adjust-top-leve…
Browse files Browse the repository at this point in the history
…l-imports

Adjust package top level imports
  • Loading branch information
ADBond authored Jul 18, 2024
2 parents a1434a1 + 1862e82 commit ccb165e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
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"]

0 comments on commit ccb165e

Please sign in to comment.