Skip to content

Commit 4fe70b6

Browse files
committed
web_modules_dir needs to be public
the web_modules_path func already is + we need it for idom-jupyter to be able to distribute just the modules without the client in a non-brittle way
1 parent 9dfa0df commit 4fe70b6

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

src/idom/client/_private.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,15 @@
1616
shutil.copytree(BACKUP_BUILD_DIR, IDOM_CLIENT_BUILD_DIR.get(), symlinks=True)
1717

1818

19-
def build_dir() -> Path:
20-
return IDOM_CLIENT_BUILD_DIR.get()
21-
22-
23-
def web_modules_dir() -> Path:
24-
return build_dir() / "_snowpack" / "pkg"
25-
26-
2719
def restore_build_dir_from_backup() -> None:
28-
target = build_dir()
20+
target = IDOM_CLIENT_BUILD_DIR.get()
2921
if target.exists():
3022
shutil.rmtree(target)
3123
shutil.copytree(BACKUP_BUILD_DIR, target, symlinks=True)
3224

3325

3426
def replace_build_dir(source: Path) -> None:
35-
target = build_dir()
27+
target = IDOM_CLIENT_BUILD_DIR.get()
3628
if target.exists():
3729
shutil.rmtree(target)
3830
shutil.copytree(source, target, symlinks=True)
@@ -58,7 +50,7 @@ def split_package_name_and_version(pkg: str) -> Tuple[str, str]:
5850

5951

6052
def build_dependencies() -> Dict[str, str]:
61-
package_json = build_dir() / "package.json"
53+
package_json = IDOM_CLIENT_BUILD_DIR.get() / "package.json"
6254
return cast(Dict[str, str], json.loads(package_json.read_text())["dependencies"])
6355

6456

src/idom/client/manage.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,27 @@
55
from tempfile import TemporaryDirectory
66
from typing import Dict, Iterable, List, Sequence, Set, Union
77

8-
from idom.config import IDOM_CLIENT_WEB_MODULE_BASE_URL
8+
from idom.config import IDOM_CLIENT_BUILD_DIR, IDOM_CLIENT_WEB_MODULE_BASE_URL
99

1010
from . import _private
1111

1212

1313
logger = getLogger(__name__)
1414

1515

16+
def web_modules_dir() -> Path:
17+
return IDOM_CLIENT_BUILD_DIR.get() / "_snowpack" / "pkg"
18+
19+
20+
def web_module_path(package_name: str, must_exist: bool = False) -> Path:
21+
path = web_modules_dir().joinpath(*(package_name + ".js").split("/"))
22+
if must_exist and not path.exists():
23+
raise ValueError(
24+
f"Web module {package_name!r} does not exist at path {str(path)!r}"
25+
)
26+
return path
27+
28+
1629
def web_module_exports(package_name: str) -> List[str]:
1730
web_module_path(package_name, must_exist=True)
1831
return _private.find_js_module_exports_in_source(
@@ -31,7 +44,7 @@ def web_module_exists(package_name: str) -> bool:
3144

3245
def web_module_names() -> Set[str]:
3346
names = []
34-
web_mod_dir = _private.web_modules_dir()
47+
web_mod_dir = web_modules_dir()
3548
for pth in web_mod_dir.glob("**/*.js"):
3649
rel_pth = pth.relative_to(web_mod_dir)
3750
if Path("common") in rel_pth.parents:
@@ -53,15 +66,6 @@ def add_web_module(package_name: str, source: Union[Path, str]) -> str:
5366
return web_module_url(package_name)
5467

5568

56-
def web_module_path(package_name: str, must_exist: bool = False) -> Path:
57-
path = _private.web_modules_dir().joinpath(*(package_name + ".js").split("/"))
58-
if must_exist and not path.exists():
59-
raise ValueError(
60-
f"Web module {package_name!r} does not exist at path {str(path)!r}"
61-
)
62-
return path
63-
64-
6569
def restore() -> None:
6670
_private.restore_build_dir_from_backup()
6771

0 commit comments

Comments
 (0)