CMS 3D CMS Logo

cmscompleter.py
Go to the documentation of this file.
1 """Word completion for CMS Software.
2 Based on rlcompleter from Python 2.4.1. Included additional namespace for not loaded modules
3 Please read license in your lcg external python version
4 
5 benedikt.hegner@cern.ch
6 
7 """
8 from __future__ import absolute_import
9 from __future__ import print_function
10 # TODO: sometimes results are doubled. clean global_matches list!
11 
12 import readline
13 import rlcompleter
14 import builtins
15 import __main__
16 
17 __all__ = ["CMSCompleter"]
18 
19 class CMSCompleter(rlcompleter.Completer):
20  def __init__(self, namespace = None):
21 
22  if namespace and not isinstance(namespace, dict):
23  raise TypeError('namespace must be a dictionary')
24 
25  # Don't bind to namespace quite yet, but flag whether the user wants a
26  # specific namespace or to use __main__.__dict__. This will allow us
27  # to bind to __main__.__dict__ at completion time, not now.
28  if namespace is None:
29  self.use_main_ns = 1
30  else:
31  self.use_main_ns = 0
32  self.namespace = namespace
33  try:
34  # loading cms namespace
35  from . import namespaceDict
36  self.cmsnamespace = namespaceDict.getNamespaceDict()
37  except:
38  print('Could not load CMS namespace')
39 
40 
41  def global_matches(self, text):
42  """Compute matches when text is a simple name.
43 
44  Return a list of all keywords, built-in functions and names currently
45  defined in self.namespace and self.cmsnamespace that match.
46 
47  """
48  import keyword
49  matches = []
50  n = len(text)
51  for list in [keyword.kwlist,
52  builtins.__dict__,
53  self.cmsnamespace]:
54  for word in list:
55  if word[:n] == text and word != "__builtins__":
56  matches.append(word)
57  return matches
58 
59 # connect CMSCompleter with readline
60 readline.set_completer(CMSCompleter().complete)
61 readline.parse_and_bind('tab: complete')
62 
63 
python.cmscompleter.CMSCompleter.__init__
def __init__(self, namespace=None)
Definition: cmscompleter.py:20
python.cmscompleter.CMSCompleter
Definition: cmscompleter.py:19
python.cmscompleter.CMSCompleter.use_main_ns
use_main_ns
Definition: cmscompleter.py:29
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
python.cmscompleter.CMSCompleter.cmsnamespace
cmsnamespace
Definition: cmscompleter.py:36
python.cmscompleter.CMSCompleter.global_matches
def global_matches(self, text)
Definition: cmscompleter.py:41
python.cmscompleter.CMSCompleter.namespace
namespace
Definition: cmscompleter.py:32