AssertionError after package imports
byersiiasa opened this issue · comments
Strange error I can't work out (v 3.1.4)
alive_bar was working nicely, then I have been changing some run settings of my script (e.g. Spyder IDE) and now stopped working.
The error I get is:
Traceback (most recent call last):
Cell In[4], line 2
with alive_bar(x) as bar:
File ~\.conda\envs\byersX\lib\contextlib.py:135 in __enter__
return next(self.gen)
File ~\.conda\envs\byersX\lib\site-packages\alive_progress\core\progress.py:328 in __alive_bar
start_monitoring()
File ~\.conda\envs\byersX\lib\site-packages\alive_progress\core\progress.py:190 in start_monitoring
hook_manager.install()
File ~\.conda\envs\byersX\lib\site-packages\alive_progress\core\hook_manager.py:94 in install
before_handlers.update({h: set_hook(h) for h in handlers}) # there can be Nones now.
File ~\.conda\envs\byersX\lib\site-packages\alive_progress\core\hook_manager.py:94 in <dictcomp>
before_handlers.update({h: set_hook(h) for h in handlers}) # there can be Nones now.
File ~\.conda\envs\byersX\lib\site-packages\alive_progress\core\hook_manager.py:86 in set_hook
return h.setStream(get_hook_for(h))
File ~\.conda\envs\byersX\lib\logging\__init__.py:1125 in setStream
self.stream = stream
File ~\.conda\envs\byersX\lib\site-packages\setuptools_scm\_log.py:28 in stream
assert value is sys.stderr
AssertionError
If I do simple example like below, works fine.
import time
from alive_progress import alive_bar
for x in 1000, 150:
with alive_bar(x) as bar:
for i in range(100):
time.sleep(.005)
bar()
As I start to import more packages or custom modules, then alive_bar raises the error above.
Have narrowed it down to this package, pyam https://github.com/IAMconsortium/pyam
import pyam
<IPython.core.display.Javascript object>
after this the alive_bar stops working.
Any ideas about this? Thank you!
Hey @byersiiasa,
It seems this pyam
package is using some log handler that won't allow installing the stream hooks.
It is not alive_bar
that raises the error, it is actually setuptools_scm:
File ~\.conda\envs\byersX\lib\site-packages\setuptools_scm\_log.py:28 in stream
assert value is sys.stderr
I'm really not sure why would a package use setuptools_scm
when not installing anything.
But, if it really does it every time, I'm afraid you would have to disable enrich_print
, so alive-progress
does not install the stream hooks.
thanks a lot @rsalmei !
Not sure what can be done on pyam
side - @danielhuppmann @phackstock does this mean something to you? Was there recent change in pyam relating to setupuptools_scm
?
There were some changes for pyam 2.0 related to the log-handling, so if pyam 1.9 worked but pyam 2.0 doesn’t, that could be the culprit…
And pyam uses setuptools_scm to dynamically assign the package-version from the git repo tags…
ok - thanks for clarifying @danielhuppmann
So, what are you going to do @byersiiasa?
@rsalmei I'll try other versions of pyam - but regrettably will I likely not use alive-progress in this case unless a very easy fix presents itself
Well, @byersiiasa, remember that you can simply pass enrich_print=False
so alive-progress
won't try to install log hooks. This simple config will make it work for sure.
Also, I'm preparing a new version that will ignore more exceptions when trying to install the hooks, including the AssertionError you got with pyam
, so it might work even with the enrich_print enabled...
Ah ok, super, thanks I'll try this next week :) valeu!
You're welcome!
v3.1.5 was just released, it should run now even with the enriching turned on...