LSSTApplications  16.0-10-g0ee56ad+4,16.0-11-ga33d1f2+4,16.0-12-g3ef5c14+2,16.0-12-g71e5ef5+17,16.0-12-gbdf3636+2,16.0-13-g118c103+2,16.0-13-g8f68b0a+2,16.0-15-gbf5c1cb+3,16.0-16-gfd17674+2,16.0-17-g7c01f5c+2,16.0-18-g0a50484,16.0-20-ga20f992+7,16.0-21-g0e05fd4+5,16.0-21-g15e2d33+3,16.0-22-g62d8060+3,16.0-22-g847a80f+3,16.0-25-gf00d9b8,16.0-28-g3990c221+3,16.0-3-gf928089+2,16.0-32-g88a4f23+4,16.0-34-gd7987ad+2,16.0-37-gc7333cb+1,16.0-4-g10fc685+1,16.0-4-g18f3627+25,16.0-4-g5f3a788+25,16.0-5-gaf5c3d7+3,16.0-5-gcc1f4bb,16.0-6-g3b92700+3,16.0-6-g4412fcd+2,16.0-6-g7235603+3,16.0-69-g2562ce1b+1,16.0-7-g0913a87,16.0-8-g14ebd58+3,16.0-8-g2df868b,16.0-8-g4cec79c+5,16.0-8-gadf6c7a,16.0-82-g59ec2a54a,16.0-9-g5400cdc+1,16.0-9-ge6233d7+4,master-g2880f2d8cf+2,v17.0.rc1
LSSTDataManagementBasePackage
Classes | Functions
lsst.sconsUtils.utils Namespace Reference

Classes

class  Log
 A dead-simple logger for all messages. More...
 

Functions

def libraryPathPassThrough ()
 Returns name of library path environment variable to be passed through or else returns None if no pass through is required on this platform. More...
 
def whichPython ()
 Returns the full path to the Python executable as determined from the PATH. More...
 
def needShebangRewrite ()
 Returns True if the shebang lines of executables should be rewritten. More...
 
def libraryLoaderEnvironment ()
 Returns library loader path environment string to be prepended to external commands Will be "" if nothing is required. More...
 
def runExternal (cmd, fatal=False, msg=None)
 Safe wrapper for running external programs, reading stdout, and sanitizing error messages. More...
 
def memberOf (cls, name=None)
 A Python decorator that injects functions into a class. More...
 

Function Documentation

◆ libraryLoaderEnvironment()

def lsst.sconsUtils.utils.libraryLoaderEnvironment ( )

Returns library loader path environment string to be prepended to external commands Will be "" if nothing is required.

If we have an OS X with System Integrity Protection enabled or similar we need to pass through both DYLD_LIBRARY_PATH and LSST_LIBRARY_PATH to the external command. DYLD_LIBRARY_PATH for Python code LSST_LIBRARY_PATH for shell scripts

If both are already defined then pass them each through If only one is defined, then set both to the defined env variable If neither is defined then pass through nothing.

Definition at line 116 of file utils.py.

117  libpathstr = ""
118  lib_pass_through_var = libraryPathPassThrough()
119  aux_pass_through_var = "LSST_LIBRARY_PATH"
120  if lib_pass_through_var is not None:
121  for varname in (lib_pass_through_var, aux_pass_through_var):
122  if varname in os.environ:
123  libpathstr += '{}="{}" '.format(varname, os.environ[varname])
124 
125  if aux_pass_through_var in os.environ and \
126  lib_pass_through_var not in os.environ:
127  libpathstr += '{}="{}" '.format(lib_pass_through_var, os.environ[aux_pass_through_var])
128 
129  if lib_pass_through_var in os.environ and \
130  aux_pass_through_var not in os.environ:
131  libpathstr += '{}="{}" '.format(aux_pass_through_var, os.environ[lib_pass_through_var])
132 
133  return libpathstr
134 
135 
def libraryLoaderEnvironment()
Returns library loader path environment string to be prepended to external commands Will be "" if not...
Definition: utils.py:116
def libraryPathPassThrough()
Returns name of library path environment variable to be passed through or else returns None if no pas...
Definition: utils.py:70
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:168

◆ libraryPathPassThrough()

def lsst.sconsUtils.utils.libraryPathPassThrough ( )

Returns name of library path environment variable to be passed through or else returns None if no pass through is required on this platform.

Definition at line 70 of file utils.py.

71  if _has_OSX_SIP():
72  return "DYLD_LIBRARY_PATH"
73  return None
74 
75 
76 # Cache variable for whichPython() function
def libraryPathPassThrough()
Returns name of library path environment variable to be passed through or else returns None if no pas...
Definition: utils.py:70

◆ memberOf()

def lsst.sconsUtils.utils.memberOf (   cls,
  name = None 
)

A Python decorator that injects functions into a class.

For example:

class test_class:
pass
@memberOf(test_class):
def test_method(self):
print "test_method!"

...will cause test_method to appear as as if it were defined within test_class.

The function or method will still be added to the module scope as well, replacing any existing module-scope function with that name; this appears to be unavoidable.

Definition at line 185 of file utils.py.

185 def memberOf(cls, name=None):
186  if isinstance(cls, type):
187  classes = (cls,)
188  else:
189  classes = tuple(cls)
190  kw = {"name": name}
191 
192  def nested(member):
193  if kw["name"] is None:
194  kw["name"] = member.__name__
195  for scope in classes:
196  setattr(scope, kw["name"], member)
197  return member
198  return nested
199 
table::Key< int > nested
def memberOf(cls, name=None)
A Python decorator that injects functions into a class.
Definition: utils.py:185

◆ needShebangRewrite()

def lsst.sconsUtils.utils.needShebangRewrite ( )

Returns True if the shebang lines of executables should be rewritten.

Definition at line 98 of file utils.py.

98 def needShebangRewrite():
99  return _has_OSX_SIP()
100 
101 
def needShebangRewrite()
Returns True if the shebang lines of executables should be rewritten.
Definition: utils.py:98

◆ runExternal()

def lsst.sconsUtils.utils.runExternal (   cmd,
  fatal = False,
  msg = None 
)

Safe wrapper for running external programs, reading stdout, and sanitizing error messages.

Command can be given as a list/tuple of command with separate options.

Note that the entire program output is returned, not just a single line.

Returns
Strings not bytes.

Definition at line 144 of file utils.py.

144 def runExternal(cmd, fatal=False, msg=None):
145  if msg is None:
146  try:
147  msg = "Error running %s" % cmd.split()[0]
148  except Exception:
149  msg = "Error running external command"
150 
151  # Run with shell unless given a list of options
152  shell = True
153  if isinstance(cmd, (list, tuple)):
154  shell = False
155 
156  try:
157  retval = subprocess.run(cmd, shell=shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
158  check=True)
159  except subprocess.CalledProcessError as e:
160  if fatal:
161  raise RuntimeError(f"{msg}: {e.stderr.decode()}") from e
162  else:
163  from . import state # can't import at module scope due to circular dependency
164  state.log.warn(f"{msg}: {e.stderr}")
165  return retval.stdout.decode().strip()
166 
167 
def runExternal(cmd, fatal=False, msg=None)
Safe wrapper for running external programs, reading stdout, and sanitizing error messages.
Definition: utils.py:144
bool strip
Definition: fits.cc:831

◆ whichPython()

def lsst.sconsUtils.utils.whichPython ( )

Returns the full path to the Python executable as determined from the PATH.

Does not return the full path of the Python running SCons. Caches result and assumes the PATH does not change between calls. Runs the "python" command and asks where it is rather than scanning the PATH.

Definition at line 87 of file utils.py.

87 def whichPython():
88  global _pythonPath
89  if _pythonPath is None:
90  _pythonPath = runExternal(["python", "-c", "import sys; print(sys.executable)"],
91  fatal=True, msg="Error getting python path")
92  return _pythonPath
93 
94 
def whichPython()
Returns the full path to the Python executable as determined from the PATH.
Definition: utils.py:87
def runExternal(cmd, fatal=False, msg=None)
Safe wrapper for running external programs, reading stdout, and sanitizing error messages.
Definition: utils.py:144