system
LazyLoad(import_path)
¶
rmdir(path)
¶
Remove a directory recursively. Args: path (str): path to directory to remove Returns: True if a dir was removed, false otherwise. Raises error if failed to remove.
Source code in langroid/utils/system.py
caller_name()
¶
Who called the function?
Source code in langroid/utils/system.py
generate_user_id(org='')
¶
Generate a unique user ID based on the username and machine name. Returns:
Source code in langroid/utils/system.py
update_hash(hash=None, s='')
¶
Takes a SHA256 hash string and a new string, updates the hash with the new string, and returns the updated hash string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hash |
str
|
A SHA256 hash string. |
None
|
s |
str
|
A new string to update the hash with. |
''
|
Returns:
Type | Description |
---|---|
str
|
The updated hash in hexadecimal format. |
Source code in langroid/utils/system.py
hash(s)
¶
Generate a SHA256 hash of a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
str
|
The string to hash. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The SHA256 hash of the string. |
generate_unique_id()
¶
create_file(filepath, content='', if_exists='overwrite')
¶
Create, overwrite or append to a file, with the given content at the specified filepath. If content is empty, it will simply touch to create an empty file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
str | Path
|
The relative path of the file to be created |
required |
content |
str
|
The content to be written to the file |
''
|
if_exists |
Literal['overwrite', 'skip', 'error', 'append']
|
Action to take if file exists |
'overwrite'
|
Source code in langroid/utils/system.py
read_file(path, line_numbers=False)
¶
Read the contents of a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The path to the file to be read. |
required |
line_numbers |
bool
|
If True, prepend line numbers to each line. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The contents of the file, optionally with line numbers. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the specified file does not exist. |
Source code in langroid/utils/system.py
diff_files(file1, file2)
¶
Find the diffs between two files, in unified diff format.
Source code in langroid/utils/system.py
list_dir(path)
¶
List the contents of a directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
The path to the directory. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A list of the files and directories in the specified directory. |