--iversions returns an error if no package has been imported
pareyesv opened this issue · 1 comments
pareyesv commented
Example (watermark v1.8.1):
%load_ext watermark
%watermark --iversions
the output (traceback) is the following:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-f12554b3f891> in <module>
----> 1 get_ipython().run_line_magic('watermark', '--iversions')
~/.pyenv/versions/miniconda3-latest/envs/myenvname/lib/python3.7/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2311 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2312 with self.builtin_trap:
-> 2313 result = fn(*args, **kwargs)
2314 return result
2315
</home/myusername/.pyenv/versions/miniconda3-latest/envs/myenvname/lib/python3.7/site-packages/decorator.py:decorator-gen-126> in watermark(self, line)
~/.pyenv/versions/miniconda3-latest/envs/myenvname/lib/python3.7/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
~/.pyenv/versions/miniconda3-latest/envs/myenvname/lib/python3.7/site-packages/watermark/watermark.py in watermark(self, line)
133 self._get_git_branch(bool(args.machine))
134 if args.iversions:
--> 135 self._print_all_import_versions(self.shell.user_ns)
136 if args.watermark:
137 if self.out:
~/.pyenv/versions/miniconda3-latest/envs/myenvname/lib/python3.7/site-packages/watermark/watermark.py in _print_all_import_versions(vars)
245 continue
246
--> 247 longest = max([len(i[0]) for i in to_print]) + 1
248 for entry in to_print:
249 print(('%s' % entry[0]).ljust(longest) + entry[1])
ValueError: max() arg is an empty sequence
rasbt commented
Thanks for the note. I can confirm that when this is the first entry executed in a code cell, the same error occurs (prob. because no package has been imported, like you mentioned). This should be fixed though such that if no package has been imported, the code should just print an empty string instead of an error. (If someone has a better suggestion, instead of printing an empty string, I'd be happy to hear.)
I am currently traveling and probably won't get to it immediately, but will try to fix that in the next couple of days.