Skip to content

Commit 88ec34f

Browse files
Use github to get core meta (#51)
* use-github-to-get-core-meta * add-requests-as-dep * cache-core-data * Automatic application of license header --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 880a31d commit 88ec34f

File tree

5 files changed

+70
-13
lines changed

5 files changed

+70
-13
lines changed

jupyter_builder/core_path.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,35 @@
33

44
from pathlib import Path
55

6+
import requests
67

7-
def default_core_path() -> str:
8-
import jupyterlab
98

10-
return str(Path(jupyterlab.__file__).parent / "staging")
9+
def get_core_staging(version: str = "main") -> str:
10+
"""
11+
Fetch and cache JupyterLab core staging metadata.
12+
Returns path to the cached staging directory.
13+
"""
14+
15+
cache_root = Path.home() / ".cache" / "jupyterlab_builder" / "core"
16+
staging_path = cache_root / version
17+
18+
package_json_path = staging_path / "package.json"
19+
20+
# If already cached, reuse
21+
if package_json_path.exists():
22+
return str(staging_path)
23+
24+
# Otherwise download
25+
staging_path.mkdir(parents=True, exist_ok=True)
26+
27+
url = (
28+
"https://raw.githubusercontent.com/"
29+
f"jupyterlab/jupyterlab/{version}/"
30+
"jupyterlab/staging/package.json"
31+
)
32+
33+
r = requests.get(url, timeout=10)
34+
r.raise_for_status()
35+
36+
package_json_path.write_bytes(r.content)
37+
return str(staging_path)

jupyter_builder/extension_commands/build.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from traitlets import Bool, Unicode
77

88
from jupyter_builder.base_extension_app import BaseExtensionApp
9-
from jupyter_builder.core_path import default_core_path
109
from jupyter_builder.federated_extensions import build_labextension
1110

1211
HERE = os.path.dirname(os.path.abspath(__file__))
@@ -22,16 +21,23 @@ class BuildLabExtensionApp(BaseExtensionApp):
2221
source_map = Bool(False, config=True, help="Generate source maps")
2322

2423
core_path = Unicode(
25-
default_core_path(),
24+
"",
2625
config=True,
2726
help="Directory containing core application package.json file",
2827
)
2928

29+
core_version = Unicode(
30+
"main",
31+
config=True,
32+
help="Version of JupyterLab core to use when building (ignored if core-path is set)",
33+
)
34+
3035
aliases = { # noqa: RUF012
3136
"static-url": "BuildLabExtensionApp.static_url",
3237
"development": "BuildLabExtensionApp.development",
3338
"source-map": "BuildLabExtensionApp.source_map",
3439
"core-path": "BuildLabExtensionApp.core_path",
40+
"core-version": "BuildLabExtensionApp.core_version",
3541
}
3642

3743
def run_task(self):
@@ -43,6 +49,7 @@ def run_task(self):
4349
static_url=self.static_url or None,
4450
source_map=self.source_map,
4551
core_path=self.core_path or None,
52+
core_version=self.core_version or None,
4653
)
4754

4855

jupyter_builder/extension_commands/watch.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from traitlets import Bool, Unicode
77

88
from jupyter_builder.base_extension_app import BaseExtensionApp
9-
from jupyter_builder.core_path import default_core_path
109
from jupyter_builder.federated_extensions import watch_labextension
1110

1211
HERE = os.path.dirname(os.path.abspath(__file__))
@@ -20,15 +19,22 @@ class WatchLabExtensionApp(BaseExtensionApp):
2019
source_map = Bool(False, config=True, help="Generate source maps")
2120

2221
core_path = Unicode(
23-
default_core_path(),
22+
"",
2423
config=True,
2524
help="Directory containing core application package.json file",
2625
)
2726

27+
core_version = Unicode(
28+
"main",
29+
config=True,
30+
help="Version of JupyterLab core to use when watching (ignored if core-path is set)",
31+
)
32+
2833
aliases = { # noqa: RUF012
2934
"core-path": "WatchLabExtensionApp.core_path",
3035
"development": "WatchLabExtensionApp.development",
3136
"source-map": "WatchLabExtensionApp.source_map",
37+
"core-version": "WatchLabExtensionApp.core_version",
3238
}
3339

3440
def run_task(self):
@@ -41,6 +47,7 @@ def run_task(self):
4147
development=self.development,
4248
source_map=self.source_map,
4349
core_path=self.core_path or None,
50+
core_version=self.core_version or None,
4451
)
4552

4653

jupyter_builder/federated_extensions.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from tomli import load
3434

3535
from .commands import _test_overlap
36-
from .core_path import default_core_path
36+
from .core_path import get_core_staging
3737

3838
DEPRECATED_ARGUMENT = object()
3939

@@ -197,10 +197,18 @@ def develop_labextension_py( # noqa: PLR0913
197197

198198

199199
def build_labextension( # noqa: PLR0913
200-
path, logger=None, development=False, static_url=None, source_map=False, core_path=None
200+
path,
201+
logger=None,
202+
development=False,
203+
static_url=None,
204+
source_map=False,
205+
core_path=None,
206+
core_version=None,
201207
):
202208
"""Build a labextension in the given path"""
203-
core_path = default_core_path() if core_path is None else str(Path(core_path).resolve())
209+
core_path = (
210+
get_core_staging(core_version) if core_path is None else str(Path(core_path).resolve())
211+
)
204212
ext_path = str(Path(path).resolve())
205213

206214
if logger:
@@ -220,10 +228,18 @@ def build_labextension( # noqa: PLR0913
220228

221229

222230
def watch_labextension( # noqa: PLR0913
223-
path, labextensions_path, logger=None, development=False, source_map=False, core_path=None
231+
path,
232+
labextensions_path,
233+
logger=None,
234+
development=False,
235+
source_map=False,
236+
core_path=None,
237+
core_version=None,
224238
):
225239
"""Watch a labextension in a given path"""
226-
core_path = default_core_path() if core_path is None else str(Path(core_path).resolve())
240+
core_path = (
241+
get_core_staging(core_version) if core_path is None else str(Path(core_path).resolve())
242+
)
227243
ext_path = str(Path(path).resolve())
228244

229245
if logger:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ classifiers = [
2929
"Programming Language :: Python :: 3.11",
3030
"Programming Language :: Python :: 3.12",
3131
]
32-
dependencies = ["traitlets", "jupyterlab_server"]
32+
dependencies = ["traitlets", "requests", "jupyterlab_server"]
3333
dynamic = ["version"]
3434

3535
[project.urls]

0 commit comments

Comments
 (0)