@@ -296,7 +296,7 @@ if (launcher) {
296
296
}
297
297
` ` `
298
298
299
- Invoking the command (via the command palette or the launcher) will open a new tab with
299
+ Invoking the command (via the command palette or the launcher) will open a new tab with
300
300
an ` IFrame ` that will display static content fetched from the server extension.
301
301
302
302
**Note**
@@ -312,14 +312,14 @@ an `IFrame` that will display static content fetched from the server extension.
312
312
313
313
The server part of the extension is going to be presented in this section.
314
314
315
- You first need to install the python source code. The following will install
315
+ You first need to install the python source code. The following will install
316
316
the ` jlab_ext_example ` package in dev mode:
317
317
318
318
` ` ` bash
319
319
pip install - e .
320
320
` ` `
321
321
322
- Then you need to enable the package at the Jupyter level
322
+ Then you need to enable the package at the Jupyter level
323
323
so that it becomes a server extension.
324
324
325
325
` ` ` bash
@@ -450,7 +450,7 @@ input_data = self.get_json_body()
450
450
data = {" greetings" : " Hello {}, enjoy JupyterLab!" .format (input_data [" name" ])}
451
451
` ` `
452
452
453
- The part responsible to serve static content with a ` StaticFileHandler ` handler
453
+ The part responsible to serve static content with a ` StaticFileHandler ` handler
454
454
is the following:
455
455
456
456
` ` ` py
@@ -486,7 +486,7 @@ through package managers like `pip`.
486
486
487
487
> Note: In particular, [ ` jupyter - packaging ` ](https://github.com/jupyter/jupyter-packaging) provides helpers to package and install JS files
488
488
> with a Python package for Jupyter frontends (classical notebook,
489
- > JupyterLab,...).
489
+ > JupyterLab,...).
490
490
> As this package is a setup requirement, it needs to be specified in the ` pyproject .toml ` to be installed by ` pip ` .
491
491
492
492
The ` setup .py ` file is the entry point to describe package metadata:
@@ -497,6 +497,7 @@ The `setup.py` file is the entry point to describe package metadata:
497
497
" " "
498
498
jlab_ext_example setup
499
499
" " "
500
+ import json
500
501
import os
501
502
502
503
from jupyter_packaging import (
@@ -511,14 +512,15 @@ HERE = os.path.abspath(os.path.dirname(__file__))
511
512
name =" jlab_ext_example"
512
513
513
514
# Get our version
514
- version = get_version (os .path .join (name , " _version.py" ))
515
+ with open (os .path .join (HERE , ' package.json' )) as f :
516
+ version = json .load (f )[' version' ]
515
517
516
- lab_path = os .path .join (HERE , name , " static " )
518
+ lab_path = os .path .join (HERE , name , " labextension " )
517
519
518
520
# Representative files that should exist after a successful build
519
521
jstargets = [
520
522
os .path .join (HERE , " lib" , " index.js" ),
521
- os .path .join (HERE , name , " static " , " package.json" ),
523
+ os .path .join (lab_path , " package.json" ),
522
524
]
523
525
524
526
package_data_spec = {
@@ -530,7 +532,8 @@ package_data_spec = {
530
532
labext_name = " @jupyterlab-examples/server-extension"
531
533
532
534
data_files_spec = [
533
- (" share/jupyter/labextensions/%s" % labext_name , lab_path , " *.*" ),(" etc/jupyter/jupyter_server_config.d" ,
535
+ (" share/jupyter/labextensions/%s" % labext_name , lab_path , " **" ),
536
+ (" share/jupyter/labextensions/%s" % labext_name , HERE , " install.json" ),(" etc/jupyter/jupyter_server_config.d" ,
534
537
" jupyter-config" , " jlab_ext_example.json" ),
535
538
536
539
]
@@ -541,7 +544,7 @@ cmdclass = create_cmdclass("jsdeps",
541
544
)
542
545
543
546
cmdclass [" jsdeps" ] = combine_commands (
544
- install_npm (HERE , build_cmd =" build" , npm =[" jlpm" ]),
547
+ install_npm (HERE , build_cmd =" build:prod " , npm =[" jlpm" ]),
545
548
ensure_targets (jstargets ),
546
549
)
547
550
@@ -590,35 +593,35 @@ the frontend NPM package needs to be built and inserted in the Python package. T
590
593
done using a special ` cmdclass ` :
591
594
592
595
` ` ` py
593
- # setup .py #L42 - L50
596
+ # setup .py #L45 - L53
594
597
595
598
cmdclass = create_cmdclass (" jsdeps" ,
596
599
package_data_spec =package_data_spec ,
597
600
data_files_spec =data_files_spec
598
601
)
599
602
600
603
cmdclass [" jsdeps" ] = combine_commands (
601
- install_npm (HERE , build_cmd =" build" , npm =[" jlpm" ]),
604
+ install_npm (HERE , build_cmd =" build:prod " , npm =[" jlpm" ]),
602
605
ensure_targets (jstargets ),
603
606
)
604
607
` ` `
605
608
606
609
Basically it will build the frontend NPM package:
607
610
608
611
` ` ` py
609
- # setup .py #L48 - L48
612
+ # setup .py #L51 - L51
610
613
611
- install_npm (HERE , build_cmd =" build" , npm =[" jlpm" ]),
614
+ install_npm (HERE , build_cmd =" build:prod " , npm =[" jlpm" ]),
612
615
` ` `
613
616
614
617
It will ensure one of the generated JS files is ` lib /jlabextexample .js ` :
615
618
616
619
` ` ` py
617
- # setup .py #L23 - L26
620
+ # setup .py #L25 - L28
618
621
619
622
jstargets = [
620
623
os .path .join (HERE , " lib" , " index.js" ),
621
- os .path .join (HERE , name , " static " , " package.json" ),
624
+ os .path .join (lab_path , " package.json" ),
622
625
]
623
626
` ` `
624
627
@@ -663,9 +666,8 @@ user about that dependency by adding the `discovery` metadata to your `package.j
663
666
file:
664
667
665
668
` ` ` json5
666
- // package.json#L68-L78
669
+ // package.json#L70-L80
667
670
668
- ],
669
671
" jupyterlab" : {
670
672
"discovery" : {
671
673
"server" : {
@@ -676,20 +678,21 @@ file:
676
678
"name" : "jlab_ext_example"
677
679
}
678
680
}
681
+ },
679
682
` ` `
680
683
681
684
In this example, the extension requires a ` server ` extension:
682
685
683
686
` ` ` json5
684
- // package.json#L70-L70
687
+ // package.json#L71-L71
685
688
686
689
" discovery" : {
687
690
`` `
688
691
689
692
And that server extension is available through `pip` :
690
693
691
694
`` `json5
692
- // package.json#L71-L73
695
+ // package.json#L72-L74
693
696
694
697
"server" : {
695
698
"managers" : [
0 commit comments