pyBiocFileCache 0.6.1__py3-none-any.whl → 0.7.0__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.
- pybiocfilecache/cache.py +138 -54
- pybiocfilecache/models.py +19 -1
- pybiocfilecache/utils.py +27 -4
- {pyBiocFileCache-0.6.1.dist-info → pybiocfilecache-0.7.0.dist-info}/METADATA +7 -5
- pybiocfilecache-0.7.0.dist-info/RECORD +12 -0
- {pyBiocFileCache-0.6.1.dist-info → pybiocfilecache-0.7.0.dist-info}/WHEEL +1 -1
- pyBiocFileCache-0.6.1.dist-info/RECORD +0 -13
- pybiocfilecache/exceptions.py +0 -31
- {pyBiocFileCache-0.6.1.dist-info → pybiocfilecache-0.7.0.dist-info/licenses}/AUTHORS.md +0 -0
- {pyBiocFileCache-0.6.1.dist-info → pybiocfilecache-0.7.0.dist-info/licenses}/LICENSE.txt +0 -0
- {pyBiocFileCache-0.6.1.dist-info → pybiocfilecache-0.7.0.dist-info}/top_level.txt +0 -0
pybiocfilecache/cache.py
CHANGED
|
@@ -5,26 +5,22 @@ from pathlib import Path
|
|
|
5
5
|
from time import sleep, time
|
|
6
6
|
from typing import Any, Dict, Iterator, List, Literal, Optional, Tuple, Union
|
|
7
7
|
|
|
8
|
+
from biocframe import BiocFrame
|
|
8
9
|
from sqlalchemy import create_engine, func, text
|
|
9
10
|
from sqlalchemy.orm import Session, sessionmaker
|
|
10
11
|
from sqlalchemy.pool import QueuePool
|
|
11
12
|
|
|
12
13
|
from .config import CacheConfig
|
|
13
14
|
from .const import SCHEMA_VERSION
|
|
14
|
-
from .
|
|
15
|
-
BiocCacheError,
|
|
16
|
-
InvalidRnameError,
|
|
17
|
-
NoFpathError,
|
|
18
|
-
RnameExistsError,
|
|
19
|
-
RpathTimeoutError,
|
|
20
|
-
)
|
|
21
|
-
from .models import Base, Resource
|
|
15
|
+
from .models import Base, Metadata, Resource
|
|
22
16
|
from .utils import (
|
|
23
17
|
calculate_file_hash,
|
|
18
|
+
convert_to_columnar,
|
|
24
19
|
copy_or_move,
|
|
25
20
|
create_tmp_dir,
|
|
21
|
+
download_web_file,
|
|
26
22
|
generate_id,
|
|
27
|
-
|
|
23
|
+
generate_uuid,
|
|
28
24
|
)
|
|
29
25
|
|
|
30
26
|
__author__ = "Jayaram Kancherla"
|
|
@@ -65,7 +61,6 @@ class BiocFileCache:
|
|
|
65
61
|
db_schema_version = self._setup_database()
|
|
66
62
|
|
|
67
63
|
if db_schema_version != SCHEMA_VERSION:
|
|
68
|
-
print(db_schema_version)
|
|
69
64
|
raise RuntimeError(f"Database version is not {SCHEMA_VERSION}.")
|
|
70
65
|
|
|
71
66
|
self._last_cleanup = datetime.now()
|
|
@@ -111,13 +106,19 @@ class BiocFileCache:
|
|
|
111
106
|
|
|
112
107
|
return SCHEMA_VERSION
|
|
113
108
|
|
|
114
|
-
def _get_detached_resource(self, session: Session,
|
|
109
|
+
def _get_detached_resource(self, session: Session, obj: Union[Resource, Metadata]) -> Optional[dict]:
|
|
115
110
|
"""Get a detached copy of a resource."""
|
|
116
|
-
if
|
|
111
|
+
if obj is None:
|
|
117
112
|
return None
|
|
118
|
-
session.refresh(
|
|
119
|
-
session.expunge(
|
|
120
|
-
|
|
113
|
+
session.refresh(obj)
|
|
114
|
+
session.expunge(obj)
|
|
115
|
+
obj_dict = obj.to_dict()
|
|
116
|
+
|
|
117
|
+
if isinstance(obj, Resource):
|
|
118
|
+
if obj_dict["rtype"] == "relative":
|
|
119
|
+
obj_dict["rpath"] = f"{self.config.cache_dir}/{obj_dict['rpath']}"
|
|
120
|
+
|
|
121
|
+
return obj_dict
|
|
121
122
|
|
|
122
123
|
def __enter__(self) -> "BiocFileCache":
|
|
123
124
|
return self
|
|
@@ -142,10 +143,14 @@ class BiocFileCache:
|
|
|
142
143
|
finally:
|
|
143
144
|
session.close()
|
|
144
145
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
#########################
|
|
147
|
+
######>> cleanup <<######
|
|
148
|
+
#########################
|
|
149
|
+
|
|
150
|
+
# def _validate_rname(self, rname: str) -> None:
|
|
151
|
+
# """Validate resource name format."""
|
|
152
|
+
# if not validate_rname(rname, self.config.rname_pattern):
|
|
153
|
+
# raise Exception(f"Resource name '{rname}' doesn't match pattern " f"'{self.config.rname_pattern}'")
|
|
149
154
|
|
|
150
155
|
def _should_cleanup(self) -> bool:
|
|
151
156
|
"""Check if cache cleanup should be performed.
|
|
@@ -196,26 +201,37 @@ class BiocFileCache:
|
|
|
196
201
|
self._last_cleanup = datetime.now()
|
|
197
202
|
return removed
|
|
198
203
|
|
|
199
|
-
|
|
204
|
+
###############################
|
|
205
|
+
######>> get resources <<######
|
|
206
|
+
###############################
|
|
207
|
+
|
|
208
|
+
def get(self, rname: str = None, rid: str = None) -> Optional[dict]:
|
|
200
209
|
"""Get resource by name from cache.
|
|
201
210
|
|
|
202
211
|
Args:
|
|
203
212
|
rname:
|
|
204
213
|
Name to identify the resource in cache.
|
|
205
214
|
|
|
215
|
+
rid:
|
|
216
|
+
Resource id to search by.
|
|
217
|
+
|
|
206
218
|
"""
|
|
219
|
+
if rname is None and rid is None:
|
|
220
|
+
raise ValueError("either 'rname' or 'rid' must be provided.")
|
|
221
|
+
|
|
207
222
|
with self.get_session() as session:
|
|
208
|
-
|
|
223
|
+
if rname is not None:
|
|
224
|
+
resource = session.query(Resource).filter(Resource.rname == rname).first()
|
|
225
|
+
elif rid is not None:
|
|
226
|
+
resource = session.query(Resource).filter(Resource.rid == rid).first()
|
|
209
227
|
|
|
210
228
|
if resource is not None:
|
|
211
229
|
# Check if path exists with timeout
|
|
212
230
|
start = time()
|
|
213
231
|
timeout = 30
|
|
214
|
-
while not Path(str(resource.rpath)).exists():
|
|
232
|
+
while not Path(str(self.config.cache_dir / resource.rpath)).exists():
|
|
215
233
|
if time() - start >= timeout:
|
|
216
|
-
raise
|
|
217
|
-
f"For resource: '{rname}' the rpath does not exist " f"after {timeout} seconds."
|
|
218
|
-
)
|
|
234
|
+
raise TimeoutError(f"For resource: '{rname}' the rpath does not exist after {timeout} seconds.")
|
|
219
235
|
sleep(0.1)
|
|
220
236
|
|
|
221
237
|
# Update access time
|
|
@@ -229,11 +245,12 @@ class BiocFileCache:
|
|
|
229
245
|
self,
|
|
230
246
|
rname: str,
|
|
231
247
|
fpath: Union[str, Path],
|
|
232
|
-
rtype: Literal["local", "web", "relative"] = "
|
|
248
|
+
rtype: Literal["local", "web", "relative"] = "relative",
|
|
233
249
|
action: Literal["copy", "move", "asis"] = "copy",
|
|
234
250
|
expires: Optional[datetime] = None,
|
|
235
|
-
|
|
236
|
-
|
|
251
|
+
download: bool = True,
|
|
252
|
+
ext: bool = True,
|
|
253
|
+
) -> dict:
|
|
237
254
|
"""Add a resource to the cache.
|
|
238
255
|
|
|
239
256
|
Args:
|
|
@@ -252,29 +269,41 @@ class BiocFileCache:
|
|
|
252
269
|
How to handle the file ("copy", "move", or "asis").
|
|
253
270
|
Defaults to ``copy``.
|
|
254
271
|
|
|
272
|
+
download:
|
|
273
|
+
Whether to download the resource.
|
|
274
|
+
Only used if 'rtype' is "web".
|
|
275
|
+
|
|
255
276
|
expires:
|
|
256
277
|
Optional expiration datetime.
|
|
257
278
|
If None, resource never expires.
|
|
258
279
|
|
|
259
280
|
ext:
|
|
260
281
|
Whether to use filepath extension when storing in cache.
|
|
261
|
-
Defaults to `
|
|
282
|
+
Defaults to `True`.
|
|
262
283
|
|
|
263
284
|
Returns:
|
|
264
|
-
The `Resource` object added to the cache.
|
|
285
|
+
The `Resource` object added to the cache as dictionary.
|
|
265
286
|
"""
|
|
266
287
|
# self._validate_rname(rname)
|
|
267
|
-
fpath = Path(fpath)
|
|
268
|
-
|
|
269
|
-
if not fpath.exists():
|
|
270
|
-
raise NoFpathError(f"Resource at '{fpath}' does not exist")
|
|
288
|
+
fpath = Path(fpath) if rtype != "web" else fpath
|
|
271
289
|
|
|
272
290
|
if self.get(rname) is not None:
|
|
273
|
-
raise
|
|
291
|
+
raise FileExistsError(f"Resource '{rname}' already exists")
|
|
292
|
+
|
|
293
|
+
if rtype == "web":
|
|
294
|
+
outpath = download_web_file(fpath, Path(fpath).name, download)
|
|
295
|
+
action = "copy"
|
|
296
|
+
else:
|
|
297
|
+
outpath = Path(fpath)
|
|
298
|
+
|
|
299
|
+
if action == "asis":
|
|
300
|
+
logger.warning("If action='asis', rtype must be 'local'.")
|
|
301
|
+
rtype = "local"
|
|
274
302
|
|
|
275
303
|
# Generate paths and check size
|
|
276
304
|
rid = generate_id(size=len(self))
|
|
277
|
-
|
|
305
|
+
uuid = generate_uuid()
|
|
306
|
+
rpath = f"{uuid}_{outpath.name if ext else outpath.stem}" if action != "asis" else fpath
|
|
278
307
|
|
|
279
308
|
# Create resource record
|
|
280
309
|
resource = Resource(
|
|
@@ -292,10 +321,10 @@ class BiocFileCache:
|
|
|
292
321
|
session.commit()
|
|
293
322
|
|
|
294
323
|
try:
|
|
295
|
-
copy_or_move(
|
|
324
|
+
copy_or_move(outpath, self.config.cache_dir / rpath, rname, action, False)
|
|
296
325
|
|
|
297
326
|
# Calculate and store checksum
|
|
298
|
-
resource.etag = calculate_file_hash(rpath, self.config.hash_algorithm)
|
|
327
|
+
resource.etag = calculate_file_hash(self.config.cache_dir / rpath, self.config.hash_algorithm)
|
|
299
328
|
session.commit()
|
|
300
329
|
result = self._get_detached_resource(session, resource)
|
|
301
330
|
return result
|
|
@@ -303,9 +332,9 @@ class BiocFileCache:
|
|
|
303
332
|
except Exception as e:
|
|
304
333
|
session.delete(resource)
|
|
305
334
|
session.commit()
|
|
306
|
-
raise
|
|
335
|
+
raise Exception("Failed to add resource") from e
|
|
307
336
|
|
|
308
|
-
def add_batch(self, resources: List[Dict[str, Any]]) ->
|
|
337
|
+
def add_batch(self, resources: List[Dict[str, Any]]) -> BiocFrame:
|
|
309
338
|
"""Add multiple resources in a single transaction.
|
|
310
339
|
|
|
311
340
|
Args:
|
|
@@ -329,7 +358,7 @@ class BiocFileCache:
|
|
|
329
358
|
rname: str,
|
|
330
359
|
fpath: Union[str, Path],
|
|
331
360
|
action: Literal["copy", "move", "asis"] = "copy",
|
|
332
|
-
) ->
|
|
361
|
+
) -> dict:
|
|
333
362
|
"""Update an existing resource.
|
|
334
363
|
|
|
335
364
|
Args:
|
|
@@ -344,12 +373,12 @@ class BiocFileCache:
|
|
|
344
373
|
Defaults to ``copy``.
|
|
345
374
|
|
|
346
375
|
Returns:
|
|
347
|
-
Updated `Resource` object.
|
|
376
|
+
Updated `Resource` object as dictionary.
|
|
348
377
|
|
|
349
378
|
"""
|
|
350
379
|
fpath = Path(fpath)
|
|
351
380
|
if not fpath.exists():
|
|
352
|
-
raise
|
|
381
|
+
raise FileNotFoundError(f"File '{fpath}' does not exist")
|
|
353
382
|
|
|
354
383
|
with self.get_session() as session:
|
|
355
384
|
resource = session.query(Resource).filter(Resource.rname == rname).first()
|
|
@@ -369,7 +398,7 @@ class BiocFileCache:
|
|
|
369
398
|
|
|
370
399
|
except Exception as e:
|
|
371
400
|
session.rollback()
|
|
372
|
-
raise
|
|
401
|
+
raise Exception("Failed to update resource") from e
|
|
373
402
|
|
|
374
403
|
def remove(self, rname: str) -> None:
|
|
375
404
|
"""Remove a resource from cache by name.
|
|
@@ -381,7 +410,7 @@ class BiocFileCache:
|
|
|
381
410
|
Name to identify the resource in cache.
|
|
382
411
|
|
|
383
412
|
Raises:
|
|
384
|
-
|
|
413
|
+
Exception: If resource removal fails
|
|
385
414
|
"""
|
|
386
415
|
with self.get_session() as session:
|
|
387
416
|
resource = session.query(Resource).filter(Resource.rname == rname).first()
|
|
@@ -399,9 +428,9 @@ class BiocFileCache:
|
|
|
399
428
|
|
|
400
429
|
except Exception as e:
|
|
401
430
|
session.rollback()
|
|
402
|
-
raise
|
|
431
|
+
raise Exception(f"Failed to remove resource '{rname}'") from e
|
|
403
432
|
|
|
404
|
-
def list_resources(self, rtype: Optional[str] = None, expired: Optional[bool] = None) ->
|
|
433
|
+
def list_resources(self, rtype: Optional[str] = None, expired: Optional[bool] = None) -> BiocFrame:
|
|
405
434
|
"""List resources in the cache with optional filtering.
|
|
406
435
|
|
|
407
436
|
Args:
|
|
@@ -417,7 +446,7 @@ class BiocFileCache:
|
|
|
417
446
|
Note: Resources with no expiration are always considered non-expired.
|
|
418
447
|
|
|
419
448
|
Returns:
|
|
420
|
-
List of Resource objects matching the filters
|
|
449
|
+
List of Resource objects matching the filters.
|
|
421
450
|
"""
|
|
422
451
|
with self.get_session() as session:
|
|
423
452
|
query = session.query(Resource)
|
|
@@ -437,7 +466,7 @@ class BiocFileCache:
|
|
|
437
466
|
)
|
|
438
467
|
|
|
439
468
|
resources = query.all()
|
|
440
|
-
return [self._get_detached_resource(session, r) for r in resources]
|
|
469
|
+
return BiocFrame(convert_to_columnar([self._get_detached_resource(session, r) for r in resources]))
|
|
441
470
|
|
|
442
471
|
def validate_resource(self, resource: Resource) -> bool:
|
|
443
472
|
"""Validate resource integrity.
|
|
@@ -506,7 +535,7 @@ class BiocFileCache:
|
|
|
506
535
|
invalid += 1
|
|
507
536
|
return valid, invalid
|
|
508
537
|
|
|
509
|
-
def search(self, query: str, field: str = "rname", exact: bool = False) ->
|
|
538
|
+
def search(self, query: str, field: str = "rname", exact: bool = False) -> BiocFrame:
|
|
510
539
|
"""Search for resources by field value.
|
|
511
540
|
|
|
512
541
|
Args:
|
|
@@ -528,7 +557,7 @@ class BiocFileCache:
|
|
|
528
557
|
else:
|
|
529
558
|
resources = session.query(Resource).filter(Resource[field].ilike(f"%{query}%")).all()
|
|
530
559
|
|
|
531
|
-
return [self._get_detached_resource(session, r) for r in resources]
|
|
560
|
+
return BiocFrame(convert_to_columnar([self._get_detached_resource(session, r) for r in resources]))
|
|
532
561
|
|
|
533
562
|
def get_stats(self) -> Dict[str, Any]:
|
|
534
563
|
"""Get statistics about the cache."""
|
|
@@ -564,7 +593,7 @@ class BiocFileCache:
|
|
|
564
593
|
True if purge was successful, False otherwise.
|
|
565
594
|
|
|
566
595
|
Raises:
|
|
567
|
-
|
|
596
|
+
Exception: If purge fails and force=False.
|
|
568
597
|
"""
|
|
569
598
|
try:
|
|
570
599
|
with self.get_session() as session:
|
|
@@ -577,7 +606,7 @@ class BiocFileCache:
|
|
|
577
606
|
except Exception as e:
|
|
578
607
|
if not force:
|
|
579
608
|
session.rollback()
|
|
580
|
-
raise
|
|
609
|
+
raise Exception(f"Failed to remove file for resource '{resource.rname}'") from e
|
|
581
610
|
logger.warning(f"Failed to remove file for resource '{resource.rname}': {e}")
|
|
582
611
|
|
|
583
612
|
session.commit()
|
|
@@ -598,7 +627,7 @@ class BiocFileCache:
|
|
|
598
627
|
|
|
599
628
|
except Exception as e:
|
|
600
629
|
if not force:
|
|
601
|
-
raise
|
|
630
|
+
raise Exception("Failed to purge cache") from e
|
|
602
631
|
|
|
603
632
|
logger.error("Database cleanup failed, forcing file removal", exc_info=e)
|
|
604
633
|
for file in self.config.cache_dir.iterdir():
|
|
@@ -616,3 +645,58 @@ class BiocFileCache:
|
|
|
616
645
|
def __len__(self):
|
|
617
646
|
with self.get_session() as session:
|
|
618
647
|
return session.query(Resource).count()
|
|
648
|
+
|
|
649
|
+
def check_metadata_key(self, key: str) -> bool:
|
|
650
|
+
"""Check if a key exists in the metadata table.
|
|
651
|
+
|
|
652
|
+
Args:
|
|
653
|
+
key:
|
|
654
|
+
Key to search.
|
|
655
|
+
|
|
656
|
+
Returns:
|
|
657
|
+
True if the key exists, else False.
|
|
658
|
+
"""
|
|
659
|
+
with self.get_session() as session:
|
|
660
|
+
return session.query(Metadata).filter(Metadata.key == key).count() != 0
|
|
661
|
+
|
|
662
|
+
def get_metadata(self, key: str):
|
|
663
|
+
"""Add a new metadata key"""
|
|
664
|
+
with self.get_session() as session:
|
|
665
|
+
meta = session.query(Metadata).filter(Metadata.key == key).first()
|
|
666
|
+
if meta is not None:
|
|
667
|
+
return self._get_detached_resource(session, meta)
|
|
668
|
+
|
|
669
|
+
return None
|
|
670
|
+
|
|
671
|
+
def add_metadata(self, key: str, value: str):
|
|
672
|
+
"""Add a new metadata key"""
|
|
673
|
+
exists = self.get_metadata(key=key)
|
|
674
|
+
|
|
675
|
+
if exists is None:
|
|
676
|
+
meta = Metadata(key=key, value=value)
|
|
677
|
+
|
|
678
|
+
with self.get_session() as session:
|
|
679
|
+
try:
|
|
680
|
+
session.add(meta)
|
|
681
|
+
session.commit()
|
|
682
|
+
return self._get_detached_resource(session, meta)
|
|
683
|
+
except Exception as e:
|
|
684
|
+
session.delete(meta)
|
|
685
|
+
session.commit()
|
|
686
|
+
raise Exception("Failed to add metadata", str(e)) from e
|
|
687
|
+
else:
|
|
688
|
+
raise Exception(f"'key'={key} already exists in metadata.")
|
|
689
|
+
|
|
690
|
+
def remove_metadata(self, key: str) -> None:
|
|
691
|
+
"""Remove a metadata key."""
|
|
692
|
+
with self.get_session() as session:
|
|
693
|
+
meta = session.query(Metadata).filter(Metadata.key == key).first()
|
|
694
|
+
|
|
695
|
+
if meta is not None:
|
|
696
|
+
try:
|
|
697
|
+
session.delete(meta)
|
|
698
|
+
session.commit()
|
|
699
|
+
|
|
700
|
+
except Exception as e:
|
|
701
|
+
session.rollback()
|
|
702
|
+
raise Exception(f"Failed to remove key '{key}'") from e
|
pybiocfilecache/models.py
CHANGED
|
@@ -19,6 +19,9 @@ class Metadata(Base):
|
|
|
19
19
|
def __repr__(self) -> str:
|
|
20
20
|
return f"<Metadata(key='{self.key}', value='{self.value}')>"
|
|
21
21
|
|
|
22
|
+
def to_dict(self) -> dict:
|
|
23
|
+
return {"key": self.key, "value": self.value}
|
|
24
|
+
|
|
22
25
|
|
|
23
26
|
class Resource(Base):
|
|
24
27
|
"""Resource information stored in cache.
|
|
@@ -73,4 +76,19 @@ class Resource(Base):
|
|
|
73
76
|
expires = Column(DateTime, default=None)
|
|
74
77
|
|
|
75
78
|
def __repr__(self) -> str:
|
|
76
|
-
return f"<Resource(rid='{self.rid}', rname='{self.rname}')>"
|
|
79
|
+
return f"<Resource(rid='{self.rid}', rname='{self.rname}', rpath='{self.rpath}')>"
|
|
80
|
+
|
|
81
|
+
def to_dict(self) -> dict:
|
|
82
|
+
return {
|
|
83
|
+
"id": self.id,
|
|
84
|
+
"rid": self.rid,
|
|
85
|
+
"rname": self.rname,
|
|
86
|
+
"create_time": self.create_time,
|
|
87
|
+
"access_time": self.access_time,
|
|
88
|
+
"rpath": self.rpath,
|
|
89
|
+
"rtype": self.rtype,
|
|
90
|
+
"fpath": self.fpath,
|
|
91
|
+
"last_modified_time": self.last_modified_time,
|
|
92
|
+
"etag": self.etag,
|
|
93
|
+
"expires": self.expires,
|
|
94
|
+
}
|
pybiocfilecache/utils.py
CHANGED
|
@@ -2,13 +2,12 @@ import hashlib
|
|
|
2
2
|
import logging
|
|
3
3
|
import re
|
|
4
4
|
import tempfile
|
|
5
|
+
import urllib.request
|
|
5
6
|
import uuid
|
|
6
7
|
import zlib
|
|
7
8
|
from pathlib import Path
|
|
8
9
|
from shutil import copy2, move
|
|
9
|
-
from typing import Literal
|
|
10
|
-
|
|
11
|
-
from .exceptions import BiocCacheError
|
|
10
|
+
from typing import List, Literal
|
|
12
11
|
|
|
13
12
|
__author__ = "Jayaram Kancherla"
|
|
14
13
|
__copyright__ = "Jayaram Kancherla"
|
|
@@ -86,4 +85,28 @@ def copy_or_move(
|
|
|
86
85
|
elif action == "asis":
|
|
87
86
|
pass
|
|
88
87
|
except Exception as e:
|
|
89
|
-
raise
|
|
88
|
+
raise Exception(f"Failed to store resource '{rname}' from '{source}' to '{target}'") from e
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def download_web_file(url: str, filename: str, download: bool):
|
|
92
|
+
tmp_dir = create_tmp_dir()
|
|
93
|
+
outpath = tmp_dir / filename
|
|
94
|
+
if download:
|
|
95
|
+
urllib.request.urlretrieve(str(url), str(outpath))
|
|
96
|
+
else:
|
|
97
|
+
open(str(outpath), "a").close()
|
|
98
|
+
|
|
99
|
+
return outpath
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def convert_to_columnar(list_of_dicts: List[dict]):
|
|
103
|
+
if not list_of_dicts:
|
|
104
|
+
return {}
|
|
105
|
+
|
|
106
|
+
column_names = list_of_dicts[0].keys()
|
|
107
|
+
result = {col: [] for col in column_names}
|
|
108
|
+
|
|
109
|
+
for row in list_of_dicts:
|
|
110
|
+
for col in column_names:
|
|
111
|
+
result[col].append(row.get(col))
|
|
112
|
+
return result
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: pyBiocFileCache
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: File based cache for resources and metadata
|
|
5
|
-
Home-page: https://github.com/
|
|
5
|
+
Home-page: https://github.com/biocpy/pyBiocFileCache
|
|
6
6
|
Author: jkanche
|
|
7
7
|
Author-email: jayaram.kancherla@gmail.com
|
|
8
8
|
License: MIT
|
|
9
|
-
Project-URL: Documentation, https://
|
|
9
|
+
Project-URL: Documentation, https://github.com/biocpy/pyBiocFileCache
|
|
10
10
|
Platform: any
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Programming Language :: Python
|
|
@@ -16,10 +16,12 @@ License-File: LICENSE.txt
|
|
|
16
16
|
License-File: AUTHORS.md
|
|
17
17
|
Requires-Dist: importlib-metadata; python_version < "3.8"
|
|
18
18
|
Requires-Dist: sqlalchemy
|
|
19
|
+
Requires-Dist: biocframe
|
|
19
20
|
Provides-Extra: testing
|
|
20
21
|
Requires-Dist: setuptools; extra == "testing"
|
|
21
22
|
Requires-Dist: pytest; extra == "testing"
|
|
22
23
|
Requires-Dist: pytest-cov; extra == "testing"
|
|
24
|
+
Dynamic: license-file
|
|
23
25
|
|
|
24
26
|
[](https://pyscaffold.org/)
|
|
25
27
|
[](https://pypi.org/project/pyBiocFileCache/)
|
|
@@ -52,7 +54,7 @@ resource = cache.add("myfile", "path/to/file.txt")
|
|
|
52
54
|
resource = cache.get("myfile")
|
|
53
55
|
|
|
54
56
|
# Use the cached file
|
|
55
|
-
print(resource
|
|
57
|
+
print(resource["rpath"]) # Path to cached file
|
|
56
58
|
```
|
|
57
59
|
|
|
58
60
|
## Advanced Usage
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
pybiocfilecache/__init__.py,sha256=kClwDkzgGPYAyDW-fuo5LI4lKCruYJhDHvw0lq9u4b0,652
|
|
2
|
+
pybiocfilecache/cache.py,sha256=VELZ8Ao_9clIUvKXjkCSFsXwf8KK2s4yLOJWT4xxneo,23666
|
|
3
|
+
pybiocfilecache/config.py,sha256=bado4Hg6QFIfV46zKwx6Q9AoV__G-e8fghylnk5I-nk,803
|
|
4
|
+
pybiocfilecache/const.py,sha256=c9167eSCGBp0wF1xuAEvr-fbYCzp0lcOtKF9sqxlLF8,26
|
|
5
|
+
pybiocfilecache/models.py,sha256=ahnGpEhoZzXzvzb9lphs45uU2wts-_q26LOA_P3URKo,2517
|
|
6
|
+
pybiocfilecache/utils.py,sha256=M59NG_oMVvVw03t1hDNaaKtcBZWY4U0KSfpQx_L5U1Y,2981
|
|
7
|
+
pybiocfilecache-0.7.0.dist-info/licenses/AUTHORS.md,sha256=ptvMLokf9Knfp0Ng-dHSgtEimkXWZhjZAR_o2aJm9bw,161
|
|
8
|
+
pybiocfilecache-0.7.0.dist-info/licenses/LICENSE.txt,sha256=bV5MJ4ezdCnC4yREyxU30iel5hFq8T8kGqobu4Kc-WM,1082
|
|
9
|
+
pybiocfilecache-0.7.0.dist-info/METADATA,sha256=4qvcDLIDVooC3kNk-38vk2ETPgRC9XoDeSvqHns0gR4,3015
|
|
10
|
+
pybiocfilecache-0.7.0.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
|
11
|
+
pybiocfilecache-0.7.0.dist-info/top_level.txt,sha256=_A2QFmYMnsz6WoSRPk1EFMDr5mkQVGx9Xtz2RMv3aF4,16
|
|
12
|
+
pybiocfilecache-0.7.0.dist-info/RECORD,,
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
pybiocfilecache/__init__.py,sha256=kClwDkzgGPYAyDW-fuo5LI4lKCruYJhDHvw0lq9u4b0,652
|
|
2
|
-
pybiocfilecache/cache.py,sha256=cBPQYW4EW5ACRvbWotYJaDkzJpNZhvPC2hPlFd9mAO4,20641
|
|
3
|
-
pybiocfilecache/config.py,sha256=bado4Hg6QFIfV46zKwx6Q9AoV__G-e8fghylnk5I-nk,803
|
|
4
|
-
pybiocfilecache/const.py,sha256=c9167eSCGBp0wF1xuAEvr-fbYCzp0lcOtKF9sqxlLF8,26
|
|
5
|
-
pybiocfilecache/exceptions.py,sha256=8jrnctFYF7Rc1xsITtLUwKKvx8GMoKbarucyc-4f2zI,706
|
|
6
|
-
pybiocfilecache/models.py,sha256=oEQaLB9haWtSnm8DybMoMf8INZ4czxs7jriHv61YCb8,1945
|
|
7
|
-
pybiocfilecache/utils.py,sha256=a2sUcnWzu8F0nwdmun8Ke0hj0-bFJ5JF-Z1tq9NT0NM,2406
|
|
8
|
-
pyBiocFileCache-0.6.1.dist-info/AUTHORS.md,sha256=ptvMLokf9Knfp0Ng-dHSgtEimkXWZhjZAR_o2aJm9bw,161
|
|
9
|
-
pyBiocFileCache-0.6.1.dist-info/LICENSE.txt,sha256=bV5MJ4ezdCnC4yREyxU30iel5hFq8T8kGqobu4Kc-WM,1082
|
|
10
|
-
pyBiocFileCache-0.6.1.dist-info/METADATA,sha256=KhKuU1Dbho0go2sWVpVrrm2WHTDPFn_doktKrqNRdO8,2947
|
|
11
|
-
pyBiocFileCache-0.6.1.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
|
|
12
|
-
pyBiocFileCache-0.6.1.dist-info/top_level.txt,sha256=_A2QFmYMnsz6WoSRPk1EFMDr5mkQVGx9Xtz2RMv3aF4,16
|
|
13
|
-
pyBiocFileCache-0.6.1.dist-info/RECORD,,
|
pybiocfilecache/exceptions.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
__author__ = "Jayaram Kancherla"
|
|
2
|
-
__copyright__ = "Jayaram Kancherla"
|
|
3
|
-
__license__ = "MIT"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class BiocCacheError(Exception):
|
|
7
|
-
"""Base exception for BiocFileCache errors."""
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class NoFpathError(BiocCacheError):
|
|
11
|
-
"""Source file does not exist."""
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class RnameExistsError(BiocCacheError):
|
|
15
|
-
"""Resource name already exists in cache."""
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class RpathTimeoutError(BiocCacheError):
|
|
19
|
-
"""Resource path does not exist after timeout."""
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class CacheSizeLimitError(BiocCacheError):
|
|
23
|
-
"""Cache size limit would be exceeded."""
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class ResourceValidationError(BiocCacheError):
|
|
27
|
-
"""Resource failed validation check."""
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class InvalidRnameError(BiocCacheError):
|
|
31
|
-
"""Invalid resource name format."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|