Using itk-vtk-viewer from local build

(Newbie question)

I want to be able to make changes to itk-vtk-viewer and test the new code within my current project.
(Geometry / Point selection · Issue #575 · Kitware/itk-vtk-viewer · GitHub)

I have forked the repo and have cloned locally.

How do I load in the code from my local version of itk-vtk-viewer so that I can see the changes when I run my project?

Thanks

@PaulHax @thewtex (tagging as have been helpful before)

I can see that the viewer_config.py file from itkwidgets points to the ITK_VIEWER_SRC location. I have cloned itkwidgets locally and created a local version of the package (python -m pip -e .) which means I can edit itkwidgets as required. I have tried pointing the ITK_VIEWER_SRC to my local folder but that is not working. How do I tell itkwidgets to use my local itk-vtk-viewer code instead of that at ITK_VIEWER_SRC = ("https://bafybeidadaazleqcepkcofenl5vvnf6uod6tjqvlkoj2ceynhbyzkku5hu.on.fleek.co/")

@Sebastien_Jourdain (tagging as have been helpful before)

I have stepped back a number of versions due to a known bug - which results in the current version of itkwidgets not working for me.

Using itkwidgets v0.32.0

To review:
I am trying to edit files (js) within itk-vtk-viewer project which are called by itkwidgets in Python, however I am unable to determine the steps to be able to do so. I am looking to add some functionality to the itkwidgets package by updating the annotations returned by some function calls within the itk-vtk-viewer js files.

I have forked itkwidgets from git and installed locally using python -m pip install -e .. I can import this package in my notebook and have confirmed that it is loaded and working as expected.

My expectation is that I should be able to point the package (itkwidgets) towards a local version of the js project (itk-vtk-viewer) so that any edits made can be observed in the notebook.

(Part I do not understand)

  • In a viewer.js file (itkwidgets) it specifies the location of the js code that I want to edit:
    • import createViewer from 'itk-vtk-viewer/src/createViewer'
  • This viewer.js file is pointed to in a index.js file:
    • const { ViewerModel, ViewerView } = require('./viewer.js');
  • and this index.js file is pointed to within the package.json file.

My original thoughts were that I should be able to change the location pointed to in viewer.js file to a local folder and it would point towards the new code. However, even if I change the line to import createViewer from '/<NON_EXISTENT_FOLDER>/src/createViewer'. The code still runs as before. If I point towards the local version, I would expect some added console.log’s to be printed, but again this does not occur.

I have tried reinstalling the package using pip following the change but that did not help either.

Any help appreciated.

Hello, sorry I missed your tag there. To point itkwidgets at your locally developed itk-vtk-viewer:

  1. Start the itk-vtk-viewer dev server: npm run start which should serve at http://localhost:8082/
  2. In the viewer_config.py file of itkwidgets, set ITK_VIEWER_SRC to http://localhost:8082/

itk-vtk-viewer needs to be served by http server. Can’t just point itkwidgets at a file.

Hope that gets you hacking.

@PaulHax Sorry, now it was my turn to miss your tag!

I appreciate this help, but as specified in my latest post above, I have to use itkwidgets v0.32.0 due to a known bug which restricts me being able to use the latest version.

Within v0.32.0, the method to link to itk-vtk-viewer is different.

@PaulHax

I have tried a few things, and believe I am on the right track, but still getting some errors.

Current steps:

  • Fork both itk-vtk-viewer and itkwidgets repos and clone locally.
  • Set itkwidgets to v0.32.0 (required version) and itk-vtk-viewer to v10.7.4 (as per version specified in package.json file from itkwidgets)

itk-vtk-viewer

  • Install/build the itk-vtk-viewer package
    • cd itk-vtk-viewer
    • npm install
  • Then create a link to the package
    • npm link

itkwidgets

  • I delete the itk-vtk-viewer info from the dependancies list in the package.json fil
    • I do not want this module installed when calling npm install
  • Install the rest of the required modules for itkwidgets
    • cd itkwidgets/js
    • npm install
  • I then need to link the itk-vtk-viewer module
    • To do this I add the following lines to the setup.py file
      • check_call([npmName, 'link', 'itk-vtk-viewer'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr)
  • I then try to install the itkwidgets package in dev mode
    • python -m pip install -e . from the parent directory

Outputs

  • The linking of the module seems to work as I can see it in the list if I call check_call(['ls','node_modules'], cwd=node_root, stdout=sys.stdout, stderr=sys.stderr) following the linking.

    • Also, when it is not added I get the following error in the output of python -m pip install -e .:
      • ERROR in ./lib/viewer.js
        Module not found: Error: Can't resolve 'itk-vtk-viewer/src/createViewer' in '/.../itkwidgets/js/lib'
  • However, am getting an error specifying:

    • rebuilding js and css failed
      missing files: ['/.../itkwidgets/itkwidgets/static/index.js']
    • This file is indeed not there. The only file created within static folder is extension.js
    • By the looks of it, it is not created due to other errors of Modules not found, for example
      • Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
      • How do I load these modules? (@thewtex, Any input here?)
    • Please find a snippet of the output below (apologies for the length)

Error Message


itkwidgets@0.32.0 build
webpack --mode production -p

:information_source: Compiling Webpack
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
:information_source: Compiling Webpack (repeated 3 times)
:heavy_check_mark: Webpack: Compiled successfully in 5.80s
Hash: 4a78116d9ef989538c9b2b50b9c939e990b653640817ccd06068362b3f638bd9ee9b1faba8410a05
Version: webpack 4.42.1
Child
Hash: 4a78116d9ef989538c9b
Time: 5825ms
Built at: 28/02/2023 10:21:29
Asset Size Chunks Chunk Names
extension.js 1.08 KiB 0 [emitted] main
Entrypoint main = extension.js
[0] ./lib/extension.js 521 bytes {0} [built]
Child
Hash: 2b50b9c939e990b65364
Time: 65384ms
Built at: 28/02/2023 10:22:29
3 assets
Entrypoint main = index.js index.js.map
[34] (webpack)/buildin/global.js 723 bytes {0} [built]
[58] external “@jupyter-widgets/base” 42 bytes {0} [built]
[81] /…/itk-vtk-viewer/src/Rendering/updateGradientOpacity.js 1.36 KiB {0} [built]
[83] /…/itk-vtk-viewer/src/UserInterface/hex2rgb.js 375 bytes {0} [built]
[85] /…/itk-vtk-viewer/src/Rendering/updateLabelMapPiecewiseFunction.js 1.89 KiB {0} [built]
[87] ./lib/index.js 694 bytes {0} [built]
[88] ./lib/viewer.js 71.1 KiB {0} [built]
[148] /…/itk-vtk-viewer/src/Rendering/updateVolumeProperties.js 1.87 KiB {0} [built]
[149] /…/itk-vtk-viewer/src/UserInterface/Image/updateTransferFunctionWidget.js 1.31 KiB {0} [built]
[161] /…/itk-vtk-viewer/src/Rendering/updateLabelMapComponentWeight.js 1.16 KiB {0} [built]
[173] ./lib/itkConfigJupyter.js 271 bytes {0} [built]
[214] /…/itk-vtk-viewer/src/createViewer.js 34.2 KiB {0} [built]
[225] /…/itk-vtk-viewer/src/vtk/proxyManagerConfiguration.js 3.1 KiB {0} [built]
[468] ./lib/lineProfiler.js 6.27 KiB {0} [built]
[469] ./package.json 1.95 KiB {0} [built]
+ 455 hidden modules

    ERROR in /.../itk-vtk-viewer/src/UserInterface/createCategoricalColorIconSelector.js
    Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
     @ /.../itk-vtk-viewer/src/UserInterface/createCategoricalColorIconSelector.js 12:18-74
     @ /.../itk-vtk-viewer/src/UserInterface/Image/createLabelMapColorWidget.js
     @ /.../itk-vtk-viewer/src/createViewer.js
     @ ./lib/viewer.js
     @ ./lib/index.js

    ERROR in /.../itk-vtk-viewer/src/UserInterface/createColorMapIconSelector.js
    Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
     @ /.../itk-vtk-viewer/src/UserInterface/createColorMapIconSelector.js 12:18-74
     @ /.../itk-vtk-viewer/src/UserInterface/Image/createColorRangeInput.js
     @ /.../itk-vtk-viewer/src/UserInterface/createImageUI.js
     @ /.../itk-vtk-viewer/src/UserInterface/index.js
     @ /.../itk-vtk-viewer/src/createViewer.js
     @ ./lib/viewer.js
     @ ./lib/index.js

    ERROR in /.../itk-vtk-viewer/src/ViewerStore.js
    Module not found: Error: Can't resolve 'eventemitter3' in '/.../itk-vtk-viewer/src'
     @ /.../itk-vtk-viewer/src/ViewerStore.js 24:43-67
     @ /.../itk-vtk-viewer/src/createViewer.js
     @ ./lib/viewer.js
     @ ./lib/index.js

    ERROR in /.../itk-vtk-viewer/src/UserInterface/addKeyboardShortcuts.js
    Module not found: Error: Can't resolve 'mousetrap' in '/.../itk-vtk-viewer/src/UserInterface'
     @ /.../itk-vtk-viewer/src/UserInterface/addKeyboardShortcuts.js 10:40-60
     @ /.../itk-vtk-viewer/src/createViewer.js
     @ ./lib/viewer.js
     @ ./lib/index.js
    Child worker:
         2 assets
        Entrypoint main = e2e5b834a5dc5a56c944.worker.js e2e5b834a5dc5a56c944.worker.js.map
           5 modules
Child
    Hash: 0817ccd06068362b3f63
    Time: 67725ms
    Built at: 28/02/2023 10:22:31
     3 assets
    Entrypoint main = index.js index.js.map
     [34] (webpack)/buildin/global.js 723 bytes {0} [built]
     [58] external "@jupyter-widgets/base" 42 bytes {0} [built]
     [81] /.../itk-vtk-viewer/src/Rendering/updateGradientOpacity.js 1.36 KiB {0} [built]
     [83] /.../itk-vtk-viewer/src/UserInterface/hex2rgb.js 375 bytes {0} [built]
     [85] /.../itk-vtk-viewer/src/Rendering/updateLabelMapPiecewiseFunction.js 1.89 KiB {0} [built]
     [87] ./lib/index.js 694 bytes {0} [built]
     [88] ./lib/viewer.js 71.1 KiB {0} [built]
    [148] /.../itk-vtk-viewer/src/Rendering/updateVolumeProperties.js 1.87 KiB {0} [built]
    [149] /.../itk-vtk-viewer/src/UserInterface/Image/updateTransferFunctionWidget.js 1.31 KiB {0} [built]
    [161] /.../itk-vtk-viewer/src/Rendering/updateLabelMapComponentWeight.js 1.16 KiB {0} [built]
    [173] ./lib/itkConfigCDN.js 114 bytes {0} [built]
    [174] ./lib/embed.js 399 bytes {0} [built]
    [215] /.../itk-vtk-viewer/src/createViewer.js 34.2 KiB {0} [built]
    [469] ./lib/lineProfiler.js 6.27 KiB {0} [built]
    [470] ./package.json 1.95 KiB {0} [built]
        + 456 hidden modules

    ERROR in /.../itk-vtk-viewer/src/UserInterface/createCategoricalColorIconSelector.js
    Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
     @ /.../itk-vtk-viewer/src/UserInterface/createCategoricalColorIconSelector.js 12:18-74
     @ /.../itk-vtk-viewer/src/UserInterface/Image/createLabelMapColorWidget.js
     @ /.../itk-vtk-viewer/src/createViewer.js
     @ ./lib/viewer.js
     @ ./lib/index.js
     @ ./lib/embed.js

    ERROR in /.../itk-vtk-viewer/src/UserInterface/createColorMapIconSelector.js
    Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
     @ /.../itk-vtk-viewer/src/UserInterface/createColorMapIconSelector.js 12:18-74
     @ /.../itk-vtk-viewer/src/UserInterface/Image/createColorRangeInput.js
     @ /.../itk-vtk-viewer/src/UserInterface/createImageUI.js
     @ /.../itk-vtk-viewer/src/UserInterface/index.js
     @ /.../itk-vtk-viewer/src/createViewer.js
     @ ./lib/viewer.js
     @ ./lib/index.js
     @ ./lib/embed.js

    ERROR in /.../itk-vtk-viewer/src/ViewerStore.js
    Module not found: Error: Can't resolve 'eventemitter3' in '/.../itk-vtk-viewer/src'
     @ /.../itk-vtk-viewer/src/ViewerStore.js 24:43-67
     @ /.../itk-vtk-viewer/src/createViewer.js
     @ ./lib/viewer.js
     @ ./lib/index.js
     @ ./lib/embed.js

    ERROR in /.../itk-vtk-viewer/src/UserInterface/addKeyboardShortcuts.js
    Module not found: Error: Can't resolve 'mousetrap' in '/.../itk-vtk-viewer/src/UserInterface'
     @ /.../itk-vtk-viewer/src/UserInterface/addKeyboardShortcuts.js 10:40-60
     @ /.../itk-vtk-viewer/src/createViewer.js
     @ ./lib/viewer.js
     @ ./lib/index.js
     @ ./lib/embed.js
    Child worker:
         2 assets
        Entrypoint main = a6481b1cabc91a7ecac9.worker.js a6481b1cabc91a7ecac9.worker.js.map
           5 modules
Child
    Hash: 8bd9ee9b1faba8410a05
    Time: 62803ms
    Built at: 28/02/2023 10:22:26
     3 assets
    Entrypoint main = labextension.js labextension.js.map
      [0] external "@babel/runtime/helpers/interopRequireDefault" 42 bytes {0} [built]
      [2] external "@babel/runtime/helpers/defineProperty" 42 bytes {0} [built]
      [3] external "@babel/runtime/helpers/interopRequireWildcard" 42 bytes {0} [built]
      [6] external "mobx" 42 bytes {0} [built]
      [7] external "@babel/runtime/helpers/toConsumableArray" 42 bytes {0} [built]
     [35] external "@babel/runtime/regenerator" 42 bytes {0} [built]
     [36] external "@babel/runtime/helpers/asyncToGenerator" 42 bytes {0} [built]
     [79] external "@jupyter-widgets/base" 42 bytes {0} [built]
     [80] ./lib/index.js 694 bytes {0} [built]
     [81] ./lib/viewer.js 71.1 KiB {0} [built]
     [82] external "jupyter-dataserializers" 42 bytes {0} [built]
    [144] ./lib/extension-jupyterlab.js 406 bytes {0} [built]
    [150] /.../itk-vtk-viewer/src/createViewer.js 34.2 KiB {0} [built]
    [386] ./lib/lineProfiler.js 6.27 KiB {0} [built]
    [387] ./package.json 1.95 KiB {0} [built]
        + 373 hidden modules

    ERROR in /.../itk-vtk-viewer/src/UserInterface/createCategoricalColorIconSelector.js
    Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
     @ /.../itk-vtk-viewer/src/UserInterface/createCategoricalColorIconSelector.js 12:18-74
     @ /.../itk-vtk-viewer/src/UserInterface/Image/createLabelMapColorWidget.js
     @ /.../itk-vtk-viewer/src/createViewer.js
     @ ./lib/viewer.js
     @ ./lib/index.js
     @ ./lib/extension-jupyterlab.js

    ERROR in /.../itk-vtk-viewer/src/UserInterface/createColorMapIconSelector.js
    Module not found: Error: Can't resolve '@thewtex/iconselect.js/lib/control/iconselect' in '/.../itk-vtk-viewer/src/UserInterface'
     @ /.../itk-vtk-viewer/src/UserInterface/createColorMapIconSelector.js 12:18-74
     @ /.../itk-vtk-viewer/src/UserInterface/Image/createColorRangeInput.js
     @ /.../itk-vtk-viewer/src/UserInterface/createImageUI.js
     @ /.../itk-vtk-viewer/src/UserInterface/index.js
     @ /.../itk-vtk-viewer/src/createViewer.js
     @ ./lib/viewer.js
     @ ./lib/index.js
     @ ./lib/extension-jupyterlab.js

    ERROR in /.../itk-vtk-viewer/src/ViewerStore.js
    Module not found: Error: Can't resolve 'eventemitter3' in '/.../itk-vtk-viewer/src'
     @ /.../itk-vtk-viewer/src/ViewerStore.js 24:43-67
     @ /.../itk-vtk-viewer/src/createViewer.js
     @ ./lib/viewer.js
     @ ./lib/index.js
     @ ./lib/extension-jupyterlab.js

    ERROR in /.../itk-vtk-viewer/src/UserInterface/addKeyboardShortcuts.js
    Module not found: Error: Can't resolve 'mousetrap' in '/.../itk-vtk-viewer/src/UserInterface'
     @ /.../itk-vtk-viewer/src/UserInterface/addKeyboardShortcuts.js 10:40-60
     @ /.../itk-vtk-viewer/src/createViewer.js
     @ ./lib/viewer.js
     @ ./lib/index.js
     @ ./lib/extension-jupyterlab.js
    Child worker:
         2 assets
        Entrypoint main = a6481b1cabc91a7ecac9.worker.js a6481b1cabc91a7ecac9.worker.js.map
           5 modules
rebuilding js and css failed
missing files: ['/.../itkwidgets/itkwidgets/static/index.js']
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/.../itkwidgets/setup.py", line 212, in <module>
    setup(**setup_args)
  File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/__init__.py", line 87, in setup
    return distutils.core.setup(**attrs)
  File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 148, in setup
    return run_commands(dist)
  File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 163, in run_commands
    dist.run_commands()
  File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 967, in run_commands
    self.run_command(cmd)
  File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/dist.py", line 1214, in run_command
    super().run_command(command)
  File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
    cmd_obj.run()
  File "/.../itkwidgets/setup.py", line 49, in run
    raise e
  File "/.../itkwidgets/setup.py", line 42, in run
    self.distribution.run_command('jsdeps')
  File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/dist.py", line 1214, in run_command
    super().run_command(command)
  File "/.../opt/anaconda3/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 986, in run_command
    cmd_obj.run()
  File "/.../itkwidgets/setup.py", line 120, in run
    check_call([npmName, 'run', 'build'], cwd=node_root,
  File "/.../opt/anaconda3/lib/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['npm', 'run', 'build']' returned non-zero exit status 2.
----------------------------------------

WARNING: Discarding file:///…/itkwidgets. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Any help here would be appreciated


Additional Notes:

  • python -m pip install -e . works sucessfully if I just build itkwidgets without amending or linking itk-vtk-viewer
    • static folder now contains index.js (plus other files)
  • Using install rather than link:
    • npm install /.../itk-vtk-viewer --save
    • Updates the package.json and package-lock.json files
    • Then tried python -m pip install -e .
      • That seems to work as well (builds without errors anyway)
      • But only if I have run it without any changes, as stated above, first. Otherwise get same error as with link