-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhooks.py
More file actions
65 lines (48 loc) · 1.65 KB
/
Copy pathhooks.py
File metadata and controls
65 lines (48 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
59
60
61
62
63
64
65
from __future__ import annotations
import importlib
import shutil
from pathlib import Path
import sys
from usr.plugins.rlm.helpers.bootstrap import ensure_rlm_dependency
from usr.plugins.rlm.helpers.docker_setup import (
activate_docker_cli_shim,
deactivate_docker_cli_shim,
)
PLUGIN_PACKAGE_PREFIX = "usr.plugins.rlm"
DEPENDENCY_PACKAGE_PREFIX = "rlm"
PLUGIN_ROOT = Path(__file__).resolve().parent
def install() -> None:
_ensure_rlm_dependency()
activate_docker_cli_shim()
_clear_dependency_modules()
_clear_plugin_modules()
_clear_plugin_bytecode()
def pre_update() -> None:
deactivate_docker_cli_shim()
_clear_dependency_modules()
_clear_plugin_modules()
_clear_plugin_bytecode()
def uninstall() -> None:
deactivate_docker_cli_shim()
_clear_dependency_modules()
_clear_plugin_modules()
_clear_plugin_bytecode()
def _ensure_rlm_dependency() -> None:
ensure_rlm_dependency()
def _clear_plugin_modules() -> None:
for module_name in list(sys.modules):
if module_name == PLUGIN_PACKAGE_PREFIX or module_name.startswith(
f"{PLUGIN_PACKAGE_PREFIX}."
):
sys.modules.pop(module_name, None)
importlib.invalidate_caches()
def _clear_dependency_modules() -> None:
for module_name in list(sys.modules):
if module_name == DEPENDENCY_PACKAGE_PREFIX or module_name.startswith(
f"{DEPENDENCY_PACKAGE_PREFIX}."
):
sys.modules.pop(module_name, None)
importlib.invalidate_caches()
def _clear_plugin_bytecode() -> None:
for cache_dir in PLUGIN_ROOT.rglob("__pycache__"):
shutil.rmtree(cache_dir, ignore_errors=True)