File tree Expand file tree Collapse file tree 4 files changed +37
-18
lines changed Expand file tree Collapse file tree 4 files changed +37
-18
lines changed Original file line number Diff line number Diff line change 1
- from pathlib import Path
2
- import platformdirs
3
- from pydra ._version import __version__
4
-
5
- user_cache_dir = Path (
6
- platformdirs .user_cache_dir (
7
- appname = "pydra" ,
8
- appauthor = "nipype" ,
9
- version = __version__ ,
10
- )
11
- )
1
+ from .misc import user_cache_dir , add_exc_note # noqa: F401
Original file line number Diff line number Diff line change 19
19
from filelock import SoftFileLock
20
20
import attrs .exceptions
21
21
from fileformats .core import FileSet
22
- from . import user_cache_dir
22
+ from . import user_cache_dir , add_exc_note
23
23
24
24
logger = logging .getLogger ("pydra" )
25
25
@@ -197,10 +197,6 @@ def __contains__(self, object_id):
197
197
return object_id in self ._hashes
198
198
199
199
200
- class UnhashableError (ValueError ):
201
- """Error for objects that cannot be hashed"""
202
-
203
-
204
200
def hash_function (obj , ** kwargs ):
205
201
"""Generate hash of object."""
206
202
return hash_object (obj , ** kwargs ).hex ()
@@ -224,7 +220,8 @@ def hash_object(
224
220
try :
225
221
return hash_single (obj , cache )
226
222
except Exception as e :
227
- raise UnhashableError (f"Cannot hash object { obj !r} due to '{ e } '" ) from e
223
+ add_exc_note (e , f"Therefore cannot hash object { obj !r} " )
224
+ raise e
228
225
229
226
230
227
def hash_single (obj : object , cache : Cache ) -> Hash :
Original file line number Diff line number Diff line change
1
+ from pathlib import Path
2
+ import platformdirs
3
+ from pydra ._version import __version__
4
+
5
+ user_cache_dir = Path (
6
+ platformdirs .user_cache_dir (
7
+ appname = "pydra" ,
8
+ appauthor = "nipype" ,
9
+ version = __version__ ,
10
+ )
11
+ )
12
+
13
+
14
+ def add_exc_note (e : Exception , note : str ) -> Exception :
15
+ """Adds a note to an exception in a Python <3.11 compatible way
16
+
17
+ Parameters
18
+ ----------
19
+ e : Exception
20
+ the exception to add the note to
21
+ note : str
22
+ the note to add
23
+
24
+ Returns
25
+ -------
26
+ Exception
27
+ returns the exception again
28
+ """
29
+ if hasattr (e , "add_note" ):
30
+ e .add_note (note )
31
+ else :
32
+ e .args = (e .args [0 ] + "\n " + note ,)
33
+ return e
Original file line number Diff line number Diff line change 11
11
from fileformats .text import TextFile
12
12
from ..hash import (
13
13
Cache ,
14
- UnhashableError ,
15
14
bytes_repr ,
16
15
hash_object ,
17
16
register_serializer ,
You can’t perform that action at this time.
0 commit comments