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

Add a redirect handler to open non-notebook files from the cli #45

Merged
merged 4 commits into from
Mar 2, 2021

Conversation

jtpio
Copy link
Member

@jtpio jtpio commented Feb 22, 2021

This makes it possible to open non-notebook files from the cli, for example:

jupyter nbclassic setup.py
open-files-edit.mp4

setup.py Show resolved Hide resolved
nbclassic/notebookapp.py Outdated Show resolved Hide resolved
@jtpio
Copy link
Member Author

jtpio commented Feb 23, 2021

Starting nbclassic with this PR and:

jupyter nbclassic LICENSE

Throws the following exception in jupyter_server:

$ jupyter nbclassic LICENSE
Traceback (most recent call last):
  File "/path/to/miniforge3/envs/nbclassic/bin/jupyter-nbclassic", line 33, in <module>
    sys.exit(load_entry_point('nbclassic', 'console_scripts', 'jupyter-nbclassic')())
  File "/path/to/miniforge3/envs/nbclassic/lib/python3.9/site-packages/jupyter_server/extension/application.py", line 500, in launch_instance
    subapp = _preparse_for_subcommand(cls, args)
  File "/path/to/miniforge3/envs/nbclassic/lib/python3.9/site-packages/jupyter_server/extension/application.py", line 42, in _preparse_for_subcommand
    if re.match(r'^\w(\-?\w)*$', subc) and subc in Application.subcommands:
TypeError: argument of type 'Dict' is not iterable

It looks like passing a file name without an extension like LICENSE makes the regex check truthy here and reveals the issue:

https://github.com/jupyter-server/jupyter_server/blob/9b9b311feddf1a6769ad16553357a87984e98085/jupyter_server/extension/application.py#L42

@jtpio
Copy link
Member Author

jtpio commented Mar 2, 2021

Updated the regex to also handle files without an extension.

Tested locally with:

  • LICENSE
  • setup.py
  • Untitled.ipynb

@Zsailer
Copy link
Member

Zsailer commented Mar 2, 2021

Thanks, @jtpio. I verified this works locally for me too.

@Zsailer Zsailer merged commit 0e30d80 into jupyter:master Mar 2, 2021
@jtpio jtpio deleted the open-handler branch March 3, 2021 07:11
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 this pull request may close these issues.

3 participants