Skip to content

Commit 4d54da5

Browse files
committed
Testing remove item
1 parent 5bd00b6 commit 4d54da5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

shiny/_app.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import copy
44
import os
5+
import shutil
6+
import tempfile
57
import secrets
68
from contextlib import AsyncExitStack, asynccontextmanager
79
from inspect import signature
@@ -214,6 +216,24 @@ def __init__(
214216
cast("Tag | TagList", ui), lib_prefix=self.lib_prefix
215217
)
216218

219+
def __del__(self):
220+
current_temp_dir = os.path.realpath(tempfile.gettempdir())
221+
222+
user_dependencies = [
223+
v.source["subdir"]
224+
for k, v in self._registered_dependencies.items()
225+
if k.startswith("include-")
226+
]
227+
228+
for item in user_dependencies:
229+
# Only remove the item if it exists and it is in the current temp directory
230+
if (
231+
os.path.exists(item)
232+
and os.path.commonprefix([os.path.realpath(item), current_temp_dir])
233+
== current_temp_dir
234+
):
235+
shutil.rmtree(item)
236+
217237
def init_starlette_app(self) -> starlette.applications.Starlette:
218238
routes: list[starlette.routing.BaseRoute] = [
219239
starlette.routing.WebSocketRoute("/websocket/", self._on_connect_cb),

0 commit comments

Comments
 (0)