Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: t.currentWidget.context.model.metadata.has is not a function with JupyterLab 4 #1054

Closed
mgunyho opened this issue Mar 29, 2023 · 26 comments

Comments

@mgunyho
Copy link

mgunyho commented Mar 29, 2023

Hello,

I was trying out JupyterLab 4 (4.0.0b0), and noticed that jupytext doesn't work. When I open JupyterLab, the browser console gets filled with the following error message several times:

console output
TypeError: t.currentWidget.context.model.metadata.has is not a function
    e http://localhost:8890/lab/extensions/jupyterlab-jupytext/static/568.5f8c2e2ac5a41b57f216.js?v=5f8c2e2ac5a41b57f216:1
    u http://localhost:8890/lab/extensions/jupyterlab-jupytext/static/568.5f8c2e2ac5a41b57f216.js?v=5f8c2e2ac5a41b57f216:1
    isToggled http://localhost:8890/lab/extensions/jupyterlab-jupytext/static/568.5f8c2e2ac5a41b57f216.js?v=5f8c2e2ac5a41b57f216:1
    isToggled http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    get isToggled http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    createItemClass http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    renderItem http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    onUpdateRequest http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    processMessage http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    C http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    r http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    _ http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    n http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    promise callback*37192/n http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    b http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    s http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    update http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    refresh http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    hideAndReset http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    handleEvent http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    onAfterShow http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    processMessage http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    C http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    r http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    show http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    onActivateRequest http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    processMessage http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    C http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    r http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    _ http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    n http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    promise callback*37192/n http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    b http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    s http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    activate http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    execute http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    execute http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    _executeKeyBinding http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    processKeydownEvent http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    evtKeydown http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
    handleEvent http://localhost:8890/static/lab/jlab_core.fb8ee545cf9dfd6b68f1.js?v=fb8ee545cf9dfd6b68f1:1
jlab_core.fb8ee545cf9dfd6b68f1.js:1:1597138

Also, if I open the command palette, the search doesn't work, and whenever I type something the error appears in the console.

This happens both on Firefox and Chrome.

I can reproduce this with an environment created from scratch:

$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ pip install --pre jupyterlab
(venv) $ pip install jupytext
(venv) $ jupyter --version

IPython          : 8.11.0
ipykernel        : 6.22.0
ipywidgets       : not installed
jupyter_client   : 8.1.0
jupyter_core     : 5.3.0
jupyter_server   : 2.5.0
jupyterlab       : 4.0.0b0
nbclient         : 0.7.2
nbconvert        : 7.2.10
nbformat         : 5.8.0
notebook         : not installed
qtconsole        : not installed
traitlets        : 5.9.0

(venv) $ pip list | grep "jupytext"

jupytext                  1.14.5

(venv) $ jupyter lab

...
[I 2023-03-29 13:46:33.070 ServerApp] jupytext | extension was successfully linked.
...

If I leave out --pre from pip install jupyterlab, I get jupyterlab 3.6.2 and this doesn't happen.

I'm not familiar with extension development, I briefly tried to look through the jupyter extension migration guide, but I couldn't see anything obvious related to this.

I'm on ubuntu 20.04. Let me know if you need more information.

@mwouts
Copy link
Owner

mwouts commented Apr 4, 2023

Thanks @mgunyho for reporting this. At the moment I am not sure where this come from. Maybe it is the JupyterLab extension that we need to port to version 4? Can you try deactivating it with jupyter labextension disable jupytext?

If you want to try and see if we can make the extension compatible with Jupyter Lab 4, this is what you would have to do

  1. Clone our project locally
  2. Replace 3.0.0 with 4.0.0 at this location:
    "dependencies": {
    "@jupyterlab/application": "^3.0.0",
    "@jupyterlab/apputils": "^3.0.0",
    "@jupyterlab/nbformat": "^3.0.0",
    "@jupyterlab/notebook": "^3.0.0"
    },
    "devDependencies": {
    "@jupyterlab/builder": "^3.0.0",
  3. Install the modified version with BUILD_JUPYTERLAB_EXTENSION=1 pip install .

Let us know if either deactivating or porting to version 4.0.0 works! Thanks

@mgunyho
Copy link
Author

mgunyho commented Apr 8, 2023

Hi,

This seems to be indeed coming from jupytext, if I disable jupytext with jupyter labextension disable jupyterlab-jupytext, the problem goes away. The exception seems to be coming from here.

I tried to install the extension locally with JupyterLab 4, but I couldn't get it to work. I changed the versions to 4.0.0-beta.1 in package.json (^4.0.0 didn't work because it's not released yet), but then I get some typescript errors, these seem to be unrelated to jupytext but I've pasted them below for reference.

output of pip install command
$ BUILD_JUPYTERLAB_EXTENSION=1 pip install .
Processing .../jupytext
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: markdown-it-py<3.0.0,>=1.0.0 in ./venv/lib/python3.10/site-packages (from jupytext==1.14.5) (2.2.0)
Requirement already satisfied: toml in ./venv/lib/python3.10/site-packages (from jupytext==1.14.5) (0.10.2)
Requirement already satisfied: mdit-py-plugins in ./venv/lib/python3.10/site-packages (from jupytext==1.14.5) (0.3.5)
Requirement already satisfied: pyyaml in ./venv/lib/python3.10/site-packages (from jupytext==1.14.5) (6.0)
Requirement already satisfied: nbformat in ./venv/lib/python3.10/site-packages (from jupytext==1.14.5) (5.8.0)
Requirement already satisfied: mdurl~=0.1 in ./venv/lib/python3.10/site-packages (from markdown-it-py<3.0.0,>=1.0.0->jupytext==1.14.5) (0.1.2)
Requirement already satisfied: traitlets>=5.1 in ./venv/lib/python3.10/site-packages (from nbformat->jupytext==1.14.5) (5.9.0)
Requirement already satisfied: fastjsonschema in ./venv/lib/python3.10/site-packages (from nbformat->jupytext==1.14.5) (2.16.3)
Requirement already satisfied: jsonschema>=2.6 in ./venv/lib/python3.10/site-packages (from nbformat->jupytext==1.14.5) (4.18.0a3)
Requirement already satisfied: jupyter-core in ./venv/lib/python3.10/site-packages (from nbformat->jupytext==1.14.5) (5.3.0)
Requirement already satisfied: jsonschema-specifications>=2023.03.6 in ./venv/lib/python3.10/site-packages (from jsonschema>=2.6->nbformat->jupytext==1.14.5) (2023.3.6)
Requirement already satisfied: attrs>=22.2.0 in ./venv/lib/python3.10/site-packages (from jsonschema>=2.6->nbformat->jupytext==1.14.5) (22.2.0)
Requirement already satisfied: rpds-py>=0.7.1 in ./venv/lib/python3.10/site-packages (from jsonschema>=2.6->nbformat->jupytext==1.14.5) (0.7.1)
Requirement already satisfied: referencing>=0.26.4 in ./venv/lib/python3.10/site-packages (from jsonschema>=2.6->nbformat->jupytext==1.14.5) (0.27.0)
Requirement already satisfied: platformdirs>=2.5 in ./venv/lib/python3.10/site-packages (from jupyter-core->nbformat->jupytext==1.14.5) (3.2.0)
Building wheels for collected packages: jupytext
  Building wheel for jupytext (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for jupytext (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [126 lines of output]
      running bdist_wheel
      running jsdeps
      Installing build dependencies with npm.  This may take a while...
      > jlpm install
      yarn install v1.21.1
      [1/4] Resolving packages...
      warning @jupyterlab/builder > terser-webpack-plugin > cacache > @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs
      [2/4] Fetching packages...
      [3/4] Linking dependencies...
      warning "@jupyterlab/application > @jupyterlab/ui-components@4.0.0-beta.1" has unmet peer dependency "react@^18.2.0".
      warning "@jupyterlab/builder > @lumino/coreutils@1.12.1" has unmet peer dependency "crypto@1.0.1".
      [4/4] Building fresh packages...
      success Saved lockfile.
      $ jlpm run clean && jlpm run build:prod
      yarn run v1.21.1
      $ jlpm run clean:lib
      $ rimraf lib tsconfig.tsbuildinfo
      Done in 1.38s.
      yarn run v1.21.1
      $ jlpm run build:lib && jlpm run build:labextension
      $ tsc
      node_modules/@jupyterlab/notebook/lib/toc.d.ts(136,10): error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
      node_modules/@lumino/polling/types/index.d.ts(14,56): error TS2304: Cannot find name 'AsyncIterable'.
      node_modules/@lumino/polling/types/poll.d.ts(61,13): error TS2339: Property 'asyncIterator' does not exist on type 'SymbolConstructor'.
      node_modules/@lumino/polling/types/poll.d.ts(61,31): error TS2304: Cannot find name 'AsyncIterableIterator'.
      node_modules/@lumino/signaling/types/index.d.ts(65,55): error TS2304: Cannot find name 'AsyncIterable'.
      node_modules/@lumino/signaling/types/index.d.ts(289,13): error TS2339: Property 'asyncIterator' does not exist on type 'SymbolConstructor'.
      node_modules/@lumino/signaling/types/index.d.ts(289,31): error TS2304: Cannot find name 'AsyncIterableIterator'.
      node_modules/@rjsf/utils/dist/index.d.ts(733,25): error TS7039: Mapped object type implicitly has an 'any' template type.
      node_modules/@rjsf/utils/dist/index.d.ts(734,29): error TS1005: ']' expected.
      node_modules/@rjsf/utils/dist/index.d.ts(734,29): error TS2304: Cannot find name 'as'.
      node_modules/@rjsf/utils/dist/index.d.ts(734,38): error TS2693: 'string' only refers to a type, but is being used as a value here.
      node_modules/@rjsf/utils/dist/index.d.ts(734,47): error TS2304: Cannot find name 'Property'.
      node_modules/@rjsf/utils/dist/index.d.ts(734,57): error TS1005: ';' expected.
      node_modules/@rjsf/utils/dist/index.d.ts(734,58): error TS1128: Declaration or statement expected.
      node_modules/@rjsf/utils/dist/index.d.ts(734,60): error TS2304: Cannot find name 'Type'.
      node_modules/@rjsf/utils/dist/index.d.ts(734,65): error TS2304: Cannot find name 'Property'.
      node_modules/@rjsf/utils/dist/index.d.ts(735,1): error TS1128: Declaration or statement expected.
      node_modules/vscode-languageserver-protocol/lib/common/protocol.diagnostic.d.ts(159,10): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[uri: string]: FullDocumentDiagnosticReport | UnchangedDocumentDiagnosticReport' instead.
      node_modules/vscode-languageserver-protocol/lib/common/protocol.diagnostic.d.ts(198,10): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[uri: string]: FullDocumentDiagnosticReport | UnchangedDocumentDiagnosticReport' instead.
      node_modules/vscode-languageserver-protocol/lib/common/protocol.diagnostic.d.ts(218,10): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[uri: string]: FullDocumentDiagnosticReport | UnchangedDocumentDiagnosticReport' instead.
      node_modules/vscode-languageserver-types/lib/umd/main.d.ts(893,10): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[uri: string]: TextEdit[]' instead.
      node_modules/vscode-languageserver-types/lib/umd/main.d.ts(917,10): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[id: string]: ChangeAnnotation' instead.
      src/index.ts(112,62): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(115,92): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(129,70): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(158,63): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(159,96): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(240,101): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(312,69): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(323,68): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(332,66): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(370,67): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(373,97): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(384,67): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(387,97): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(402,67): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(405,97): error TS2349: This expression is not callable.
        No constituent of type 'PartialJSONValue' is callable.
      src/index.ts(463,7): error TS2345: Argument of type '{ name: string; fileTypes: string[]; modelName: string; preferKernel: boolean; canStartKernel: boolean; rendermime: IRenderMimeRegistry; contentFactory: NotebookPanel.IContentFactory; ... 5 more ...; translator: ITranslator; }' is not assignable to parameter of type 'IOptions<NotebookPanel>'.
        Object literal may only specify known properties, and 'sessionDialogs' does not exist in type 'IOptions<NotebookPanel>'.
      error Command failed with exit code 1.
      info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
      error Command failed with exit code 1.
      info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
      error Command failed with exit code 1.
      info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
      Traceback (most recent call last):
        File ".../jupytext/venv/lib64/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 351, in <module>
          main()
        File ".../jupytext/venv/lib64/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 333, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File ".../jupytext/venv/lib64/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 249, in build_wheel
          return _build_backend().build_wheel(wheel_directory, config_settings,
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 413, in build_wheel
          return self._build_with_temp_dir(['bdist_wheel'], '.whl',
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 398, in _build_with_temp_dir
          self.run_setup()
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 335, in run_setup
          exec(code, locals())
        File "<string>", line 170, in <module>
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/setuptools/__init__.py", line 108, in setup
          return distutils.core.setup(**attrs)
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 1221, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/jupyter_packaging/setupbase.py", line 503, in run
          [self.run_command(cmd) for cmd in cmds]
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/jupyter_packaging/setupbase.py", line 503, in <listcomp>
          [self.run_command(cmd) for cmd in cmds]
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 1221, in run_command
          super().run_command(command)
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/jupyter_packaging/setupbase.py", line 274, in run
          c.run()
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/jupyter_packaging/setupbase.py", line 379, in run
          run(npm_cmd + ['install'], cwd=node_package)
        File "/tmp/pip-build-env-q_u8s3wb/overlay/lib/python3.10/site-packages/jupyter_packaging/setupbase.py", line 225, in run
          return subprocess.check_call(cmd, **kwargs)
        File "/usr/lib64/python3.10/subprocess.py", line 369, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['/tmp/pip-build-env-q_u8s3wb/overlay/bin/jlpm', 'install']' returned non-zero exit status 1.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for jupytext
Failed to build jupytext
ERROR: Could not build wheels for jupytext, which is required to install pyproject.toml-based projects

If I install with BUILD_JUPYTERLAB_EXTENSION=1 pip install -e . (with the added -e), the command succeeds, but the extension is not listed in jupyter labextension list, so it's probably not really building the jupyterlab extension?

I also tried to run BUILD_JUPYTERLAB_EXTENSION=1 jupyter labextension develop . --overwite as suggested in these (outdated?) instructions, but then I get the error

.../jupytext/venv/lib64/python3.10/site-packages/jupyterlab/debuglog.py:57: UserWarning: FileNotFoundError: [Errno 2] No such file or directory: '.../jupytext/jupytext/package.json'

when running the command in the root of the repo. If I run the same command in the folder packages/labextension, I get the error The Python package '.' is not a valid package, it is missing the 'setup.py' file..

Just to confirm, I also tried to install the extension with the package.json unchanged in a virtualenv with jupyterlab 3, and everything works fine there. So maybe porting to JL4 requires a bit more work?

@mgunyho
Copy link
Author

mgunyho commented Apr 8, 2023

Okay, I followed the extension migration guide and ran the upgrade script using

python -m jupyterlab.upgrade_extension .

in the packages/labextension folder. This updated package.json and also tsconfig.json, and now the typescript error is indeed coming from jupytext:

  × Building wheel for jupytext (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [134 lines of output]
      running bdist_wheel
      running jsdeps
      Installing build dependencies with npm.  This may take a while...
      > jlpm install
      yarn install v1.21.1
      [1/4] Resolving packages...
      [2/4] Fetching packages...
      [3/4] Linking dependencies...
      warning "@jupyterlab/application > @jupyterlab/ui-components@4.0.0-beta.1" has unmet peer dependency "react@^18.2.0".
      warning "@jupyterlab/application > @jupyterlab/docregistry > @jupyter/ydoc > @jupyterlab/nbformat > @lumino/coreutils@1.12.1" has unmet peer dependency "crypto@1.0.1".
      warning " > style-loader@3.3.2" has unmet peer dependency "webpack@^5.0.0".
      warning " > css-loader@6.7.3" has unmet peer dependency "webpack@^5.0.0".
      warning " > source-map-loader@1.1.3" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
      [4/4] Building fresh packages...
      success Saved lockfile.
      $ jlpm run clean && jlpm run build:prod
      yarn run v1.21.1
      $ jlpm run clean:lib
      $ rimraf lib tsconfig.tsbuildinfo
      Done in 1.98s.
      yarn run v1.21.1
      $ jlpm run build:lib && jlpm run build:labextension
      $ tsc
      src/index.ts(112,8): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
      src/index.ts(112,8): error TS18049: 'notebook_tracker.currentWidget.context.model.metadata.has' is possibly 'null' or 'undefined'.

along with about 50 other errors from index.ts. So the migration indeed needs some work.

@mwouts
Copy link
Owner

mwouts commented May 9, 2023

I will try to work on this in the following weeks. I might use either the extension migration guide, or recode the extension from scratch using the extension tutorial (since it's a fairly basic extension).

If I can, I will also try to provide the same Jupytext menu that we had in Jupyter Notebook.

Also ideally I would prefer the extension logo to use the project logo, not my user picture 😄

@JasonWeill may I ask you how a rough estimate for how much time we have before Jupyter Lab 4.0 gets released ? I see that jupyterlab-4.0.0rc1 is out already - it's just that I need to plan some time to work on this, if possible ahead of the release.

Meanwhile as noted above by @mgunyho the extension can be disabled using jupyter labextension disable jupyterlab-jupytext (and you can still open text notebooks as notebooks, the only thing you cannot do without the extension is to pair notebooks individually)

@zhengpd
Copy link

zhengpd commented May 17, 2023

I guess this is why the jupytext commands not showing up in jupyterlab. Got confused when commands not shown like the docs said, until seeing this issue.

@JasonWeill
Copy link

@mwouts JupyterLab 4.0.0 was released this past Monday, May 15.

@mwouts
Copy link
Owner

mwouts commented May 18, 2023

I've seen this! And it matters a lot to me, but I also happen to have a full-time day job.

I will see what I can do, but any help here would be much appreciated 😀

@mwouts
Copy link
Owner

mwouts commented May 18, 2023

I am trying to follow the extension tutorial.

Since the extension tutorial seems to require that the extension has its own repository, I have unarchived https://github.com/mwouts/jupyterlab-jupytext/ (Q: if I package the extension separately from jupytext, I will probably have to take a dependency from jupytext onto jupyterlab-jupytext to get the extension installed automatically?)

The corresponding PR is mwouts/jupyterlab-jupytext#3, however I have not yet been able to test it. The command pip install -ve . fails with an error that seems similar to jupyterlab/jupyterlab#13224. I have tried to run jlpm cache clean but the issue remains. Any suggestion?

@krassowski
Copy link

fails with an error that seems similar to

What is the exact error you see?

@mwouts
Copy link
Owner

mwouts commented Jun 2, 2023

Well I just gave it another try. If I run pip install -ve . on an empty new extension created with copier, then the command works fine. If I run it on mwouts/jupyterlab-jupytext#3 then I get this output:

(...)
 ➤ YN0000: └ Completed in 0s 210ms
  ➤ YN0000: ┌ Fetch step
  ➤ YN0000: └ Completed in 0s 242ms
  ➤ YN0000: ┌ Link step
  ➤ YN0000: └ Completed in 0s 294ms
  ➤ YN0000: Done with warnings in 0s 791ms
  INFO:hatch_jupyter_builder.utils:> /tmp/pip-build-env-85x51pux/overlay/bin/jlpm run install:extension
  src/index.ts(112,8): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(112,8): error TS18049: 'notebook_tracker.currentWidget.context.model.metadata.has' is possibly 'null' or 'undefined'.
  src/index.ts(112,62): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(115,38): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(115,92): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(129,16): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(129,70): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(158,9): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(158,9): error TS18049: 'notebook_tracker.currentWidget.context.model.metadata.has' is possibly 'null' or 'undefined'.
  src/index.ts(158,63): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(159,42): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(159,96): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(240,48): error TS18047: 'notebookTracker.currentWidget' is possibly 'null'.
  src/index.ts(240,48): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(240,101): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(257,17): error TS2322: Type 'string | undefined' is not assignable to type 'string'.
    Type 'undefined' is not assignable to type 'string'.
  src/index.ts(257,46): error TS18047: 'notebookTracker.currentWidget' is possibly 'null'.
  src/index.ts(312,16): error TS18047: 'notebookTracker.currentWidget' is possibly 'null'.
  src/index.ts(312,16): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(312,16): error TS18049: 'notebookTracker.currentWidget.context.model.metadata.has' is possibly 'null' or 'undefined'.
  src/index.ts(312,69): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(323,15): error TS18047: 'notebookTracker.currentWidget' is possibly 'null'.
  src/index.ts(323,15): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(323,68): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(332,13): error TS18047: 'notebookTracker.currentWidget' is possibly 'null'.
  src/index.ts(332,13): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(332,66): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(370,14): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(370,14): error TS18049: 'notebookTracker.currentWidget.context.model.metadata.has' is possibly 'null' or 'undefined'.
  src/index.ts(370,67): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(373,44): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(373,97): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(384,14): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(384,14): error TS18049: 'notebookTracker.currentWidget.context.model.metadata.has' is possibly 'null' or 'undefined'.
  src/index.ts(384,67): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(387,44): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(387,97): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(402,14): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(402,14): error TS18049: 'notebookTracker.currentWidget.context.model.metadata.has' is possibly 'null' or 'undefined'.
  src/index.ts(402,67): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(405,44): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(405,97): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.
  src/index.ts(465,7): error TS2322: Type 'ITranslator | null' is not assignable to type 'ITranslator | undefined'.
    Type 'null' is not assignable to type 'ITranslator | undefined'.
  Traceback (most recent call last):
    File "/home/marc/miniconda3/envs/jupyterlab-ext/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 167, in prepare_metadata_for_build_editable
      hook = backend.prepare_metadata_for_build_editable
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  AttributeError: module 'hatchling.build' has no attribute 'prepare_metadata_for_build_editable'

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/home/marc/miniconda3/envs/jupyterlab-ext/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
      main()
    File "/home/marc/miniconda3/envs/jupyterlab-ext/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/marc/miniconda3/envs/jupyterlab-ext/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 176, in prepare_metadata_for_build_editable
      whl_basename = build_hook(metadata_directory, config_settings)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/pip-build-env-85x51pux/overlay/lib/python3.11/site-packages/hatchling/build.py", line 78, in build_editable
      return os.path.basename(next(builder.build(wheel_directory, ['editable'])))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/tmp/pip-build-env-85x51pux/overlay/lib/python3.11/site-packages/hatchling/builders/plugin/interface.py", line 150, in build
      build_hook.initialize(version, build_data)
    File "/tmp/pip-build-env-85x51pux/normal/lib/python3.11/site-packages/hatch_jupyter_builder/plugin.py", line 87, in initialize
      raise e
    File "/tmp/pip-build-env-85x51pux/normal/lib/python3.11/site-packages/hatch_jupyter_builder/plugin.py", line 82, in initialize
      build_func(self.target_name, version, **build_kwargs)
    File "/tmp/pip-build-env-85x51pux/normal/lib/python3.11/site-packages/hatch_jupyter_builder/utils.py", line 115, in npm_builder
      run([*npm_cmd, "run", build_cmd], cwd=str(abs_path))
    File "/tmp/pip-build-env-85x51pux/normal/lib/python3.11/site-packages/hatch_jupyter_builder/utils.py", line 229, in run
      return subprocess.check_call(cmd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/marc/miniconda3/envs/jupyterlab-ext/lib/python3.11/subprocess.py", line 413, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['/tmp/pip-build-env-85x51pux/overlay/bin/jlpm', 'run', 'install:extension']' returned non-zero exit status 1.
  error: subprocess-exited-with-error
  
  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /home/marc/miniconda3/envs/jupyterlab-ext/bin/python3.11 /home/marc/miniconda3/envs/jupyterlab-ext/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py prepare_metadata_for_build_editable /tmp/tmphxvm2xln
  cwd: /home/marc/GitHub/jupyterlab-jupytext
  Preparing editable metadata (pyproject.toml) ... error
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

In the above I notice a series of errors about index.js. The first one is

  src/index.ts(112,8): error TS2723: Cannot invoke an object which is possibly 'null' or 'undefined'.
  src/index.ts(112,8): error TS18049: 'notebook_tracker.currentWidget.context.model.metadata.has' is possibly 'null' or 'undefined'.
  src/index.ts(112,62): error TS2349: This expression is not callable.
    No constituent of type 'string | number | boolean | PartialJSONObject | PartialJSONArray' is callable.

which is the same error as in the title of this issue!

This probably means that most of the work involved in fixing the extension is about fixing index.ts. @krassowski , has the INotebookTracker interface changed? Could you recommend an editor/development environment setup where I could explore that interface and find out how to access the notebook metadata?

NB: If it is correct that the fix will be mostly on index.js, then if possible, I would prefer to fix this in the main jupytext directory, unless of course you have a different recommendation.

@ethanmsl
Copy link

ethanmsl commented Jun 4, 2023

Thanks for working on this.
Side Note: I'd suggest adjusting the compatibility of the module to require something like jupyter-lab ... <4.0.0 until compatibility is established. Will probably help a number of people that would otherwise think the core functionality is broken, among other things.

(made a pull request to, I believe, that effect: PR_1071)

@parmentelat
Copy link
Contributor

I will see what I can do, but any help here would be much appreciated 😀

in case it is indeed helpful, please see this PR
mwouts/jupyterlab-jupytext#4

where the pip install issue is fixed

@parmentelat
Copy link
Contributor

double-checking:

I restarted from a freshly cloned repo, conda activate'd into an env that has jupyterlab 4.0.1 installed, and did

jlpm install
pip install -e .

@parmentelat
Copy link
Contributor

about using a different icon I have asked the question on discourse here
https://discourse.jupyter.org/t/how-to-choose-a-different-icon-for-my-extension/19709

@parmentelat
Copy link
Contributor

parmentelat commented Jun 4, 2023

as far as I can tell this hacky first step works reasonably, at least I have not found any big glitch when giving it a quick try around


the one thing that stood out though, is that when double-clicking in the file browser on a text-encoded notebook, it opens with the Editor and not as a Notebook

at some point in time I had that working (I mean double clicking did open as a notebook) once I had put the following in place

cat ~/.jupyter/labconfig/default_setting_overrides.json
{
  "@jupyterlab/docmanager-extension:plugin": {
    "defaultViewers": {
      "markdown": "Jupytext Notebook",
      "myst": "Jupytext Notebook",
      "r-markdown": "Jupytext Notebook",
      "quarto": "Jupytext Notebook",
      "julia": "Jupytext Notebook",
      "python": "Jupytext Notebook",
      "r": "Jupytext Notebook"
    }
  }
}

however I am in no position right now to say if that was still working for me in jlab3
so I am not sure whether this is related to the current topic (jlab4) or some other unrelated change

@mwouts
Copy link
Owner

mwouts commented Jun 4, 2023

Hey @parmentelat , @ethanmsl , thank you this is super helpful! I will try to deliver an updated version tonight. More precisely, my plan is to

  1. fix the CI, that has been broken by both the jupyterlab4 release and the quarto update
  2. ship a last version of jupytext that works in JupyterLab3
  3. and then, based on @parmentelat 's PR prepare a release candidate that might work with JupyterLab4.

@parmentelat
Copy link
Contributor

sounds great !
because my own extension only work in jlab4, and all my notebooks are jupytext-based, I'm super eager to give all this a try !

@mwouts
Copy link
Owner

mwouts commented Jun 4, 2023

I have seen the tentative version of the extension working with Jupyter Lab 4 - thank you so much @parmentelat!

This is how I installed it:

# Install jupytext
pip install jupytext

# Uninstall the extension 1.3.9 binded with Jupytext (that one only works with JLab 3)
jupyter labextension uninstall jupytext

# Install the development version of the extension
pip install git+https://github.com/mwouts/jupyterlab-jupytext.git@jupyterlab4

In the coming days, I would like to

  • See how we can fix the option to open text notebooks with a double click (cf @parmentelat 's comment above)
  • Understand if we can continue shipping the new extension directly within Jupytext, or not
  • If we have to move it to the other repository, then I'd like to keep the full history of index.ts there

@parmentelat
Copy link
Contributor

as far as the first bullet, I have asked the jupyter discourse for insights:
https://discourse.jupyter.org/t/defining-jupytext-as-the-default-viewer-for-text-notebooks-under-jlab4/19730

nothing ventured nothing gained ;)

@parmentelat
Copy link
Contributor

parmentelat commented Jun 7, 2023

about bullet 1 (double-clicking opens a notebook instead of an editor or other preview)

I managed to get that to work, doing the following

  • one-line change in index.ts (stupid me, the line explicitly says it is required within jlab4...)
    please merge this PR add a label field to the widget factory jupyterlab-jupytext#5
  • the configuration; it can now be done
    • either through the Settings dialog (Settings → Document Manager → Default Viewers)

    • or in config files; one way to do it is to write something like this (add more file types of course if needed)

      cat ~/.jupyter/labconfig/default_setting_overrides.json
      {
        "@jupyterlab/docmanager-extension:plugin": {
            "defaultViewers": {
                "python": "Jupytext Notebook",
                "markdown": "Jupytext Notebook"
          }
        }
      }

IMPORTANT NOTE
about the config files, I'd like to report how I screwed up at first, because it may be confusing:

it took me some time to figure that in my own case I also had the same settings in another file under ~/.jupyter, and namely

cd
find .jupyter -type f | xargs grep defaultViewers
.jupyter/labconfig/default_setting_overrides.json:    "defaultViewers": {
.jupyter/lab/user-settings/@jupyterlab/docmanager-extension/plugin.jupyterlab-settings:    "defaultViewers": {

(see also https://discourse.jupyter.org/t/defining-jupytext-as-the-default-viewer-for-text-notebooks-under-jlab4/19730/2?u=parmentelat)
it is not quite clear to me which one wins over the other
regardless, my recommendation is to clean that up before messing with that setting

@mwouts
Copy link
Owner

mwouts commented Jun 7, 2023

Thank you @parmentelat , that is really promising!

I hope I will be able to find some time in the coming days / week-end to finalize this.

I think what is probably going to happen next is that we will move the JupyterLab extension for Jupytext in that other repository. There we would provide one version of the extension for JupyterLab 3 and one other for JupyterLab 4. jupytext would then have a dependency on jupyterlab-jupytext. This would also mean that, for the first time, jupytext would get a dependency on jupyterlab. I guess that is allright, let me know if you think otherwise.

NB: I wrote a detailed plan here

@nattaylor
Copy link

It took me a long time to find this thread :)

I found I was unable to uninstall the extension with jupyter labextension uninstall jupytext so I just used rm and then was able to pip install the tagged version and it worked.

@parmentelat
Copy link
Contributor

hi @nattaylor
thanks for reporting this
can you please be more explicit on what you call the tagged version ?

also for the record the latest attempt at addressing this is in this PR
#1092

@nattaylor
Copy link

Sorry, what I meant was that installation was successful with @mwouts 's fork and branch (mwouts/jupyterlab-jupytext.git@jupyterlab4)

@tonykploomber
Copy link

Hi @mwouts,
I am suffering from the pip install -ve . issue from my side, do you mind to share how you fix that?

@mwouts
Copy link
Owner

mwouts commented Jul 30, 2023

This has been solved in jupytext==1.15.0. Thanks to @parmentelat , the embedded extension is now compatible with both JLab 3 and 4!

Those who installed the temporary workaround will need to uninstall it. In other words, the new instructions are

pip uninstall jupyterlab-jupytext
pip install 'jupytext>=1.15.0'

@mwouts mwouts closed this as completed Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants