ATLAS Offline Software
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
python.Include.Include Class Reference
Inheritance diagram for python.Include.Include:
Collaboration diagram for python.Include.Include:

Public Member Functions

def __init__ (self, show=True, collect=1, clean=False)
 
def setShowIncludes (self, show)
 
def setCollect (self, collect)
 
def setClean (self, clean)
 
def __call__ (self, fn, *args, **kw)
 
def block (self, fn)
 
def unblock (self, fn)
 

Public Attributes

 msg
 

Static Public Attributes

int fid = 0
 

Private Member Functions

def _doTrace (self, fn)
 
def _trace_include (self, frame, event, arg)
 
def _oneline (self, fid, lineno, detail, buf)
 

Private Attributes

 _show
 
 _once
 
 _fcurrent
 
 _workspace
 
 _collect
 

Detailed Description

Definition at line 76 of file Include.py.

Constructor & Destructor Documentation

◆ __init__()

def python.Include.Include.__init__ (   self,
  show = True,
  collect = 1,
  clean = False 
)

Definition at line 79 of file Include.py.

79  def __init__( self, show = True, collect = 1, clean = False ):
80  self._show = show
81  self._once = []
82  self._fcurrent = ''
83  self.msg = Logging.logging.getLogger( 'Athena' )
84 
85  if clean:
86  self._workspace = {}
87  else:
88  import __main__
89  self._workspace = __main__.__dict__
90 
91  if collect:
92  self._collect = 1
93 

Member Function Documentation

◆ __call__()

def python.Include.Include.__call__ (   self,
  fn,
args,
**  kw 
)
Include <fn> in the current scope by executing it globally.

Definition at line 112 of file Include.py.

112  def __call__( self, fn, *args, **kw ):
113  """Include <fn> in the current scope by executing it globally."""
114 
115  # some basic sanity check first
116  if isinstance(fn, str) and len(fn) == 0:
117  raise IncludeError("can not 'include' empty filenames")
118 
119  # don't include file if not allowed (has to be exact match in py code)
120  if fn in self._once:
121  self.msg.debug( 'file "%s" is blocked; not included', fn )
122  return
123 
124  # locate the file
125  name = FindFile( os.path.expanduser( os.path.expandvars( fn ) ), optionsPath, os.R_OK )
126  if not name:
127  name = FindFile( os.path.basename( fn ), optionsPath, os.R_OK )
128  if name:
129  self.msg.warning( 'using %s instead of %s', name, fn )
130  else:
131  raise IncludeError( 'include file %s can not be found' % fn )
132 
133  self.msg.debug( 'located %s as %s', fn, name )
134 
135  # print if 'show' is set to non-null
136  show = self._show
137  if 'show' in kw:
138  show = kw[ 'show' ]
139 
140  # notify of start of file inclusion
141  if show:
142  self.msg.info( 'including file "%s" with ID %d', fn, self.fid )
143  else:
144  self.msg.info( 'including file "%s"', fn )
145  self._fcurrent = name
146 
147  # actual inclusion
148  if show and self._doTrace( name ):
149  # traced
150  _filecache[ name ] = open( name, 'r' ).readlines()
151  _linecache[ name ] = 0, self.fid
152  self.fid += 1
153 
154  from past.builtins import execfile
155  sys.settrace( self._trace_include )
156  execfile( name, self._workspace, self._workspace )
157  sys.settrace( sys._getframe(0).f_trace )
158 
159  # finish file printout
160  ncur, fid = _linecache[ name ]
161  buf = _filecache[ name ]
162  for i in range( ncur, len(buf) ):
163  self._oneline( fid, i, silentMarker, buf )
164 
165  del _filecache[ name ]
166  del _linecache[ name ]
167 
168  self.msg.info( 'end of "%s"', fn )
169 
170  else:
171  # non-traced
172  #execfile( name, self._workspace, self._workspace )
173  exec(compile(open(name).read(), name, 'exec'), self._workspace, self._workspace)
174 
175 
176  if hasattr( self, '_collect' ):
177  if not self._collect % 10:
178  import gc
179  gc.collect()
180  else:
181  self._collect += 1
182 

◆ _doTrace()

def python.Include.Include._doTrace (   self,
  fn 
)
private

Definition at line 197 of file Include.py.

197  def _doTrace( self, fn ):
198  # Tracing into non-included files is controlled with two variables:
199  # excludeTracePattern and includeTracePattern. The former goes first,
200  # the latter can override any excluded results.
201 
202  if fn in _notrcache:
203  return False
204 
205  doTrace = True
206  for tracePattern in excludeTracePattern:
207  if fnmatch.fnmatch( fn, tracePattern ):
208  doTrace = False
209  break
210 
211  if not doTrace:
212  for tracePattern in includeTracePattern:
213  if fnmatch.fnmatch( fn, tracePattern ):
214  doTrace = True
215  break
216 
217  if not doTrace:
218  _notrcache[ fn ] = 1
219 
220  return doTrace
221 

◆ _oneline()

def python.Include.Include._oneline (   self,
  fid,
  lineno,
  detail,
  buf 
)
private

Definition at line 285 of file Include.py.

285  def _oneline( self, fid, lineno, detail, buf ):
286  print (marker, fidMarker % fid, lineMarker % lineno, detail,)
287 
288  try:
289 
290  # simple eol case
291  if not buf or not buf[ lineno ]:
292  print()
293  return
294 
295  # in general, an interpreter "line" may be longer than a file line
296  line = buf[ lineno ].rstrip()
297  while line and ( line[-1] == '(' or line[-1] == '\\' ):
298  # this line appears to have a continuation ...
299  try:
300  # output traced line
301  print (line)
302 
303  # output continued line
304  lineno += 1
305  print (marker, fidMarker % fid, lineMarker % lineno, detail,)
306  line = buf[ lineno ].rstrip()
307  except IndexError:
308  # shouldn't happen; but must mean that the diagnosis above is
309  # wrong and that there is no continuation, keep silent
310  break
311 
312  print (line)
313 
314  except IndexError:
315  log.warning( 'index (%d) out of range while scanning include file %d', lineno, fid )
316 
317 
318 # use this for backward compatibility

◆ _trace_include()

def python.Include.Include._trace_include (   self,
  frame,
  event,
  arg 
)
private

Definition at line 223 of file Include.py.

223  def _trace_include( self, frame, event, arg ):
224  fn = frame.f_code.co_filename
225  if fn.find ('importlib._bootstrap') >= 0:
226  return self._trace_include
227 
228  if not os.path.exists( fn ):
229  fn = FindFile( basename2( fn ), sys.path, os.R_OK )
230 
231  if not ( fn and self._doTrace( fn ) ):
232  return self._trace_include
233 
234  if fn not in _filecache:
235  # wait until importing of the module is done to minimize pollution
236  f = frame.f_back
237  while f is not None:
238  try:
239  if 'import' in _filecache[ f.f_code.co_filename ][ f.f_lineno ]:
240  return self._trace_include
241  except Exception:
242  pass
243  f = f.f_back
244  del f
245 
246  # import is done, and we're back, accept this file from this point on
247  _filecache[ fn ] = open( fn, 'r' ).readlines() or '\n'
248  _linecache[ fn ] = sys.maxsize, self.fid
249  self.fid += 1
250 
251  lno = frame.f_lineno
252  aln = lno - 1 > 0 and lno - 1 or 0
253 
254  ncur, fid = _linecache[ fn ]
255  buf = _filecache[ fn ]
256 
257  if self._fcurrent != fn:
258  self.msg.info( 'continued trace of "%s"', basename2( fn ) )
259  self._fcurrent = fn
260 
261  if event == 'line':
262  for i in range( ncur, aln ):
263  self._oneline( fid, i, silentMarker, buf )
264 
265  if ncur <= aln:
266  self._oneline( fid, aln, activeMarker, buf )
267  elif 0 <= aln:
268  self._oneline( fid, aln, tracedMarker, buf )
269 
270  if ncur < lno:
271  _linecache[ fn ] = lno, fid
272 
273  elif event == 'call':
274  if lno < ncur:
275  self._oneline( fid, aln, callMarker, buf )
276 
277  elif event == 'return':
278  if lno < ncur:
279  fln = frame.f_code.co_firstlineno - 1
280  self._oneline( fid, fln, returnMarker, None )
281 
282  return self._trace_include
283 

◆ block()

def python.Include.Include.block (   self,
  fn 
)
Disallow the given filename(s) from being included again.

Definition at line 183 of file Include.py.

183  def block( self, fn ):
184  """Disallow the given filename(s) from being included again."""
185 
186  if type(fn) is list:
187  self._once += fn
188  else:
189  self._once.append( fn )
190 

◆ setClean()

def python.Include.Include.setClean (   self,
  clean 
)

Definition at line 103 of file Include.py.

103  def setClean( self, clean ):
104  import __main__
105  if clean:
106  if self._workspace is __main__.__dict__:
107  self._workspace = {}
108  self._workspace.update( __main__.__dict__ )
109  else:
110  self._workspace = __main__.__dict__
111 

◆ setCollect()

def python.Include.Include.setCollect (   self,
  collect 
)

Definition at line 97 of file Include.py.

97  def setCollect( self, collect ):
98  if collect and not hasattr( self, '_collect' ):
99  self._collect = 1
100  elif not collect and hasattr( self, '_collect' ):
101  del self._collect
102 

◆ setShowIncludes()

def python.Include.Include.setShowIncludes (   self,
  show 
)

Definition at line 94 of file Include.py.

94  def setShowIncludes( self, show ):
95  self._show = show
96 

◆ unblock()

def python.Include.Include.unblock (   self,
  fn 
)
Re-allow the given filename from being included.

Definition at line 191 of file Include.py.

191  def unblock( self, fn ):
192  """Re-allow the given filename from being included."""
193 
194  self._once.remove( fn )
195 

Member Data Documentation

◆ _collect

python.Include.Include._collect
private

Definition at line 92 of file Include.py.

◆ _fcurrent

python.Include.Include._fcurrent
private

Definition at line 82 of file Include.py.

◆ _once

python.Include.Include._once
private

Definition at line 81 of file Include.py.

◆ _show

python.Include.Include._show
private

Definition at line 80 of file Include.py.

◆ _workspace

python.Include.Include._workspace
private

Definition at line 86 of file Include.py.

◆ fid

int python.Include.Include.fid = 0
static

Definition at line 77 of file Include.py.

◆ msg

python.Include.Include.msg

Definition at line 83 of file Include.py.


The documentation for this class was generated from the following file:
grepfile.info
info
Definition: grepfile.py:38
read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.Include.basename2
def basename2(fn)
files inclusion -------------------------------------------------------—
Definition: Include.py:69
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
python.Utils.unixtools.FindFile
def FindFile(filename, pathlist, access)
helper -------------------------------------------------------------------—
Definition: unixtools.py:20
LArG4FSStartPointFilter.exec
exec
Definition: LArG4FSStartPointFilter.py:103
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
dqt_zlumi_pandas.update
update
Definition: dqt_zlumi_pandas.py:42
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28