|
1 | | -from codetide.core.defaults import DEFAULT_SERIALIZATION_PATH, LANGUAGE_EXTENSIONS, DEFAULT_MAX_CONCURRENT_TASKS, DEFAULT_BATCH_SIZE |
| 1 | +from codetide.core.defaults import ( |
| 2 | + DEFAULT_SERIALIZATION_PATH, DEFAULT_MAX_CONCURRENT_TASKS, |
| 3 | + DEFAULT_BATCH_SIZE, DEFAULT_CACHED_ELEMENTS_FILE, DEFAULT_CACHED_IDS_FILE, |
| 4 | + LANGUAGE_EXTENSIONS |
| 5 | +) |
2 | 6 | from codetide.core.models import CodeFileModel, CodeBase |
3 | 7 | from codetide.core.common import readFile, writeFile |
4 | 8 |
|
|
12 | 16 | import logging |
13 | 17 | import asyncio |
14 | 18 | import time |
| 19 | +import json |
15 | 20 | import os |
16 | 21 |
|
17 | 22 | logging.basicConfig( |
@@ -84,18 +89,35 @@ async def from_path( |
84 | 89 |
|
85 | 90 | return codebase |
86 | 91 |
|
87 | | - def serialize(self, filepath :Optional[Union[str, Path]]=DEFAULT_SERIALIZATION_PATH): |
| 92 | + def serialize(self, filepath :Optional[Union[str, Path]]=DEFAULT_SERIALIZATION_PATH, include_codebase_cached_elements :bool=False, include_cached_ids :bool=False): |
88 | 93 | if not os.path.exists(filepath): |
89 | 94 | os.makedirs(os.path.split(filepath)[0], exist_ok=True) |
90 | 95 | writeFile(self.model_dump_json(indent=4), filepath) |
| 96 | + if include_codebase_cached_elements or include_cached_ids: |
| 97 | + dir_path = Path(os.path.split(filepath))[0] |
| 98 | + if include_codebase_cached_elements: |
| 99 | + cached_elements_path = dir_path / DEFAULT_CACHED_ELEMENTS_FILE |
| 100 | + writeFile(self.codebase.serialize_cache_elements(), cached_elements_path) |
| 101 | + |
| 102 | + if include_cached_ids: |
| 103 | + cached_ids_path = dir_path / DEFAULT_CACHED_IDS_FILE |
| 104 | + writeFile(json.dumps(self.codebase.unique_ds, indent=4), cached_ids_path) |
91 | 105 |
|
92 | 106 | @classmethod |
93 | 107 | def deserialize(cls, filepath :Optional[Union[str, Path]]=DEFAULT_SERIALIZATION_PATH)->"CodeTide": |
94 | 108 | if not os.path.exists(filepath): |
95 | 109 | raise FileNotFoundError(f"{filepath} is not a valid path") |
96 | 110 |
|
97 | 111 | kwargs = readFile(filepath) |
98 | | - return cls(**kwargs) |
| 112 | + tideInstance = cls(**kwargs) |
| 113 | + |
| 114 | + # dir_path = Path(os.path.split(filepath))[0] |
| 115 | + # cached_elements_path = dir_path / DEFAULT_CACHED_ELEMENTS_FILE |
| 116 | + # if os.path.exists(cached_elements_path): |
| 117 | + # cached_elements = json.loads(readFile(cached_elements_path)) |
| 118 | + # tideInstance.codebase._cached_elements = cached_elements |
| 119 | + |
| 120 | + return tideInstance |
99 | 121 |
|
100 | 122 | def _organize_files_by_language( |
101 | 123 | self, |
|
0 commit comments