Util function used most notably in setup.py to add a bash autocompletion script.
(fname: str, script: pathlib.Path)
| 268 | |
| 269 | |
| 270 | def _add_bash_autocompletion(fname: str, script: pathlib.Path) -> None: |
| 271 | """ |
| 272 | Util function used most notably in setup.py to add a bash autocompletion script. |
| 273 | """ |
| 274 | try: |
| 275 | if BASH_COMPLETION_FOLDER is None: |
| 276 | raise OSError() |
| 277 | |
| 278 | # If already defined, exit. |
| 279 | dest = BASH_COMPLETION_FOLDER / fname |
| 280 | if dest.exists(): |
| 281 | return |
| 282 | |
| 283 | # Check that bash autocompletion folder exists |
| 284 | if not BASH_COMPLETION_FOLDER.exists(): |
| 285 | BASH_COMPLETION_FOLDER.mkdir(parents=True, exist_ok=True) |
| 286 | _check_perms(BASH_COMPLETION_FOLDER) |
| 287 | |
| 288 | # Copy file |
| 289 | shutil.copy(script, BASH_COMPLETION_FOLDER) |
| 290 | except OSError: |
| 291 | log_loading.warning("Bash autocompletion script could not be copied.", |
| 292 | exc_info=True) |
| 293 | |
| 294 | |
| 295 | ###################### |
no test coverage detected