utils
PathLibEnv
Bases: Environment
Subclass of jinja2.Environment
to enable using pathlib.Path
for template names.
Source code in cassini/utils.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
CassiniLabApp
Bases: LabApp
Subclass of jupyterlab.labapp.LabApp
that ensures ContentsManager.allow_hidden = True
(needed for jupyter_cassini_server)
Source code in cassini/utils.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
initialize_server
classmethod
initialize_server(argv=None)
Patch serverapp to ensure hidden files are allowed, needed for jupyter_cassini_server
Source code in cassini/utils.py
50 51 52 53 54 55 56 57 58 59 |
|
FileMaker
Utility content manager for making files, and then rolling back if an exception occurs.
Example
with FileMaker() as maker:
maker.mkdir('mydir')
raise Exception()
# prints:
# Exception occured, rolling back
# Removing mydir
# Done
Source code in cassini/utils.py
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 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 129 130 131 132 133 134 |
|
mkdir
mkdir(path, exist_ok=False)
Make a directory.
Source code in cassini/utils.py
89 90 91 92 93 94 95 96 97 98 99 |
|
write_file
write_file(path, contents='', exist_ok=False)
Write contents to a file.
Source code in cassini/utils.py
101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
copy_file
copy_file(source, dest)
Copy a file.
Source code in cassini/utils.py
115 116 117 118 119 120 |
|
XPlatform
Bases: Generic[P, R]
Class for easily making cross platform functions/ methods(?). Stops nasty if elses.
Fallback functional called if no matching function added for current platform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
default |
Callable[P, R]
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
self |
XPlatform[P, R]
|
Callable that will always call the appropriate function for the current platform. |
Example
For example use, see open_file and win_open_file.
Source code in cassini/utils.py
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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
func
property
func
Returns the platform appropriate function (or default if not known)
add
add(platform)
Add a platform dependent function. To be used as a decorator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
platform |
str
|
platform wrapped function called for. |
required |
Returns:
Name | Type | Description |
---|---|---|
self |
XPlatform
|
Callable that will always call the appropriate function for the current platform. |
Source code in cassini/utils.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
open_file
open_file(filename)
Reveals a file in the file explorer.
*Nix implementation.
Source code in cassini/utils.py
202 203 204 205 206 207 208 209 210 211 212 |
|
win_open_file
win_open_file(filename)
Reveals a file in the file explorer.
Windows implementation.
Source code in cassini/utils.py
215 216 217 218 219 220 221 222 |
|
find_project
find_project(import_string=None)
Find the Project instance for this Python interpretter.
If this Python interpretter was launched via cassini.Project.launch()
, this will already be set.
Otherwise, import_string
or CASSINI_PROJECT environment variable can be set.
This should be of the form:
path/to/module.py:project_obj
By default, project_obj
is assumed to be called project
. This will be imported from module
, which by default is
assumed to be cas_project
.
Note that for cassini to run with a regular jupyterlab instance, ContentsManager.allow_hidden = True
must be set, either
via a config, or passed as a command line argument e.g. --ContentsManager.allow_hidden=True
Returns:
Name | Type | Description |
---|---|---|
project |
Project
|
Found project instance. Note this also sets |
Source code in cassini/utils.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
|