-
Notifications
You must be signed in to change notification settings - Fork 393
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
Is it possible to keep the standard behaviour when clicking on a Python script? #224
Comments
Hello @amarandon , thanks for your feedback. I understand that this comes as a surprise to your users! Actually, this question was initially raised at #183 and at that time we chose not to change the behavior. But we can have another look at this, certainly. For now the option you have is to disable Jupytext globally with jupyter serverextension disable jupytext and ask each user who want Jupytext to either activate the server extension with either the command jupyter serverextension enable jupytext --user or by including the line c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager" in his/her config file. Would that approach solve the issue you encounter? Otherwise, we could consider giving an option to classify only certain extensions as notebooks. Technically that would be rather easy - it is just a matter of changing the values returned by |
Hi @mwouts Thank you for the quick reply! I'd rather not disable Jupytext globally. I tried to override all_nb_extensions in a subclass but apparently it's not called at all when I start Jupyter Notebook. However this seems to work for me: from jupytext import TextFileContentsManager
TextFileContentsManager.nb_extensions.remove(".py")
c.NotebookApp.contents_manager_class = TextFileContentsManager Not very pretty but it does the job for now. It's true that I was kind of expecting a configuration setting that would allow to specify the list of extensions that should be opened as notebooks. |
You're welcome, that's an interesting question by the way!
I see. The server extension for Jupytext, when active, replaces the contents manager with Jupytext's one in case the current CM is not already an instance or a derived class of
I see what you mean, and as I mentioned earlier we could work on that. For now let me mention that I am little worried that if we do that, then collaborating on notebooks becomes a little more complex. As the links says, collaboration works in the following way: user A shares the notebook represented as a |
Hello, |
Hello @hoangthienan95, thanks for asking ! Well, for now you could use the approach that @amarandon documented above. I.e., modify Jupytext's content manager in your from jupytext import TextFileContentsManager
TextFileContentsManager.nb_extensions = ['.ipynb']
c.NotebookApp.contents_manager_class = TextFileContentsManager That will restore Jupyter's default classification for text files, and hence their default icon in both Jupyter Lab and Jupyter notebook. The drawback is that you won't have the 'open with notebook' entry in Jupyter Lab's contextual menu any more. Maybe a better solution, but more involved I am afraid, would be to restore the default icon in Jupyter Lab's JS interface itself, even if the file was classified as a potential notebook by Jupytext... Would you be interested in that? Maybe this PR (the contextual menu) can be of some help for this. |
Hello @amarandon , since there have been a few people asking for this, I have added the option for this in Jupytext 1.1.2. The option is documented at the end of this paragraph. Essentially you will have to include, say, c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager"
c.ContentsManager.notebook_extensions = "ipynb,Rmd" in your jupyter configuration file. |
@mwouts Fantastic! Thank you for letting me know! |
When clicking on a Python script in Jupyter Notebook, by default it opens as a notebook. It's still possible to open it with the Jupyter built-in text editor by selecting the script and clicking the Edit button. However is there a configuration settings that would preserve Jupyter default behaviour while still allowing users to pair notebooks with scripts if they wish to? That way Jupytext would be less intrusive and would require explicit opt-in from users. To give you some context, I introduced Jupytext on a multi-user JupyterHub deployment to allow some users to edit R Markdown documents as notebooks, but my Python users got surprised that their scripts where suddenly opening as notebooks and thought that it might be a bug.
The text was updated successfully, but these errors were encountered: