util
SSB-project utils.
Nothing
dataclass
Bases: Option[T]
An 'Option' type that doesn't contain a value.
Source code in ssb_project_cli/ssb_project/util.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
get_or_else(default)
Get value if it exists or return default.
Source code in ssb_project_cli/ssb_project/util.py
69 70 71 |
|
is_empty()
Check if the Option type contains a value.
Source code in ssb_project_cli/ssb_project/util.py
77 78 79 |
|
map(func)
Map function over value if it exists.
Source code in ssb_project_cli/ssb_project/util.py
73 74 75 |
|
Option
Bases: Generic[T]
Represents a value that might be empty.
Source code in ssb_project_cli/ssb_project/util.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
get_or_else(default)
Get value if it exists or return default.
Source code in ssb_project_cli/ssb_project/util.py
33 34 35 |
|
is_empty()
Check if the Option type contains a value.
Source code in ssb_project_cli/ssb_project/util.py
41 42 43 |
|
map(func)
Map function over value if it exists.
Source code in ssb_project_cli/ssb_project/util.py
37 38 39 |
|
Some
dataclass
Bases: Option[T]
An 'Option' type that contains a value.
Source code in ssb_project_cli/ssb_project/util.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
get_or_else(default)
Get value if it exists or return default.
Source code in ssb_project_cli/ssb_project/util.py
52 53 54 |
|
is_empty()
Check if the Option type contains a value.
Source code in ssb_project_cli/ssb_project/util.py
60 61 62 |
|
map(func)
Map function over value if it exists.
Source code in ssb_project_cli/ssb_project/util.py
56 57 58 |
|
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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
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
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 |
|
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
174 175 176 177 178 179 180 |
|
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
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
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
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
remove_kernel_spec(kernel_name)
Remove a kernel spec.
Source code in ssb_project_cli/ssb_project/util.py
183 184 185 |
|
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
90 91 92 93 94 95 96 97 98 99 100 |
|
try_if_file_exists(f)
Convert a function that may throw a 'FileExistsError' into an Option value that returns None if an error is thrown.
Source code in ssb_project_cli/ssb_project/util.py
82 83 84 85 86 87 |
|