cdxcore 0.1.29__py3-none-any.whl → 0.1.31__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cdxcore might be problematic. Click here for more details.
- cdxcore/__init__.py +1 -1
- cdxcore/subdir.py +47 -35
- {cdxcore-0.1.29.dist-info → cdxcore-0.1.31.dist-info}/METADATA +1 -1
- {cdxcore-0.1.29.dist-info → cdxcore-0.1.31.dist-info}/RECORD +8 -8
- tests/test_subdir.py +74 -15
- {cdxcore-0.1.29.dist-info → cdxcore-0.1.31.dist-info}/WHEEL +0 -0
- {cdxcore-0.1.29.dist-info → cdxcore-0.1.31.dist-info}/licenses/LICENSE +0 -0
- {cdxcore-0.1.29.dist-info → cdxcore-0.1.31.dist-info}/top_level.txt +0 -0
cdxcore/__init__.py
CHANGED
cdxcore/subdir.py
CHANGED
|
@@ -628,12 +628,9 @@ class CacheController( object ):
|
|
|
628
628
|
When a parameter object of this type
|
|
629
629
|
is assigned to a :class:`cdxcore.subdir.SubDir`,
|
|
630
630
|
then it is passed on when sub-directories are
|
|
631
|
-
created. This way all
|
|
632
|
-
caching behaviour.
|
|
631
|
+
created. This way all sub directories have the same
|
|
632
|
+
caching behaviour.
|
|
633
633
|
|
|
634
|
-
See :class:`cdxcore.subdir.CacheController` for
|
|
635
|
-
a list of control parameters.
|
|
636
|
-
|
|
637
634
|
Parameters
|
|
638
635
|
----------
|
|
639
636
|
exclude_arg_types : list[type], optional
|
|
@@ -803,16 +800,18 @@ class SubDir(object):
|
|
|
803
800
|
Parent directory.
|
|
804
801
|
|
|
805
802
|
If ``parent`` is a :class:`cdxcore.subdir.SubDir` then its parameters are used
|
|
806
|
-
as default values
|
|
803
|
+
as default values.
|
|
807
804
|
|
|
808
805
|
ext : str | None, default ``None``
|
|
809
|
-
Extension for files managed by this ``SubDir``. All files will share the same extension.
|
|
806
|
+
Extension for files managed by this ``SubDir``. All files managed by ``self`` will share the same extension.
|
|
810
807
|
|
|
811
|
-
If set to ``""`` no extension is assigned to this directory. That
|
|
812
|
-
|
|
808
|
+
If set to ``""`` no extension is assigned to this directory. That mean that
|
|
809
|
+
all files are considered. For example,
|
|
810
|
+
:meth:`cdxcore.subdir.SubDir.files` then returns all files contained in the directory, not
|
|
813
811
|
just files with a specific extension.
|
|
814
812
|
|
|
815
|
-
If ``None``, use
|
|
813
|
+
If ``ext`` is ``None``, then use ``parent.ext`` or if ``parent`` was provided, or otherwise
|
|
814
|
+
the extension defined by ``fmt``:
|
|
816
815
|
|
|
817
816
|
* 'pck' for the default PICKLE format.
|
|
818
817
|
* 'json' for JSON_PLAIN.
|
|
@@ -823,7 +822,9 @@ class SubDir(object):
|
|
|
823
822
|
fmt : :class:`cdxcore.subdir.Format` | None, default ``Format.PICKLE``
|
|
824
823
|
|
|
825
824
|
One of the :class:`cdxcore.subdir.Format` codes.
|
|
826
|
-
|
|
825
|
+
|
|
826
|
+
If ``ext`` is left to ``None`` and ``parent`` is ``None``
|
|
827
|
+
then setting the a format will also set the corrsponding ``ext``.
|
|
827
828
|
|
|
828
829
|
create_directory : bool | None, default ``False``
|
|
829
830
|
|
|
@@ -836,7 +837,7 @@ class SubDir(object):
|
|
|
836
837
|
cache_controller : :class:`cdxcore.subdir.CacheController` | None, default ``None``
|
|
837
838
|
|
|
838
839
|
An object which fine-tunes the behaviour of :meth:`cdxcore.subdir.SubDir.cache`.
|
|
839
|
-
See
|
|
840
|
+
See :class:`cdxcore.subdir.CacheController` documentation for further details.
|
|
840
841
|
|
|
841
842
|
delete_everything : bool, default ``False``
|
|
842
843
|
|
|
@@ -849,7 +850,7 @@ class SubDir(object):
|
|
|
849
850
|
|
|
850
851
|
Note, however, that this will only be executed once the object is garbage collected.
|
|
851
852
|
|
|
852
|
-
Default is, for some good reason, ``False``.
|
|
853
|
+
Default is, for some good reason, is ``False``.
|
|
853
854
|
"""
|
|
854
855
|
|
|
855
856
|
class __RETURN_SUB_DIRECTORY(object):
|
|
@@ -907,6 +908,7 @@ class SubDir(object):
|
|
|
907
908
|
|
|
908
909
|
"""
|
|
909
910
|
create_directory = bool(create_directory) if not create_directory is None else None
|
|
911
|
+
ext = SubDir._extract_ext(ext) if not ext is None else None
|
|
910
912
|
|
|
911
913
|
# copy constructor support
|
|
912
914
|
if isinstance(name, SubDir):
|
|
@@ -918,6 +920,7 @@ class SubDir(object):
|
|
|
918
920
|
self._cctrl = name._cctrl if cache_controller is None else cache_controller
|
|
919
921
|
self._tclean = False # "_clean" is not inherited
|
|
920
922
|
if delete_everything: raise ValueError( "Cannot use 'delete_everything' when cloning a directory")
|
|
923
|
+
assert self._ext=="" or self._ext==self.EXT_FMT_AUTO or self._ext[0] == ".", ("Extension error", self._ext)
|
|
921
924
|
return
|
|
922
925
|
|
|
923
926
|
# reconstruction from a dictionary
|
|
@@ -930,6 +933,7 @@ class SubDir(object):
|
|
|
930
933
|
self._cctrl = name['_cctrl'] if cache_controller is None else cache_controller
|
|
931
934
|
self._tclean = name['_tclean']
|
|
932
935
|
if delete_everything: raise ValueError( "Cannot use 'delete_everything' when cloning a directory")
|
|
936
|
+
assert self._ext=="" or self._ext==self.EXT_FMT_AUTO or self._ext[0] == ".", ("Extension error", self._ext)
|
|
933
937
|
return
|
|
934
938
|
|
|
935
939
|
# parent
|
|
@@ -965,12 +969,15 @@ class SubDir(object):
|
|
|
965
969
|
_ext = name[ext_i+3:]
|
|
966
970
|
if not ext is None and ext != _ext:
|
|
967
971
|
raise ValueError( txtfmt("Canot specify an extension both in the name string ('%s') and as 'ext' ('%s')", _name, ext))
|
|
968
|
-
ext = _ext
|
|
972
|
+
ext = SubDir._extract_ext(_ext)
|
|
969
973
|
name = name[:ext_i]
|
|
974
|
+
del _ext
|
|
975
|
+
del ext_i
|
|
970
976
|
if ext is None:
|
|
971
977
|
self._ext = self.EXT_FMT_AUTO if parent is None else parent._ext
|
|
972
978
|
else:
|
|
973
|
-
self._ext =
|
|
979
|
+
self._ext = ext
|
|
980
|
+
assert self._ext=="" or self._ext==self.EXT_FMT_AUTO or self._ext[0] == ".", ("Extension error", self._ext)
|
|
974
981
|
|
|
975
982
|
# create_directory
|
|
976
983
|
if create_directory is None:
|
|
@@ -1050,7 +1057,8 @@ class SubDir(object):
|
|
|
1050
1057
|
If neither of these matches the first character, ``name``
|
|
1051
1058
|
is returned as is.
|
|
1052
1059
|
|
|
1053
|
-
This function does not support ``"?"
|
|
1060
|
+
This function does not support ``"?"`` because ``"?"`` used in the constructor
|
|
1061
|
+
represents a new directory every time it is used.
|
|
1054
1062
|
"""
|
|
1055
1063
|
if len(name) < 2 or name[0] not in ['.','!','~'] or name[1] not in ["\\","/"]:
|
|
1056
1064
|
return name
|
|
@@ -1146,6 +1154,7 @@ class SubDir(object):
|
|
|
1146
1154
|
Returns the common extension of the files in this directory, including leading ``'.'``.
|
|
1147
1155
|
Resolves ``"*"`` into the extension associated with the current :class:`cdxcore.subdir.Format`.
|
|
1148
1156
|
"""
|
|
1157
|
+
assert self._ext=="" or self._ext==self.EXT_FMT_AUTO or self._ext[0] == ".", ("Extension error", self._ext)
|
|
1149
1158
|
return self._ext if self._ext != self.EXT_FMT_AUTO else self._auto_ext(self._fmt)
|
|
1150
1159
|
|
|
1151
1160
|
def auto_ext( self, ext_or_fmt : str|Format = None ) -> str:
|
|
@@ -1167,10 +1176,13 @@ class SubDir(object):
|
|
|
1167
1176
|
The extension with leading ``'.'``.
|
|
1168
1177
|
"""
|
|
1169
1178
|
if isinstance(ext_or_fmt, Format):
|
|
1170
|
-
|
|
1179
|
+
r = self._auto_ext(ext_or_fmt)
|
|
1171
1180
|
else:
|
|
1172
1181
|
ext = self._ext if ext_or_fmt is None else SubDir._extract_ext(ext_or_fmt)
|
|
1173
|
-
|
|
1182
|
+
r = ext if ext != self.EXT_FMT_AUTO else self._auto_ext(self._fmt)
|
|
1183
|
+
del ext
|
|
1184
|
+
assert r=="" or r[0] == ".", ("Extension error", self._ext, ext_or_fmt)
|
|
1185
|
+
return r
|
|
1174
1186
|
|
|
1175
1187
|
def auto_ext_fmt( self, *, ext : str = None, fmt : Format = None ) -> tuple[str]:
|
|
1176
1188
|
"""
|
|
@@ -1266,6 +1278,7 @@ class SubDir(object):
|
|
|
1266
1278
|
# remove internal characters
|
|
1267
1279
|
verify( ext[0] != "!", "Extension '%s' cannot start with '!' (this symbol indicates the temp directory)", ext, exception=ValueError )
|
|
1268
1280
|
verify( ext[0] != "~", "Extension '%s' cannot start with '~' (this symbol indicates the user's directory)", ext, exception=ValueError )
|
|
1281
|
+
verify( ext[0] != "?", "Extension '%s' cannot start with '?' (this symbol indicates a temporary directory)", ext, exception=ValueError )
|
|
1269
1282
|
return "." + ext
|
|
1270
1283
|
|
|
1271
1284
|
# -- public utilities --
|
|
@@ -1302,6 +1315,7 @@ class SubDir(object):
|
|
|
1302
1315
|
verify( file[0] != "?", "Key '%s' cannot start with '?' (this symbol indicates the user's directory)", file, exception=ValueError )
|
|
1303
1316
|
|
|
1304
1317
|
ext = self.auto_ext( ext )
|
|
1318
|
+
assert len(ext) == 0 or ext[0]==".", ("Extension error", ext)
|
|
1305
1319
|
if len(ext) > 0 and file[-len(ext):] != ext:
|
|
1306
1320
|
return self._path + file + ext
|
|
1307
1321
|
return self._path + file
|
|
@@ -2924,7 +2938,7 @@ class SubDir(object):
|
|
|
2924
2938
|
|
|
2925
2939
|
You can define certain types as non-functional for *all* functions wrapped
|
|
2926
2940
|
by :meth:`cdxcore.subdir.SubDir.cache` when construcing
|
|
2927
|
-
the :class:`
|
|
2941
|
+
the :class:`cdxcore.cache.CacheController` parameter for in :class:`cdxcore.subdir.SubDir`:
|
|
2928
2942
|
|
|
2929
2943
|
.. code-block:: python
|
|
2930
2944
|
|
|
@@ -2949,7 +2963,7 @@ class SubDir(object):
|
|
|
2949
2963
|
|
|
2950
2964
|
Key default behaviours of :class:`cdxcore.uniquehash.NamedUniqueHash`:
|
|
2951
2965
|
|
|
2952
|
-
*
|
|
2966
|
+
* :class:`cdxcore.uniquehash.NamedUniqueHash` hashes objects via their ``__dict__`` or ``__slot__`` members.
|
|
2953
2967
|
This can be overwritten for a class by implementing ``__unique_hash__``; see :class:`cdxcore.uniquehash.NamedUniqueHash`.
|
|
2954
2968
|
|
|
2955
2969
|
* Function members of objects or any members starting with '_' are not hashed
|
|
@@ -2980,12 +2994,9 @@ class SubDir(object):
|
|
|
2980
2994
|
return x*y
|
|
2981
2995
|
|
|
2982
2996
|
We can also use a function to generate a ``label``. In that case all parameters
|
|
2983
|
-
to the function including its ``
|
|
2984
|
-
we eat any parameters we are not interested in with ``** _``:
|
|
2985
|
-
|
|
2986
|
-
.. code-block:: python
|
|
2997
|
+
to the function including its ``func_name`` are passed to the function.::
|
|
2987
2998
|
|
|
2988
|
-
@cache.cache("0.1", label=lambda x,y
|
|
2999
|
+
@cache.cache("0.1", label=lambda x,y: f"h({x},{y})", exclude_args='debug')
|
|
2989
3000
|
def h(x,y,debug=False):
|
|
2990
3001
|
if debug:
|
|
2991
3002
|
print(f"h(x={x},y={y})")
|
|
@@ -3019,7 +3030,7 @@ class SubDir(object):
|
|
|
3019
3030
|
|
|
3020
3031
|
.. code-block:: python
|
|
3021
3032
|
|
|
3022
|
-
@cache.cache("0.1", uid=lambda x,y
|
|
3033
|
+
@cache.cache("0.1", uid=lambda x,y: f"h2({x},{y})", exclude_args='debug')
|
|
3023
3034
|
def h2(x,y,debug=False):
|
|
3024
3035
|
if debug:
|
|
3025
3036
|
print(f"h(x={x},y={y})")
|
|
@@ -3136,7 +3147,8 @@ class SubDir(object):
|
|
|
3136
3147
|
a.x = 2
|
|
3137
3148
|
_ = a.f(y=1) # 'a' changed: compute f and store result
|
|
3138
3149
|
b = A(x=2)
|
|
3139
|
-
_ = b.f(y=1) # same unique call ID as previous call
|
|
3150
|
+
_ = b.f(y=1) # same unique call ID as previous call
|
|
3151
|
+
# -> restore result from disk
|
|
3140
3152
|
|
|
3141
3153
|
**WARNING**
|
|
3142
3154
|
:class:`cdxcore.uniquehash.UniqueHash` does *not* by default process members of objects or dictionaries
|
|
@@ -3157,7 +3169,8 @@ class SubDir(object):
|
|
|
3157
3169
|
.. code-block:: python
|
|
3158
3170
|
|
|
3159
3171
|
from cdxcore.subdir import SubDir, version
|
|
3160
|
-
cache = SubDir("!/.cache", cache_controller
|
|
3172
|
+
cache = SubDir("!/.cache", cache_controller =
|
|
3173
|
+
CacheController(debug_verbose=Context("all")))
|
|
3161
3174
|
cache.delete_all_content() # for illustration
|
|
3162
3175
|
|
|
3163
3176
|
class A(object):
|
|
@@ -3232,7 +3245,8 @@ class SubDir(object):
|
|
|
3232
3245
|
@cache.cache_class("0.1")
|
|
3233
3246
|
class A(object):
|
|
3234
3247
|
|
|
3235
|
-
|
|
3248
|
+
# NOTE: 'self' is not passed to the lambda function "uid"
|
|
3249
|
+
@cache.cache_init(uid=lambda x, debug: f"A.__init__(x={x})")
|
|
3236
3250
|
def __init__(self, x, debug):
|
|
3237
3251
|
if debug:
|
|
3238
3252
|
print("__init__",x)
|
|
@@ -3373,8 +3387,6 @@ class SubDir(object):
|
|
|
3373
3387
|
function name. If there is already a parameter ``func_name`` for the function, an error will be raised.
|
|
3374
3388
|
Use this flag to change the parameter name. Example::
|
|
3375
3389
|
|
|
3376
|
-
.. code-block:: python
|
|
3377
|
-
|
|
3378
3390
|
from cdxcore.subdir import SubDir
|
|
3379
3391
|
cache = SubDir("?/temp")
|
|
3380
3392
|
|
|
@@ -3458,7 +3470,7 @@ class SubDir(object):
|
|
|
3458
3470
|
xy = f( x=1, y=2 )
|
|
3459
3471
|
uid = f.cache_info.filename
|
|
3460
3472
|
"""
|
|
3461
|
-
return
|
|
3473
|
+
return _CacheCallable(subdir = self,
|
|
3462
3474
|
version = version,
|
|
3463
3475
|
dependencies = dependencies,
|
|
3464
3476
|
label = label,
|
|
@@ -3729,7 +3741,7 @@ def _expected_str_fmt_args(fmt: str):
|
|
|
3729
3741
|
keywords=kws
|
|
3730
3742
|
)
|
|
3731
3743
|
|
|
3732
|
-
class
|
|
3744
|
+
class _CacheCallable(object):
|
|
3733
3745
|
"""
|
|
3734
3746
|
Wrapper for a cached function.
|
|
3735
3747
|
|
|
@@ -3774,7 +3786,7 @@ class CacheCallable(object):
|
|
|
3774
3786
|
which = "'uid'" if not uid is None else "'label'"
|
|
3775
3787
|
if isinstance( F, str ):
|
|
3776
3788
|
r = _expected_str_fmt_args( F )
|
|
3777
|
-
if
|
|
3789
|
+
if r.positional + len(r.posindices) > 0:
|
|
3778
3790
|
raise ValueError("f{which} '{F}' cannot have positional arguments (empty brackets {} or brackets with integer position {1}). Use only named arguments.")
|
|
3779
3791
|
self._uid_label_params = list(r.keywords)
|
|
3780
3792
|
del r
|
|
@@ -3860,7 +3872,7 @@ class CacheCallable(object):
|
|
|
3860
3872
|
init_cache_callable = getattr(C__init__, "init_cache_callable", None)
|
|
3861
3873
|
if init_cache_callable is None:
|
|
3862
3874
|
raise RuntimeError("'{F.__qualname__}': must also decorate __init__")
|
|
3863
|
-
assert type(init_cache_callable).__name__ ==
|
|
3875
|
+
assert type(init_cache_callable).__name__ == _CacheCallable.__name__, (f"*** Internal error: '{C.__qualname__}': __init__ has wrong type for 'init_cache_callable': {type(init_cache_callable)} ?")
|
|
3864
3876
|
|
|
3865
3877
|
C__init__.init_cache_callable = None # tell the __init__ wrapper we have processed this information
|
|
3866
3878
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
cdxcore/__init__.py,sha256=
|
|
1
|
+
cdxcore/__init__.py,sha256=WN94f-YsRGI6f9O-uipJ9qL-e5iDhOxxPVj9ABkmmqI,127
|
|
2
2
|
cdxcore/config.py,sha256=RaxpAnTEyGXLiq-1O2prXFBb2sdyqB6hHDHPAFGe2k0,98472
|
|
3
3
|
cdxcore/deferred.py,sha256=41buUit1SOAnhVSrzlzM5hd2OOhnAS2QRDSWEpjXfdE,43138
|
|
4
4
|
cdxcore/dynalimits.py,sha256=TXEwa4wCdeM5epG1ceezaHwvmhnbU-oXlXpHNbOMQR8,11293
|
|
@@ -9,12 +9,12 @@ cdxcore/jcpool.py,sha256=Vw8o8S4_qTVQNIr2sRaBR_kHz_wO0zpYs0QjlKSYFz8,27280
|
|
|
9
9
|
cdxcore/npio.py,sha256=SVpKkFt6lyRogkns-oky0wEiWgVTalgB0OdaSvyWtlU,24212
|
|
10
10
|
cdxcore/npshm.py,sha256=9buYPNJoNlw69NZQ-nLF13PEWBWNx51a0gjQw5Gc24U,18368
|
|
11
11
|
cdxcore/pretty.py,sha256=FsI62rlaqRX1E-uPCSnu0M4UoCQ5Z55TDvYPnzTNO70,17220
|
|
12
|
-
cdxcore/subdir.py,sha256=
|
|
12
|
+
cdxcore/subdir.py,sha256=2AFW0BJ2tP6Xt40SEYTgd3diC3RlObHxVswrLHD6Auo,191404
|
|
13
13
|
cdxcore/uniquehash.py,sha256=j2pDmDPdDX4mZ8YIpZLbg-qWXQJPuR7OvZSTGnvxwL0,50827
|
|
14
14
|
cdxcore/util.py,sha256=dqCEhrDvUM4qjeUwb6n8jPfS8WC4Navcj83gDjXfRFE,39349
|
|
15
15
|
cdxcore/verbose.py,sha256=vsjGTVnAHMPg2L2RfsowWKKPjUSnQJ3F653vDTydBkI,30223
|
|
16
16
|
cdxcore/version.py,sha256=pmbFIZ6Egif_ppZNFJRqEZO0HBffIzkn-hkY6HpkMpU,27325
|
|
17
|
-
cdxcore-0.1.
|
|
17
|
+
cdxcore-0.1.31.dist-info/licenses/LICENSE,sha256=M-cisgK9kb1bqVRJ7vrCxHcMQQfDxdY3c2YFJJWfNQg,1090
|
|
18
18
|
docs/source/conf.py,sha256=yn3LYgw3sT45mUyll-B2emVp6jg7H6KfAHOcBg_MNv4,4182
|
|
19
19
|
tests/test_config.py,sha256=N86mH3y7k3LXEmU8uPLfrmRMZ-80VhlD35nBbpLmebg,15617
|
|
20
20
|
tests/test_deferred.py,sha256=4Xsb76r-XqHKiBuHa4jbErjMWbrgHXfPwewzzY4lf9Y,7922
|
|
@@ -23,7 +23,7 @@ tests/test_jcpool.py,sha256=bcGC3UcJ7SOHVgzZ-cooEJgncLWmhutBfqH7P5qB-iw,7901
|
|
|
23
23
|
tests/test_npio.py,sha256=v-_oO7bj9obSJD4TBk4gBM8ACL62DMNjyQ-iZmvOOdw,3039
|
|
24
24
|
tests/test_npshm.py,sha256=uVivQ3zI4_v3a4qDIY-1gjf5_2pEtKM00VlC3hubUl8,3270
|
|
25
25
|
tests/test_pretty.py,sha256=pVwTBjm3XqwEf2jq5GdZvT4cDSTGqiQFBMLqmGJYuB0,11644
|
|
26
|
-
tests/test_subdir.py,sha256=
|
|
26
|
+
tests/test_subdir.py,sha256=YNJ4rRBAs6ZGhhCFw8ca95RARBzBIPQZ7tthoAx0-Jo,18093
|
|
27
27
|
tests/test_uniquehash.py,sha256=sRYhdVezNViEnpf8f0GjWfJ-fgghjEFnJCM0sUBVshM,24985
|
|
28
28
|
tests/test_util.py,sha256=mwtz3o_RiLNn808928xP4jawHmGNxzUXiatMh0zBc3o,24342
|
|
29
29
|
tests/test_verbose.py,sha256=zXheIqAVOnwML2zsCjLugjYzB_KNzU_S4Xu2CSb4o10,4723
|
|
@@ -34,7 +34,7 @@ tmp/npsh1.py,sha256=mNucUl2-jNmE84GlMlliB4aJ0UQ9FqdymgcY_9mLeZY,15432
|
|
|
34
34
|
tmp/sharedarray.py,sha256=dNOT1ObCc3nM3qA3OA508NcENIBnkmWMxRPCqvMVa8A,12862
|
|
35
35
|
up/git_message.py,sha256=EfSH7Pit3ZoCiRqSMwRCUN_QyuwreU4LTIyGSutBlm4,123
|
|
36
36
|
up/pip_modify_setup.py,sha256=Esaml4yA9tFsqxLhk5bWSwvKCURONjQqfyChgFV2TSY,1584
|
|
37
|
-
cdxcore-0.1.
|
|
38
|
-
cdxcore-0.1.
|
|
39
|
-
cdxcore-0.1.
|
|
40
|
-
cdxcore-0.1.
|
|
37
|
+
cdxcore-0.1.31.dist-info/METADATA,sha256=S6lCt49Ic3mlpC0lMZRuwjDJp4pELtZhK1icowdUTAw,5939
|
|
38
|
+
cdxcore-0.1.31.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
39
|
+
cdxcore-0.1.31.dist-info/top_level.txt,sha256=phNSwCyJFe7UP2YMoi8o6ykhotatlIbJHjTp9EHM51k,26
|
|
40
|
+
cdxcore-0.1.31.dist-info/RECORD,,
|
tests/test_subdir.py
CHANGED
|
@@ -196,15 +196,28 @@ class Test(unittest.TestCase):
|
|
|
196
196
|
# wrong version
|
|
197
197
|
|
|
198
198
|
def test_new(self):
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
199
|
+
subdir0 = SubDir("my_directory") # relative to current working directory
|
|
200
|
+
subdir1 = SubDir("./my_directory") # relative to current working directory
|
|
201
|
+
subdir2 = SubDir("~/my_directory") # relative to home directory
|
|
202
|
+
subdir3 = SubDir("!/my_directory") # relative to default temp directory
|
|
203
|
+
|
|
204
|
+
subdir11 = SubDir("my_directory", ".") # relative to home directory
|
|
205
|
+
subdir22 = SubDir("my_directory", "~") # relative to default temp directory
|
|
206
|
+
subdir33 = SubDir("my_directory", "!") # relative to current directory
|
|
207
|
+
subdir44 = SubDir("my_directory", subdir3) # subdir2 is relative to `subdir`
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
self.assertEqual( subdir0.path, subdir11.path )
|
|
211
|
+
self.assertEqual( subdir1.path, subdir11.path )
|
|
212
|
+
self.assertEqual( subdir2.path, subdir22.path )
|
|
213
|
+
self.assertEqual( subdir3.path, subdir33.path )
|
|
214
|
+
self.assertEqual( subdir3.path + "my_directory/", subdir44.path )
|
|
215
|
+
|
|
216
|
+
subdir1 = SubDir("?/test")
|
|
217
|
+
subdir2 = SubDir("?/test")
|
|
218
|
+
|
|
219
|
+
self.assertNotEqual( subdir1.path, subdir2.path )
|
|
220
|
+
del subdir1, subdir2
|
|
208
221
|
|
|
209
222
|
# extension handling
|
|
210
223
|
|
|
@@ -218,7 +231,16 @@ class Test(unittest.TestCase):
|
|
|
218
231
|
self.assertEqual( subdir.ext, ".json" )
|
|
219
232
|
subdir = subdir("", fmt=SubDir.PICKLE )
|
|
220
233
|
self.assertEqual( subdir.ext, ".pck" )
|
|
221
|
-
|
|
234
|
+
|
|
235
|
+
subdir0 = SubDir("!/temp;*.bin")
|
|
236
|
+
subdir1 = SubDir("!/temp", ext="bin")
|
|
237
|
+
subdir2 = SubDir("!/temp", ext=".bin")
|
|
238
|
+
self.assertEqual( subdir0, subdir1 )
|
|
239
|
+
self.assertEqual( subdir0, subdir2 )
|
|
240
|
+
|
|
241
|
+
with self.assertRaises(ValueError):
|
|
242
|
+
subdir = SubDir("!/temp;*.bin", ext="notbin")
|
|
243
|
+
|
|
222
244
|
# version
|
|
223
245
|
|
|
224
246
|
version = "0.1"
|
|
@@ -245,6 +267,37 @@ class Test(unittest.TestCase):
|
|
|
245
267
|
test_format( SubDir.BLOSC, True )
|
|
246
268
|
test_format( SubDir.GZIP, True )
|
|
247
269
|
test_format( SubDir.JSON_PICKLE )
|
|
270
|
+
|
|
271
|
+
# copy constructor with overwrite
|
|
272
|
+
|
|
273
|
+
d1 = SubDir("?/test_subdir", ext="e1")
|
|
274
|
+
d2 = SubDir(d1)
|
|
275
|
+
self.assertEqual( d1.path, d2.path )
|
|
276
|
+
self.assertEqual( d1.fmt, d2.fmt )
|
|
277
|
+
self.assertEqual( d1.ext, d2.ext )
|
|
278
|
+
|
|
279
|
+
d1 = SubDir("?/test_subdir", ext="e1")
|
|
280
|
+
d2 = SubDir(d1, ext="e2")
|
|
281
|
+
self.assertEqual( d1.path, d2.path )
|
|
282
|
+
self.assertEqual( d1.fmt, d2.fmt )
|
|
283
|
+
self.assertEqual( d1.ext, ".e1" )
|
|
284
|
+
self.assertEqual( d2.ext, ".e2" )
|
|
285
|
+
|
|
286
|
+
d1 = SubDir("?/test_subdir", fmt=SubDir.BLOSC )
|
|
287
|
+
d2 = SubDir(d1, fmt=SubDir.GZIP )
|
|
288
|
+
self.assertEqual( d1.path, d2.path )
|
|
289
|
+
self.assertEqual( d1.fmt, SubDir.BLOSC )
|
|
290
|
+
self.assertEqual( d2.fmt, SubDir.GZIP )
|
|
291
|
+
self.assertEqual( d1.ext, ".zbsc" )
|
|
292
|
+
self.assertEqual( d2.ext, ".pgz" )
|
|
293
|
+
|
|
294
|
+
d1 = SubDir("?/test_subdir", ext="tmp", fmt=SubDir.BLOSC )
|
|
295
|
+
d2 = SubDir(d1, fmt=SubDir.GZIP )
|
|
296
|
+
self.assertEqual( d1.path, d2.path )
|
|
297
|
+
self.assertEqual( d1.fmt, SubDir.BLOSC )
|
|
298
|
+
self.assertEqual( d2.fmt, SubDir.GZIP )
|
|
299
|
+
self.assertEqual( d1.ext, ".tmp" )
|
|
300
|
+
self.assertEqual( d2.ext, d1.ext )
|
|
248
301
|
|
|
249
302
|
def test_cache_mode(self):
|
|
250
303
|
|
|
@@ -288,12 +341,19 @@ class C(object):
|
|
|
288
341
|
def f(self, y):
|
|
289
342
|
return self.x*y
|
|
290
343
|
|
|
291
|
-
class
|
|
344
|
+
class Test2(unittest.TestCase):
|
|
292
345
|
|
|
293
346
|
def test_cache( self ):
|
|
294
347
|
|
|
348
|
+
sub = SubDir("!/xx", ext="ABC")
|
|
349
|
+
self.assertEqual( sub.ext, ".ABC")
|
|
350
|
+
|
|
295
351
|
sub = VersionedCacheRoot("?/subdir_cache_test", exclude_arg_types=[A] )
|
|
296
|
-
|
|
352
|
+
|
|
353
|
+
subsub = sub("sub", ext="tst")
|
|
354
|
+
x = subsub.full_file_name( "hallo")
|
|
355
|
+
self.assertEqual( x[-9:], "hallo.tst" )
|
|
356
|
+
|
|
297
357
|
@sub.cache("1.0")
|
|
298
358
|
def f(x):
|
|
299
359
|
return x
|
|
@@ -364,7 +424,7 @@ class Test(unittest.TestCase):
|
|
|
364
424
|
return G(x)*F(x)
|
|
365
425
|
|
|
366
426
|
_ = H(2.)
|
|
367
|
-
self.assertEqual( H.cache_info.version, "H {
|
|
427
|
+
self.assertEqual( H.cache_info.version, "H { Test2.test_cache.<locals>.F: F, Test2.test_cache.<l 19b17778" )
|
|
368
428
|
self.assertEqual( H.cache_info.version, H.version.unique_id64 )
|
|
369
429
|
|
|
370
430
|
# decorate live member functions
|
|
@@ -406,8 +466,7 @@ class Test(unittest.TestCase):
|
|
|
406
466
|
if debug:
|
|
407
467
|
print(f"h(x={x},y={y})")
|
|
408
468
|
return x*y
|
|
409
|
-
h2(1,1)
|
|
410
|
-
# %%
|
|
469
|
+
h2(1,1)
|
|
411
470
|
self.assertEqual( h2.cache_info.filename, "h2(1,1)________________________________ 46a70d67" )
|
|
412
471
|
|
|
413
472
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|