jupyter / jupyter_core

Core Jupyter functionality
https://jupyter-core.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
196 stars 181 forks source link

`__version__` attribute no longer available #384

Closed joelostblom closed 9 months ago

joelostblom commented 9 months ago

It seems like __version__ has been removed from the main namespace in jupyter_core 3.6. I have noted that this had led to issues in at least two other applications that rely on being able to read the version number from __version__, see https://github.com/conda-forge/quarto-feedstock/issues/34#issuecomment-1871421353 and https://gitlab.com/joelostblom/session_info/-/issues/14 for details. Would it be possible to reintroduce the __version__ attribute (or at least mark it as deprecated for a while), or is there a reason for not using it any longer? From my understanding it is more common to have __version__ as an attribute on the main module rather than in a version.__version__ submodule, but there might very well be good reasons for the latter that I am not aware of.

I believe it happened in this PR https://github.com/jupyter/jupyter_core/pull/376 so cc @blink1073.

mfisher87 commented 9 months ago

It does look to me like an accidental API change by a Ruff autofixer, as the commit message just indicates linter fixes, and the API change was mixed in with many other safe changes, making it hard to notice.

blink1073 commented 9 months ago

Yes, this was an oversight. I'm afk this week, will make a fix release early next week.

mfisher87 commented 9 months ago

Wonderful, thank you!

dlealv commented 9 months ago

@mfisher87, @blink1073 it seems you fixed the issue, but I am not sure. What would be the process to reflect the changes? I ran pip install jupyter or pip install jupyterlab and then jupyter --version but the version that appears for jupyter core is 5.5.0:

(jupyter3) dleal:~$ jupyter --version
Selected Jupyter core packages...
IPython          : 8.18.1
ipykernel        : 6.27.1
ipywidgets       : 8.1.1
jupyter_client   : 8.6.0
jupyter_core     : 5.5.0
jupyter_server   : 2.12.1
jupyterlab       : 4.0.9
nbclient         : 0.9.0
nbconvert        : 7.12.0
nbformat         : 5.9.2
notebook         : 7.0.6
qtconsole        : 5.5.1
traitlets        : 5.14.0
(jupyter3) dleal:~$

Thanks

mfisher87 commented 9 months ago

The fix is not in quite yet, it's in open PR #386. It also adds a test and some other config to avoid regression :100:

To test if you are impacted by this issue, run python -c "import jupyter_core; print(jupyter_core.__version__)"

Unimpacted

$ python -c "import jupyter_core; print(jupyter_core.__version__)"
5.3.2

Impacted (5.6.0)

$ python -c "import jupyter_core; print(jupyter_core.__version__)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'jupyter_core' has no attribute '__version__'
blink1073 commented 9 months ago

The bug was introduced in 5.5.1, and will be fixed in 5.6.1.

dlealv commented 9 months ago

It seems the issue was fixed. I usually do: pip install jupyterlab, but the current stable version is 4.0.9, so the change hasn't been propagated to jupyter lab yet, which requires jupyter-core, as it is indicated via pip show jupyterlab in the Requires section. I don't want to install the jupyter-core alone (version 5.7.0) in case some compatibility gets broken. Please advise how to proceed. Thanks

blink1073 commented 9 months ago

pip install --no-deps jupyter_core==5.6.1 would ensure that you only update jupyter_core.