Skip to content

Commit 2775a05

Browse files
committed
Enhance CodeTide class docstrings for improved clarity and detail
1 parent 343434a commit 2775a05

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

codetide/__init__.py

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import os
2222

2323
class CodeTide(BaseModel):
24-
"""Root model representing a complete codebase"""
24+
"""Root model representing a complete codebase with tools for parsing, tracking, and managing code files."""
25+
2526
rootpath :Union[str, Path]
2627
codebase :CodeBase = Field(default_factory=CodeBase)
2728
files :Dict[Path, datetime]= Field(default_factory=dict)
@@ -97,6 +98,15 @@ def serialize(self,
9798
include_codebase_cached_elements: bool = False,
9899
include_cached_ids: bool = False,
99100
store_in_project_root: bool=True):
101+
"""
102+
Serialize the CodeTide object to a file.
103+
104+
Args:
105+
filepath: Output path for the serialized object.
106+
include_codebase_cached_elements: Whether to include codebase cache.
107+
include_cached_ids: Whether to save list of unique file IDs.
108+
store_in_project_root: Store file relative to project root if True.
109+
"""
100110

101111
if store_in_project_root:
102112
filepath = Path(self.rootpath) / filepath
@@ -132,6 +142,16 @@ def serialize(self,
132142

133143
@classmethod
134144
def deserialize(cls, filepath :Optional[Union[str, Path]]=DEFAULT_SERIALIZATION_PATH, rootpath :Optional[Union[str, Path]] = None)->"CodeTide":
145+
"""
146+
Load a CodeTide instance from a serialized file.
147+
148+
Args:
149+
filepath: Path to the serialized CodeTide JSON.
150+
rootpath: Project root directory (used for relative paths).
151+
152+
Returns:
153+
Deserialized CodeTide instance.
154+
"""
135155
if rootpath is not None:
136156
filepath = Path(rootpath) / filepath
137157

@@ -219,7 +239,16 @@ async def _process_single_file(
219239
filepath: Path,
220240
parser: BaseParser
221241
) -> Optional[CodeFileModel]:
222-
"""Process a single file with error handling."""
242+
"""
243+
Asynchronously process a single file using the given parser.
244+
245+
Args:
246+
filepath: Path to the file.
247+
parser: Parser object corresponding to the file's language.
248+
249+
Returns:
250+
Parsed CodeFileModel or None on failure.
251+
"""
223252
try:
224253
logger.debug(f"Processing file: {filepath}")
225254
return await parser.parse_file(filepath, self.rootpath)
@@ -331,8 +360,10 @@ def _resolve_files_dependencies(self):
331360

332361
def _get_changed_files(self) -> Tuple[List[Path], bool]:
333362
"""
334-
TODO consider if it is worth storing singular timestamp for latest fetch and then just use
335-
pygit2 to changed files based on commit history + current repo status
363+
Detect which files have been added, modified, or deleted since last scan.
364+
365+
Returns:
366+
Tuple containing list of changed file paths and deletion flag.
336367
"""
337368
file_deletion_detected = False
338369
files = self._find_code_files() # Dict[Path, datetime]
@@ -361,6 +392,14 @@ async def check_for_updates(self,
361392
serialize :bool=False,
362393
max_concurrent_tasks: int = DEFAULT_MAX_CONCURRENT_TASKS,
363394
batch_size: int = DEFAULT_BATCH_SIZE, **kwargs):
395+
"""
396+
Update the codebase by detecting and reprocessing changed files.
397+
398+
Args:
399+
serialize: Whether to serialize after updates.
400+
max_concurrent_tasks: Max concurrent parser tasks.
401+
batch_size: Batch size for async file processing.
402+
"""
364403

365404
changed_files, deletion_detected = self._get_changed_files()
366405
if deletion_detected:
@@ -432,12 +471,33 @@ async def check_for_updates(self,
432471
)
433472

434473
def _precheck_id_is_file(self, unique_ids : List[str])->Dict[Path, str]:
474+
"""
475+
Preload file contents for the given IDs if they correspond to known files.
476+
477+
Args:
478+
unique_ids: List of file paths or unique identifiers.
479+
480+
Returns:
481+
Dictionary mapping paths to file content.
482+
"""
435483
return {
436484
unique_id: readFile(self.rootpath / unique_id) for unique_id in unique_ids
437485
if self.rootpath / unique_id in self.files
438486
}
439487

440488
def get(self, unique_id :Union[str, List[str]], degree :int=1, as_string :bool=True, as_list_str :bool=False)->Union[CodeContextStructure, str, List[str]]:
489+
"""
490+
Retrieve context around code by unique ID(s).
491+
492+
Args:
493+
unique_id: Single or list of unique IDs for code entities.
494+
degree: Depth of context to fetch.
495+
as_string: Whether to return as a single string.
496+
as_list_str: Whether to return as list of strings.
497+
498+
Returns:
499+
Code context in the requested format.
500+
"""
441501
if isinstance(unique_id, str):
442502
unique_id = [unique_id]
443503

0 commit comments

Comments
 (0)