File Utils
Utility functions for file operations in CodeMap.
logger
module-attribute
logger = getLogger(__name__)
count_tokens
count_tokens(file_path: Path) -> int
Rough estimation of tokens in a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
Path
|
Path to the file to count tokens in. |
required |
Returns:
Type | Description |
---|---|
int
|
Estimated number of tokens in the file. |
Source code in src/codemap/utils/file_utils.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
read_file_content
read_file_content(file_path: Path | str) -> str | None
Read content from a file with proper error handling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
Path | str
|
Path to the file to read |
required |
Returns:
Type | Description |
---|---|
str | None
|
Content of the file as string, or None if the file cannot be read |
Source code in src/codemap/utils/file_utils.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
ensure_directory_exists
ensure_directory_exists(dir_path: Path) -> None
Ensure that a directory exists, creating it if necessary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dir_path
|
Path
|
The path to the directory. |
required |
Source code in src/codemap/utils/file_utils.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
is_binary_file
is_binary_file(file_path: Path) -> bool
Check if a file is binary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
Path
|
Path to the file |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the file is binary, False otherwise |
Source code in src/codemap/utils/file_utils.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|