Skip to content

Commit 83878e5

Browse files
tjhunterTim Hunter
andauthored
change ksexception -> ddsexception, first option (#107)
Co-authored-by: Tim Hunter <tjhunter@cs.stanford.edu>
1 parent 347cf13 commit 83878e5

File tree

13 files changed

+88
-70
lines changed

13 files changed

+88
-70
lines changed

dds/_api.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
from .fun_args import get_arg_ctx
1515
from .introspect import introspect, _accepted_packages
1616
from ._lru_store import LRUCacheStore, default_cache_size
17+
1718
from .store import LocalFileStore, Store
1819
from .structures import (
1920
DDSPath,
20-
KSException,
21+
DDSException,
2122
EvalContext,
2223
PyHash,
2324
ProcessingStage,
@@ -27,6 +28,7 @@
2728
FunctionInteractionsUtils,
2829
FunctionIndirectInteractionUtils,
2930
)
31+
from . import _options
3032

3133
_Out = TypeVar("_Out")
3234
_In = TypeVar("_In")
@@ -64,7 +66,7 @@ def load(path: Union[str, DDSPath, pathlib.Path]) -> Any:
6466
path_ = DDSPathUtils.create(path)
6567
key = _store.fetch_paths([path_]).get(path_)
6668
if key is None:
67-
raise KSException(f"The store {_store} did not return path {path_}")
69+
raise DDSException(f"The store {_store} did not return path {path_}")
6870
else:
6971
return _store.fetch_blob(key)
7072

@@ -85,7 +87,7 @@ def set_store(
8587
global _store
8688
if isinstance(store, Store):
8789
if cache_objects is not None:
88-
raise KSException(
90+
raise DDSException(
8991
f"Cannot provide a caching option and a store object of type 'Store' at the same time"
9092
)
9193
# Directly setting the store
@@ -99,12 +101,12 @@ def set_store(
99101
_store = LocalFileStore(internal_dir, data_dir)
100102
elif store == "dbfs":
101103
if data_dir is None:
102-
raise KSException("Missing data_dir argument")
104+
raise DDSException("Missing data_dir argument")
103105
if internal_dir is None:
104-
raise KSException("Missing internal_dir argument")
106+
raise DDSException("Missing internal_dir argument")
105107
dbutils = dbutils or _fetch_ipython_vars().get("dbutils")
106108
if dbutils is None:
107-
raise KSException(
109+
raise DDSException(
108110
"Missing dbutils objects from input or from arguments."
109111
" You must be using a databricks notebook to use the DBFS store"
110112
)
@@ -117,13 +119,13 @@ def set_store(
117119
DBFSURI.parse(internal_dir), DBFSURI.parse(data_dir), dbutils, commit_type_
118120
)
119121
else:
120-
raise KSException(f"Unknown store {store}")
122+
raise DDSException(f"Unknown store {store}")
121123

122124
if cache_objects is not None:
123125
num_objects: Optional[int] = None
124126

125127
if not isinstance(cache_objects, (int, bool)):
126-
raise KSException(
128+
raise DDSException(
127129
f"cached_object should be int or bool, received type {type(cache_objects)}"
128130
)
129131
if isinstance(cache_objects, bool) and cache_objects:
@@ -148,16 +150,16 @@ def check(s: Union[str, ProcessingStage], cur: ProcessingStage) -> ProcessingSta
148150
if isinstance(s, str):
149151
s = s.upper()
150152
if s not in dir(ProcessingStage):
151-
raise KSException(
153+
raise DDSException(
152154
f"{s} is not a valid stage name. Valid names are {dir(ProcessingStage)}"
153155
)
154156
x = ProcessingStage[s]
155157
elif isinstance(s, ProcessingStage):
156158
x = s
157159
else:
158-
raise KSException(f"Not a valid type: {s} {type(s)}")
160+
raise DDSException(f"Not a valid type: {s} {type(s)}")
159161
if x != cur:
160-
raise KSException(
162+
raise DDSException(
161163
f"Wrong order for the stage name, expected {cur} but got {x}"
162164
)
163165
return cur
@@ -182,15 +184,15 @@ def _eval(
182184

183185
stages = _parse_stages(dds_stages)
184186

185-
extra_debug = dds_extra_debug or False
187+
extra_debug = dds_extra_debug or _options._dds_extra_debug
186188

187189
if not _eval_ctx:
188190
# Not in an evaluation context, create one and introspect
189191
return _eval_new_ctx(fun, path, args, kwargs, export_graph, extra_debug, stages)
190192
else:
191193
if not path:
192-
raise KSException(
193-
"Already in eval() context. Nested eval contexts are not supported"
194+
raise DDSException(
195+
"Already in dds.eval() context. Nested eval contexts are not supported"
194196
)
195197
key = None if path is None else _eval_ctx.requested_paths[path]
196198
t = _time()
@@ -302,7 +304,7 @@ def _eval_new_ctx(
302304

303305
_logger.debug(f"Interaction tree:")
304306
FunctionInteractionsUtils.pprint_tree(
305-
inters, present_blobs, printer=lambda s: _logger.debug(s)
307+
inters, present_blobs, printer=_logger.debug
306308
)
307309
if export_graph is not None:
308310
# Attempt to run the export module:

dds/_introspect_indirect.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from .structures import (
3434
FunctionArgContext,
3535
DDSPath,
36-
KSException,
36+
DDSException,
3737
CanonicalPath,
3838
LocalDepPath,
3939
FunctionIndirectInteractions,
@@ -59,7 +59,7 @@ def _introspect(
5959
return _introspect_fun(obj, gctx, call_stack)
6060
if isinstance(obj, type):
6161
return _introspect_class(obj, gctx, call_stack)
62-
raise KSException(
62+
raise DDSException(
6363
f"Expected function or class, got object of type {type(obj)} instead: {obj}"
6464
)
6565

@@ -74,7 +74,7 @@ def _introspect_class(
7474

7575
fun_module = inspect.getmodule(c)
7676
if fun_module is None:
77-
raise KSException(f"Could not find module: class:{c} module: {fun_module}")
77+
raise DDSException(f"Could not find module: class:{c} module: {fun_module}")
7878
# _logger.debug(f"_introspect: {f}: fun_path={fun_path} fun_module={fun_module}")
7979
fiis_ = gctx.cached_indirect_interactions.get(fun_path)
8080
if fiis_ is not None:
@@ -103,7 +103,7 @@ def _introspect_fun(
103103

104104
fun_module = inspect.getmodule(f)
105105
if fun_module is None:
106-
raise KSException(f"Could not find module: f; {f} module: {fun_module}")
106+
raise DDSException(f"Could not find module: f; {f} module: {fun_module}")
107107
# _logger.debug(f"_introspect: {f}: fun_path={fun_path} fun_module={fun_module}")
108108
ast_f: Union[ast.Lambda, ast.FunctionDef]
109109
if is_lambda(f):
@@ -160,7 +160,7 @@ def inspect_fun(
160160
elif isinstance(node, ast.Lambda):
161161
body = [node.body]
162162
else:
163-
raise KSException(f"unknown ast node {type(node)}")
163+
raise DDSException(f"unknown ast node {type(node)}")
164164
dummy_arg_ctx = FunctionArgContext(OrderedDict(), None)
165165
local_vars = set(
166166
InspectFunction.get_local_vars(body, dummy_arg_ctx) + arg_names
@@ -255,7 +255,9 @@ def inspect_call(
255255
# - parse the arguments
256256
# - introspect the callee
257257
if len(node.args) < 2:
258-
raise KSException(f"Wrong number of args: expected 2+, got {node.args}")
258+
raise DDSException(
259+
f"Wrong number of args: expected 2+, got {node.args}"
260+
)
259261
store_path = InspectFunction._retrieve_store_path(node.args[0], mod, gctx)
260262
called_path_ast = node.args[1]
261263
if isinstance(called_path_ast, ast.Name):
@@ -276,7 +278,7 @@ def inspect_call(
276278
assert isinstance(called_z, AuthorizedObject)
277279
called_fun, call_fun_path = called_z.object_val, called_z.resolved_path
278280
if call_fun_path in call_stack:
279-
raise KSException(
281+
raise DDSException(
280282
f"Detected circular function calls or (co-)recursive calls."
281283
f"This is currently not supported. Change your code to split the "
282284
f"recursive section into a separate function. "
@@ -291,7 +293,7 @@ def inspect_call(
291293
if caller_fun_path == CPU.from_list(["dds", "load"]):
292294
# Evaluation call: get the argument and returns the function interaction for this call.
293295
if len(node.args) != 1:
294-
raise KSException(f"Wrong number of args: expected 1, got {node.args}")
296+
raise DDSException(f"Wrong number of args: expected 1, got {node.args}")
295297
store_path = InspectFunction._retrieve_store_path(node.args[0], mod, gctx)
296298
_logger.debug(f"inspect_call:eval: store_path: {store_path}")
297299
return store_path
@@ -300,7 +302,7 @@ def inspect_call(
300302
raise NotImplementedError("eval")
301303

302304
if caller_fun_path in call_stack:
303-
raise KSException(
305+
raise DDSException(
304306
f"Detected circular function calls or (co-)recursive calls."
305307
f"This is currently not supported. Change your code to split the "
306308
f"recursive section into a separate function. "

dds/_lambda_funs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import inspect
1212
import logging
1313
from ._print_ast import pformat
14-
from .structures import KSException
14+
from .structures import DDSException
1515

1616
_logger = logging.getLogger(__name__)
1717

@@ -79,9 +79,9 @@ def inspect_lambda_condition(fun: Callable[..., Any]) -> ast.Lambda:
7979
_logger.debug(f"_parse_lambda: call_node: {pformat(call_node)}")
8080

8181
if call_node is None:
82-
raise KSException(f"Could not find call node {pformat(call_node)}")
82+
raise DDSException(f"Could not find call node {pformat(call_node)}")
8383

8484
for node in ast.walk(call_node):
8585
if isinstance(node, ast.Lambda):
8686
return node
87-
raise KSException(f"Could not parse lambda {pformat(call_node)}")
87+
raise DDSException(f"Could not parse lambda {pformat(call_node)}")

dds/_options.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
All the options for the package.
3+
4+
TODO: provide eventually a configuration interface.
5+
"""
6+
7+
_dds_extra_debug = True

dds/_retrieve_objects.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
AuthorizedObject,
2323
)
2424
from .structures import (
25-
KSException,
25+
DDSException,
2626
CanonicalPath,
2727
LocalDepPath,
2828
)
@@ -38,7 +38,7 @@ def _mod_path(m: ModuleType) -> CanonicalPath:
3838
def function_path(f: Union[type, FunctionType]) -> CanonicalPath:
3939
mod = inspect.getmodule(f)
4040
if mod is None:
41-
raise KSException(f"Function {f} has no module")
41+
raise DDSException(f"Function {f} has no module")
4242
return CanonicalPath(_mod_path(mod)._path.joinpath(f.__name__))
4343

4444

@@ -209,15 +209,15 @@ def retrieve_object_global(
209209

210210
mod = importlib.import_module(mod_name)
211211
if mod is None:
212-
raise KSException(
212+
raise DDSException(
213213
f"Cannot process path {path}: module {mod_name} cannot be loaded"
214214
)
215215
sub_path = CanonicalPathUtils.tail(path)
216216
dep_path = LocalDepPath(sub_path._path)
217217
# _logger.debug(f"Calling retrieve_object on {dep_path}, {mod}")
218218
z = cls.retrieve_object(dep_path, mod, gctx)
219219
if z is None or isinstance(z, ExternalObject):
220-
raise KSException(
220+
raise DDSException(
221221
f"Cannot load path {path}: this object cannot be retrieved, however "
222222
f"the module '{mod_name}' exists. The typical cause of the issue is "
223223
f"that the module {mod_name} has not been whitelisted for use by DDS. Use the "

dds/codec.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Optional, Dict, List, Union
33

44
from .structures import (
5-
KSException,
5+
DDSException,
66
CodecProtocol,
77
ProtocolRef,
88
SupportedType,
@@ -58,7 +58,7 @@ def get_codec(
5858
# First the reference
5959
if ref:
6060
if ref not in self._protocols:
61-
raise KSException(f"Requested protocol {ref}, which is not registered")
61+
raise DDSException(f"Requested protocol {ref}, which is not registered")
6262
return self._protocols[ref]
6363
# Then the object type
6464
if obj_type is not None:
@@ -68,11 +68,11 @@ def get_codec(
6868
SupportedTypeUtils.from_type(object)
6969
)
7070
if cp is None:
71-
raise KSException(
71+
raise DDSException(
7272
f"Requested protocol for type {obj_type}, which is not registered"
7373
)
7474
return cp
75-
raise KSException(f"No protocol found")
75+
raise DDSException(f"No protocol found")
7676

7777

7878
def _build_default_registry() -> CodecRegistry:

dds/codecs/databricks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from ..codec import CodecRegistry
1717
from ..store import Store, current_timestamp
18-
from ..structures import CodecProtocol, ProtocolRef, FileCodecProtocol, KSException
18+
from ..structures import CodecProtocol, ProtocolRef, FileCodecProtocol, DDSException
1919
from ..structures import PyHash, DDSPath, GenericLocation, SupportedType as ST
2020
from ..structures_utils import SupportedTypeUtils as STU
2121

@@ -186,7 +186,7 @@ def fetch_blob(self, key: PyHash) -> Optional[Any]:
186186
self._dbutils.fs.cp(str(p), str(lp2))
187187
return codec.deserialize_from(lp)
188188
else:
189-
raise KSException(f"{type(codec)} codec")
189+
raise DDSException(f"{type(codec)} codec")
190190

191191
def store_blob(self, key: PyHash, blob: Any, codec: Optional[ProtocolRef]) -> None:
192192
protocol = self._registry.get_codec(STU.from_type(type(blob)), codec)
@@ -205,7 +205,7 @@ def store_blob(self, key: PyHash, blob: Any, codec: Optional[ProtocolRef]) -> No
205205
_logger.debug(f"Temporary copy from DBFS: {lp2} -> {p}")
206206
self._dbutils.fs.cp(lp2, str(p))
207207
else:
208-
raise KSException(f"{type(protocol)} codec")
208+
raise DDSException(f"{type(protocol)} codec")
209209
meta_p = self._blob_meta_path(key)
210210
try:
211211
meta = json.dumps(

0 commit comments

Comments
 (0)