zombie-squirrel 0.1.0__tar.gz → 0.1.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zombie-squirrel
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Generated from aind-library-template
5
5
  Author: Allen Institute for Neural Dynamics
6
6
  License: MIT
@@ -0,0 +1,4 @@
1
+ """Init package"""
2
+ __version__ = "0.1.2"
3
+
4
+ from zombie_squirrel.squirrels import unique_project_names
@@ -4,10 +4,7 @@ import pandas as pd
4
4
  import os
5
5
 
6
6
  from aind_data_access_api.rds_tables import Client, RDSCredentials
7
-
8
-
9
- def prefix_table_name(table_name: str) -> str:
10
- return "zs_" + table_name
7
+ from zombie_squirrel.utils import prefix_table_name
11
8
 
12
9
 
13
10
  class Acorn(ABC):
@@ -4,6 +4,8 @@ from typing import Any, Callable, Optional
4
4
  from zombie_squirrel.acorns import RedshiftAcorn, MemoryAcorn
5
5
  from aind_data_access_api.document_db import MetadataDbClient
6
6
  import os
7
+ import logging
8
+ from zombie_squirrel.utils import prefix_table_name, rds_get_handle_empty
7
9
 
8
10
  # --- Backend setup ---------------------------------------------------
9
11
 
@@ -12,8 +14,10 @@ API_GATEWAY_HOST = "api.allenneuraldynamics.org"
12
14
  tree_type = os.getenv("TREE_SPECIES", "memory").lower()
13
15
 
14
16
  if tree_type == "redshift":
17
+ logging.info("Using Redshift acorn for caching")
15
18
  ACORN = RedshiftAcorn()
16
19
  else:
20
+ logging.info("Using in-memory acorn for caching")
17
21
  ACORN = MemoryAcorn()
18
22
 
19
23
  # --- Squirrel registry -----------------------------------------------------
@@ -31,13 +35,19 @@ def register_squirrel(name: str):
31
35
 
32
36
  # --- Squirrels -----------------------------------------------------
33
37
 
38
+ NAMES = {
39
+ "upn": "unique-project-names",
40
+ "usi": "unique-subject-ids",
41
+ }
34
42
 
35
- @register_squirrel("unique-project-names")
43
+
44
+ @register_squirrel(NAMES["upn"])
36
45
  def unique_project_names(force_update: bool = False) -> list[str]:
37
- df = ACORN.scurry("unique-project-names")
46
+ df = rds_get_handle_empty(ACORN, NAMES["upn"])
38
47
 
39
48
  if df.empty or force_update:
40
49
  # If cache is missing, fetch data
50
+ logging.info("Updating cache for unique project names")
41
51
  client = MetadataDbClient(
42
52
  host=API_GATEWAY_HOST,
43
53
  version="v2",
@@ -49,14 +59,14 @@ def unique_project_names(force_update: bool = False) -> list[str]:
49
59
  ]
50
60
  )
51
61
  df = pd.DataFrame(unique_project_names)
52
- ACORN.hide("unique-project-names", df)
62
+ ACORN.hide(NAMES["upn"], df)
53
63
 
54
64
  return df["project_name"].tolist()
55
65
 
56
66
 
57
- @register_squirrel("unique-subject-ids")
67
+ @register_squirrel(NAMES["usi"])
58
68
  def unique_subject_ids(force_update: bool = False) -> list[str]:
59
- df = ACORN.scurry("unique-subject-ids")
69
+ df = rds_get_handle_empty(ACORN, NAMES["usi"])
60
70
 
61
71
  if df.empty or force_update:
62
72
  # If cache is missing, fetch data
@@ -71,6 +81,6 @@ def unique_subject_ids(force_update: bool = False) -> list[str]:
71
81
  ]
72
82
  )
73
83
  df = pd.DataFrame(unique_subject_ids)
74
- ACORN.hide("unique-subject-ids", df)
84
+ ACORN.hide(NAMES["usi"], df)
75
85
 
76
86
  return df["subject_id"].tolist()
@@ -0,0 +1,20 @@
1
+ """Utility functions"""
2
+ import pandas as pd
3
+ import logging
4
+
5
+ from zombie_squirrel.acorns import Acorn
6
+
7
+
8
+ def prefix_table_name(table_name: str) -> str:
9
+ return "zs_" + table_name
10
+
11
+
12
+ def rds_get_handle_empty(acorn: Acorn, table_name: str) -> pd.DataFrame:
13
+ """Utility function for testing purposes."""
14
+ try:
15
+ df = acorn.scurry(table_name)
16
+ except Exception as e:
17
+ logging.warning(f"Error fetching from cache: {e}")
18
+ df = pd.DataFrame()
19
+
20
+ return df
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zombie-squirrel
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Generated from aind-library-template
5
5
  Author: Allen Institute for Neural Dynamics
6
6
  License: MIT
@@ -6,6 +6,7 @@ src/zombie_squirrel/__init__.py
6
6
  src/zombie_squirrel/acorns.py
7
7
  src/zombie_squirrel/squirrels.py
8
8
  src/zombie_squirrel/sync.py
9
+ src/zombie_squirrel/utils.py
9
10
  src/zombie_squirrel.egg-info/PKG-INFO
10
11
  src/zombie_squirrel.egg-info/SOURCES.txt
11
12
  src/zombie_squirrel.egg-info/dependency_links.txt
@@ -1,4 +0,0 @@
1
- """Init package"""
2
- __version__ = "0.1.0"
3
-
4
- from zombie_squirrel.squirrels import unique_project_names
File without changes