googlecolab / colabtools

Python libraries for Google Colaboratory
Apache License 2.0
2.17k stars 705 forks source link

? (%pdoc), ?? (%psource), and %pfile open in accumulating sidebar tabs named 'Help' instead of displaying inline in output cells #4816

Open westurner opened 2 weeks ago

westurner commented 2 weeks ago

Describe the current behavior ? (%pdoc), ?? (%psource), and %pfile open in accumulating sidebar tabs named 'Help' instead of displaying inline in an output cell

Describe the expected behavior Display the output of at least %pdoc, %pfile, and %psource as output cells in the notebook and in the .ipynb.

When I run %pfile,%psource in all other notebook implementations including IPython.notebook and Retrolab, they display the output in an output cell in the notebook, so that when users scroll through the notebook in order, they see the output after the input.

Additional context A notebook in percent format that also runs as one input cell:

# %%
import pkg_resources
stylesdir = pkg_resources.resource_filename("matplotlib", "mpl-data/stylelib")
!ls {stylesdir}

# %%
%pfile {stylesdir}/dark_background.mplstyle

# %%
%psource {stylesdir}/dark_background.mplstyle
#!cat {stylesdir}/dark_background.mplstyle

# %%
pkg_resources.resource_filename?
?pkg_resources.resource_filename
%pdoc pkg_resources.resource_filename?

# %%
pkg_resources.resource_filename??
??pkg_resources.resource_filename
%psource pkg_resources.resource_filename

? (%pdoc) and ?? (%psource) are great for showing docstrings in tutorials, but it's frustrating and less accessible to have to click through indistinct 'Help' tabs that accumulate over notebook runs than to display the output inline like all other notebook output.

cperry-goog commented 1 week ago

(pasting in from a team member not on github yet!)

This is a decision that was essentially made prior to Jupyter's release, IPython does not treat ? or ?? as an output, it is merely piping an interactive terminal output to the terminal. This is easy to verify by running any ? or ?? query and then printing the Out variable. We have decided to not treat these outputs as the same since in most cases they are transitory, i.e. users typically want to check the pydoc quickly but will rewrite the cell code to be what their true intentions are; but having that pydoc still available as they test their code has proven generally useful for users.

As workarounds, the python help function will print out the pydoc in the cell output. and the inspect package is great for checking source code and other internal intricacies. An added benefit to this workaround is that since it is pure python and not contingent on Jupyter or IPython API implementation the resulting cell outputs will be the consistent across all Python based environments.

westurner commented 1 week ago

I cannot recommend your implementation for this very annoying reason.

Users should not need to rewrite notebooks for this implementation just.

It is UI wrong to open open tabs that obscure the screen (where the original and other implementations do not)

It would be easy to add a configuration option for this.

Couldn't the %psource magic emit output? That might could be better upstream.

Workaround: Just write in (inspect.getargspec(), inspect.getsource()) instead of ?

On Thu, Sep 5, 2024, 2:35 PM cperry-goog @.***> wrote:

(pasting in from a team member not on github yet!)

This is a decision that was essentially made prior to Jupyter's release, IPython does not treat ? or ?? as an output, it is merely piping an interactive terminal output to the terminal. This is easy to verify by running any ? or ?? query and then printing the Out variable. We have decided to not treat these outputs as the same since in most cases they are transitory, i.e. users typically want to check the pydoc quickly but will rewrite the cell code to be what their true intentions are; but having that pydoc still available as they test their code has proven generally useful for users.

As workarounds, the python help function will print out the pydoc in the cell output. and the inspect package is great for checking source code and other internal intricacies. An added benefit to this workaround is that since it is pure python and not contingent on Jupyter or IPython API implementation the resulting cell outputs will be the consistent across all Python based environments.

— Reply to this email directly, view it on GitHub https://github.com/googlecolab/colabtools/issues/4816#issuecomment-2332395856, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMNS4OGQLE4QNQOXUQGKTZVCP5ZAVCNFSM6AAAAABNPVJHBGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZSGM4TKOBVGY . You are receiving this because you authored the thread.Message ID: @.***>

westurner commented 1 week ago

Would you please consider adding better text than "Help" to disambiguate the tabs the accumulate from running notebooks that contain ? (%psource) calls that are an original feature of IPython?

On Thu, Sep 5, 2024, 3:14 PM Wes Turner @.***> wrote:

I cannot recommend your implementation for this very annoying reason.

Users should not need to rewrite notebooks for this implementation just.

It is UI wrong to open open tabs that obscure the screen (where the original and other implementations do not)

It would be easy to add a configuration option for this.

Couldn't the %psource magic emit output? That might could be better upstream.

Workaround: Just write in (inspect.getargspec(), inspect.getsource()) instead of ?

On Thu, Sep 5, 2024, 2:35 PM cperry-goog @.***> wrote:

(pasting in from a team member not on github yet!)

This is a decision that was essentially made prior to Jupyter's release, IPython does not treat ? or ?? as an output, it is merely piping an interactive terminal output to the terminal. This is easy to verify by running any ? or ?? query and then printing the Out variable. We have decided to not treat these outputs as the same since in most cases they are transitory, i.e. users typically want to check the pydoc quickly but will rewrite the cell code to be what their true intentions are; but having that pydoc still available as they test their code has proven generally useful for users.

As workarounds, the python help function will print out the pydoc in the cell output. and the inspect package is great for checking source code and other internal intricacies. An added benefit to this workaround is that since it is pure python and not contingent on Jupyter or IPython API implementation the resulting cell outputs will be the consistent across all Python based environments.

— Reply to this email directly, view it on GitHub https://github.com/googlecolab/colabtools/issues/4816#issuecomment-2332395856, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMNS4OGQLE4QNQOXUQGKTZVCP5ZAVCNFSM6AAAAABNPVJHBGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZSGM4TKOBVGY . You are receiving this because you authored the thread.Message ID: @.***>

westurner commented 1 week ago

UX: When editing markdown on a 10" Chromebook, the third hsplit for n x Help tabs makes it pretty difficult to edit and preview markdown.

On Thu, Sep 5, 2024, 3:18 PM Wes Turner @.***> wrote:

Would you please consider adding better text than "Help" to disambiguate the tabs the accumulate from running notebooks that contain ? (%psource) calls that are an original feature of IPython?

On Thu, Sep 5, 2024, 3:14 PM Wes Turner @.***> wrote:

I cannot recommend your implementation for this very annoying reason.

Users should not need to rewrite notebooks for this implementation just.

It is UI wrong to open open tabs that obscure the screen (where the original and other implementations do not)

It would be easy to add a configuration option for this.

Couldn't the %psource magic emit output? That might could be better upstream.

Workaround: Just write in (inspect.getargspec(), inspect.getsource()) instead of ?

On Thu, Sep 5, 2024, 2:35 PM cperry-goog @.***> wrote:

(pasting in from a team member not on github yet!)

This is a decision that was essentially made prior to Jupyter's release, IPython does not treat ? or ?? as an output, it is merely piping an interactive terminal output to the terminal. This is easy to verify by running any ? or ?? query and then printing the Out variable. We have decided to not treat these outputs as the same since in most cases they are transitory, i.e. users typically want to check the pydoc quickly but will rewrite the cell code to be what their true intentions are; but having that pydoc still available as they test their code has proven generally useful for users.

As workarounds, the python help function will print out the pydoc in the cell output. and the inspect package is great for checking source code and other internal intricacies. An added benefit to this workaround is that since it is pure python and not contingent on Jupyter or IPython API implementation the resulting cell outputs will be the consistent across all Python based environments.

— Reply to this email directly, view it on GitHub https://github.com/googlecolab/colabtools/issues/4816#issuecomment-2332395856, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMNS4OGQLE4QNQOXUQGKTZVCP5ZAVCNFSM6AAAAABNPVJHBGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZSGM4TKOBVGY . You are receiving this because you authored the thread.Message ID: @.***>

cperry-goog commented 1 week ago

You're right. Tracking this internally at b/364955129

westurner commented 1 week ago

There's a jupyterlab-sidecar that also supports sidebar output with a title and a Python API: https://github.com/jupyter-widgets/jupyterlab-sidecar

But on smaller screens moving a sidebar to a fixed header or footer hides even more of the screen

It should/could be fixed in upstream Jupyter. xeus-python probably also doesn't emit normal output for ?/%psource/? .

A generic native way to output to a movable, inlineable named panel in jupyterlab and retro notebook and colab and vscode would probably be most accessible

On Thu, Sep 5, 2024, 6:22 PM cperry-goog @.***> wrote:

You're right. Tracking this internally at b/364955129

— Reply to this email directly, view it on GitHub https://github.com/googlecolab/colabtools/issues/4816#issuecomment-2332730066, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMNS3IA2CWHX5H24JKIDLZVDKUBAVCNFSM6AAAAABNPVJHBGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZSG4ZTAMBWGY . You are receiving this because you authored the thread.Message ID: @.***>