Skip to content

Commit 1be8f20

Browse files
committed
Copy over implementation of _package_dir from htmltools
1 parent e5a2040 commit 1be8f20

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

shinywidgets/_shinywidgets.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
__all__ = ("output_widget", "register_widget", "render_widget", "reactive_read")
55

66
import copy
7+
import importlib
78
import inspect
89
import json
910
import os
11+
import tempfile
1012
from typing import Any, Awaitable, Callable, Optional, Sequence, Union, cast, overload
1113
from uuid import uuid4
1214
from weakref import WeakSet
1315

1416
from htmltools import Tag, TagList, css, tags
15-
from htmltools._util import _package_dir
1617
from ipywidgets._version import (
1718
__protocol_version__, # pyright: ignore[reportUnknownVariableType]
1819
)
@@ -309,6 +310,15 @@ def _():
309310
return w
310311

311312

313+
# similar to base::system.file()
314+
def _package_dir(package: str) -> str:
315+
with tempfile.TemporaryDirectory():
316+
pkg_file = importlib.import_module(".", package=package).__file__
317+
if pkg_file is None:
318+
raise ImportError(f"Couldn't load package {package}")
319+
return os.path.dirname(pkg_file)
320+
321+
312322
# It doesn't, at the moment, seem feasible to establish a comm with statically rendered widgets,
313323
# and partially for this reason, it may not be sensible to provide an input-like API for them.
314324

0 commit comments

Comments
 (0)