Helpers
utils.helpers
create_yaml_from_dict(data, dir, file_name)
Create a YAML file from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
The dictionary to convert to YAML. |
required |
dir
|
str
|
The directory where the YAML file will be created. |
required |
file_name
|
str
|
The name of the YAML file (without extension). |
required |
Examples:
>>> create_yaml_from_dict(
... {'key': 'value'},
... '/path/to/dir',
... 'file_name'
)
YAML file created at: /path/to/dir/file_name.yaml
Raises:
| Type | Description |
|---|---|
OSError
|
If the directory cannot be created or written to. |
YAMLError
|
If there is an error in writing the YAML file. |
Source code in hari_data/utils/helpers.py
21 22 23 24 25 26 27 28 29 30 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 | |
is_hari_project()
Check if the current directory is a Hari project by looking for the presence of a 'hari.lock' file.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if 'hari.lock' exists, indicating a Hari project; False otherwise. |
Examples:
>>> is_hari_project()
True
Source code in hari_data/utils/helpers.py
6 7 8 9 10 11 12 13 14 15 16 17 18 | |
read_yaml_to_dict(file_path)
Read a YAML file and convert its contents to a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
The path to the YAML file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The contents of the YAML file as a dictionary. |
Examples:
>>> read_yaml_to_dict('/path/to/file.yaml')
{'key': 'value'}
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified file does not exist. |
YAMLError
|
If there is an error in reading the YAML file. |
Source code in hari_data/utils/helpers.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |