Skip to content

Commit 4f559a5

Browse files
committed
error earlier
1 parent 6e766a7 commit 4f559a5

2 files changed

Lines changed: 15 additions & 44 deletions

File tree

pins/constructors.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .boards import BaseBoard, BoardManual, BoardRsConnect, board_deparse
1111
from .cache import PinsAccessTimeCache, PinsCache, PinsRscCacheMapper, prefix_cache
1212
from .config import get_cache_dir, get_data_dir
13+
from .errors import PinsError
1314

1415
# Kept here for backward-compatibility reasons
1516
# Note that this is not a constructor, but a function to represent them.
@@ -625,5 +626,10 @@ def board_databricks(path, versioned=True, cache=DEFAULT, allow_pickle_read=None
625626
0 1 a 3
626627
1 2 b 4
627628
"""
628-
629+
try:
630+
import databricks.sdk # noqa: F401
631+
except ModuleNotFoundError:
632+
raise PinsError(
633+
"Install the `databricks-sdk` package for Databricks board support."
634+
)
629635
return board("dbc", path, versioned, cache, allow_pickle_read)

pins/databricks/fs.py

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ def rm(self, path, recursive=True, maxdepth=None) -> None:
5353

5454
@staticmethod
5555
def _databricks_put(lpath, rpath):
56-
try:
57-
from databricks.sdk import WorkspaceClient
58-
except ModuleNotFoundError:
59-
raise PinsError(
60-
"Install the `databricks-sdk` package for Databricks board support."
61-
)
56+
from databricks.sdk import WorkspaceClient
6257

6358
w = WorkspaceClient()
6459
path = Path(lpath).absolute()
@@ -80,12 +75,7 @@ def _upload_files(path):
8075
_upload_files(path)
8176

8277
def _databricks_get(self, board, rpath, lpath, recursive=False, **kwargs):
83-
try:
84-
from databricks.sdk import WorkspaceClient
85-
except ModuleNotFoundError:
86-
raise PinsError(
87-
"Install the `databricks-sdk` package for Databricks board support."
88-
)
78+
from databricks.sdk import WorkspaceClient
8979

9080
w = WorkspaceClient()
9181
file_type = self._databricks_is_type(rpath)
@@ -110,12 +100,7 @@ def _get_files(path, recursive, **kwargs):
110100
_get_files(rpath, recursive, **kwargs)
111101

112102
def _databricks_open(self, path):
113-
try:
114-
from databricks.sdk import WorkspaceClient
115-
except ModuleNotFoundError:
116-
raise PinsError(
117-
"Install the `databricks-sdk` package for Databricks board support."
118-
)
103+
from databricks.sdk import WorkspaceClient
119104

120105
if not self._databricks_exists(path):
121106
raise PinsError(f"File or directory does not exist at path: {path}")
@@ -134,13 +119,8 @@ def _databricks_exists(self, path: str):
134119

135120
@staticmethod
136121
def _databricks_is_type(path: str):
137-
try:
138-
from databricks.sdk import WorkspaceClient
139-
from databricks.sdk.errors import NotFound
140-
except ModuleNotFoundError:
141-
raise PinsError(
142-
"Install the `databricks-sdk` package for Databricks board support."
143-
)
122+
from databricks.sdk import WorkspaceClient
123+
from databricks.sdk.errors import NotFound
144124

145125
w = WorkspaceClient()
146126
try:
@@ -156,12 +136,7 @@ def _databricks_is_type(path: str):
156136
return "file"
157137

158138
def _databricks_ls(self, path, detail):
159-
try:
160-
from databricks.sdk import WorkspaceClient
161-
except ModuleNotFoundError:
162-
raise PinsError(
163-
"Install the `databricks-sdk` package for Databricks board support."
164-
)
139+
from databricks.sdk import WorkspaceClient
165140

166141
if not self._databricks_exists(path):
167142
raise PinsError(f"File or directory does not exist at path: {path}")
@@ -190,12 +165,7 @@ def _databricks_ls(self, path, detail):
190165
return items
191166

192167
def _databricks_rm_dir(self, path):
193-
try:
194-
from databricks.sdk import WorkspaceClient
195-
except ModuleNotFoundError:
196-
raise PinsError(
197-
"Install the `databricks-sdk` package for Databricks board support."
198-
)
168+
from databricks.sdk import WorkspaceClient
199169

200170
w = WorkspaceClient()
201171
raw_contents = w.files.list_directory_contents(path)
@@ -211,12 +181,7 @@ def _databricks_rm_dir(self, path):
211181

212182
@staticmethod
213183
def _databricks_mkdir(path):
214-
try:
215-
from databricks.sdk import WorkspaceClient
216-
except ModuleNotFoundError:
217-
raise PinsError(
218-
"Install the `databricks-sdk` package for Databricks board support."
219-
)
184+
from databricks.sdk import WorkspaceClient
220185

221186
w = WorkspaceClient()
222187
w.files.create_directory(path)

0 commit comments

Comments
 (0)