giovannipizzi / aiida-node-shell

Proof of concept of a way to easily browse AiiDA nodes through an interactive, customisable shell with tab completion
MIT License
6 stars 1 forks source link

Calling tab-complete on `attr` raises `AttributeError` #7

Closed sphuber closed 4 years ago

sphuber commented 4 years ago

with debug on, after loading a node, typing attr and activating tab-completion, raises:

(WorkChainNode<20241>@django) attr 
Traceback (most recent call last):
  File "/home/sph/.virtualenvs/aiida_dev/lib/python3.8/site-packages/cmd2/cmd2.py", line 1816, in complete
    self._completion_for_command(text, line, begidx, endidx, shortcut_to_restore)
  File "/home/sph/.virtualenvs/aiida_dev/lib/python3.8/site-packages/cmd2/cmd2.py", line 1701, in _completion_for_command
    self.completion_matches = self._redirect_complete(text, line, begidx, endidx, compfunc)
  File "/home/sph/.virtualenvs/aiida_dev/lib/python3.8/site-packages/cmd2/cmd2.py", line 1481, in _redirect_complete
    return compfunc(text, line, begidx, endidx)
  File "/home/sph/.virtualenvs/aiida_dev/lib/python3.8/site-packages/cmd2/cmd2.py", line 1866, in _complete_argparse_command
    return completer.complete_command(tokens_to_parse, text, line, begidx, endidx, cmd_set=cmd_set)
  File "/home/sph/.virtualenvs/aiida_dev/lib/python3.8/site-packages/cmd2/argparse_completer.py", line 434, in complete_command
    completion_results = self._complete_for_arg(pos_arg_state, text, line,
  File "/home/sph/.virtualenvs/aiida_dev/lib/python3.8/site-packages/cmd2/argparse_completer.py", line 617, in _complete_for_arg
    cmd_set = self._cmd2_app._resolve_func_self(arg_choices.to_call, cmd_set)
  File "/home/sph/.virtualenvs/aiida_dev/lib/python3.8/site-packages/cmd2/cmd2.py", line 4785, in _resolve_func_self
    func_class = get_defining_class(cmd_support_func)
  File "/home/sph/.virtualenvs/aiida_dev/lib/python3.8/site-packages/cmd2/utils.py", line 1091, in get_defining_class
    cls = getattr(inspect.getmodule(meth),
AttributeError: module '__main__' has no attribute 'AiiDANodeShell'
EXCEPTION of type 'AttributeError' occurred with message: 'module '__main__' has no attribute 'AiiDANodeShell''
giovannipizzi commented 4 years ago

You are right - one should actually install this as a python module and put the main in a different file, otherwise it does not detect the class. I was hoping not to make a python module just for this for now, but maybe I could make a simple setup.py in the end, what do you think? (The goal would be not to have it as a standalone, but maybe while we use it, it's OK to make a "temporary" package, maybe we don' distribute on pip).

sphuber commented 4 years ago

I think that for testing purposes and on-boarding other people, it would be nice if tab-completion works. Creating a simple setup.py to install should not be too much work. Putting on PyPI is not necessary I would say