Skip to content

Commit

Permalink
Improve image loading logic (#40)
Browse files Browse the repository at this point in the history
* Fix missing svg file in the output

* Improve logo fetching logic

* Iterate

* Fix
  • Loading branch information
martinRenou authored Jan 12, 2024
1 parent 07d83a6 commit 98c7211
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 42 deletions.
52 changes: 26 additions & 26 deletions jupyterlite_xeus/add_on.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,32 @@ def copy_kernel(self, kernel_dir, kernel_wasm, kernel_js):
# update kernel_executable path in kernel.json
kernel_spec["argv"][0] = f"xeus/bin/{kernel_js.name}"

# find logos in the directory
image_files = []
for file_type in ["*.jpg", "*.png", "*.svg"]:
image_files.extend(kernel_dir.glob(file_type))

kernel_spec["resources"] = {}
for image in image_files:
output_image = (
self.xeus_output_dir / "kernels" / kernel_dir.name / image.name
)
kernel_spec["resources"][image.stem] = str(output_image)

# copy the logo file
yield dict(
name=f"copy:{kernel_dir.name}:{image.name}",
actions=[
(
self.copy_one,
[
kernel_dir / image.name,
output_image,
],
),
],
)

# write to temp file
kernel_json = Path(self.cwd.name) / f"{kernel_dir.name}_kernel.json"
kernel_json.write_text(json.dumps(kernel_spec), **UTF8)
Expand Down Expand Up @@ -210,32 +236,6 @@ def copy_kernel(self, kernel_dir, kernel_wasm, kernel_js):
)
],
)
# copy the logo files
yield dict(
name=f"copy:{kernel_dir.name}:logos",
actions=[
(
self.copy_one,
[
kernel_dir / "logo-32x32.png",
self.xeus_output_dir
/ "kernels"
/ kernel_dir.name
/ "logo-32x32.png",
],
),
(
self.copy_one,
[
kernel_dir / "logo-64x64.png",
self.xeus_output_dir
/ "kernels"
/ kernel_dir.name
/ "logo-64x64.png",
],
),
],
)

yield from self.pack_prefix(kernel_dir=kernel_dir)

Expand Down
4 changes: 1 addition & 3 deletions jupyterlite_xeus/create_conda_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def _extract_specs(env_location, env_data):
for pip_dependency in dependency["pip"]:
# If it's a local Python package, make its path relative to the environment file
if (env_location / pip_dependency).is_dir():
pip_dependencies.append(
(env_location / pip_dependency).resolve()
)
pip_dependencies.append((env_location / pip_dependency).resolve())
else:
pip_dependencies.append(pip_dependency)

Expand Down
18 changes: 5 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,12 @@ const plugins = kernel_list.map((kernel): JupyterLiteServerPlugin<void> => {
const kernelspec = getJson('xeus/kernels/' + kernel + '/kernel.json');
kernelspec.name = kernel;
kernelspec.dir = kernel;
kernelspec.resources = {
'logo-32x32': URLExt.join(
for (const [key, value] of Object.entries(kernelspec.resources)) {
kernelspec.resources[key] = URLExt.join(
PageConfig.getBaseUrl(),
'xeus/kernels/' + kernel + '/logo-32x32.png'
),
'logo-64x64': URLExt.join(
PageConfig.getBaseUrl(),
'xeus/kernels/' + kernel + '/logo-64x64.png'
),
'logo-svg': URLExt.join(
PageConfig.getBaseUrl(),
'xeus/kernels/' + kernel + '/logo-svg.svg'
)
};
value as string
);
}

kernelspecs.register({
spec: kernelspec,
Expand Down

0 comments on commit 98c7211

Please sign in to comment.