util
SSB-project utils.
create_error_log(log, calling_function, home_path=HOME_PATH)
Creates a file with log of error in the current folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log
|
str
|
The content of the error log. |
required |
calling_function
|
str
|
The function in which the error occurred. Used to give a more descriptive name to error log file. |
required |
home_path
|
Path
|
System home path |
HOME_PATH
|
Source code in ssb_project_cli/ssb_project/util.py
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 |
|
execute_command(command, command_shortname, success_desc=None, failure_desc=None, cwd=None)
Execute command and handle failure/success cases.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command
|
Union[str, list[str]]
|
The command to be executed. For example "poetry install". |
required |
command_shortname
|
str
|
For example: "poetry-install". Used to create descriptive error log file. |
required |
success_desc
|
Optional[str]
|
For example: "Poetry install ran successfully". |
None
|
failure_desc
|
Optional[str]
|
For example: "Something went wrong while running poetry install". |
None
|
cwd
|
Optional[Path]
|
The current working directory. |
None
|
Returns:
Type | Description |
---|---|
CompletedProcess[bytes]
|
The result of the subprocess. |
Source code in ssb_project_cli/ssb_project/util.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
get_kernels_dict()
Gets installed kernel specifications.
Returns:
Name | Type | Description |
---|---|---|
kernel_dict |
dict[str, dict[str, str]]
|
Dictionary of installed kernel specifications |
Source code in ssb_project_cli/ssb_project/util.py
107 108 109 110 111 112 113 |
|
get_project_name_and_root_path(project_path=None)
Get the name and root of the project.
- First source:
.cruft.json
- Second source:
pyproject.toml
- Final fallback: project root directory name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_path
|
Path | None
|
Optionally supply a path to the project. If not supplied, use the current working directory. |
None
|
Returns:
Name | Type | Description |
---|---|---|
project_name |
str | None
|
The name of the project. |
project_root |
Path | None
|
Path of the root directory of the project. |
Source code in ssb_project_cli/ssb_project/util.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
handle_no_kernel_argument(no_kernel)
Handle the 'no_kernel' parameter and environment variable.
The CLI flag is always prioritised, otherwise it falls back to the environment variable and then lastly defaults to False.
Source code in ssb_project_cli/ssb_project/util.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
remove_kernel_spec(kernel_name)
Remove a kernel spec.
Source code in ssb_project_cli/ssb_project/util.py
116 117 118 |
|
set_debug_logging(home_path=HOME_PATH)
Creates a file with log of error in the current folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
home_path
|
Path
|
path prefix to use for error logging, defaults to HOME_PATH. |
HOME_PATH
|
Source code in ssb_project_cli/ssb_project/util.py
23 24 25 26 27 28 29 30 31 32 33 |
|